Repository navigation
fix: make ledger posting precision context-independent - #21
Merged
Merged
Conversation
PureSaber
marked this pull request as ready for review
October 4, 2026 06:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与结果
QExec账本在当前
Decimal上下文精度较低或启用Inexact/Rounded陷阱时,100 + 0.01等合法过账可能被舍入或失败;本地fixed()还重复实现了受上下文影响的缩放转换,并通过缓存让首次调用上下文污染后续结果。本变更将QDK固定到已合并的精确转换提交
fd788b2956a10490aa00c399b717ec796ae371b1,由QExec直接复用该实现;移除转换缓存;并在ExactAccountLedger._post的普通与可回滚路径中采用基于Decimal元组和Python整数的精确累加。默认ROUND_HALF_EVEN行为保持不变。验证
250 passed:全量QExec测试,原有244项加新增6项参数化用例100 + 0.01、缓存调用顺序、严格精确拒绝、正负混合scale、持仓数量、不同精度与陷阱、成功过账后的注入失败回滚ruff check src tests通过ruff format --check src tests通过bb0da30与当前提交的normal过账现金、transaction bytes和journal SHA-256逐行完全一致quant-data-kit,HEAD与依赖固定均为fd788b2范围
该变更只保证FixedPoint转换和
ExactAccountLedger._post累加不依赖当前Decimal上下文,不宣称NAV、风险或其他任意Decimal公式均已上下文独立。