lib/bcd: to_bcd and from_bcd silently lose digits past 2^53 although documented as "any width"

未关闭
#2,238 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
compilers

调研方向

Start with lib/bcd.eigs at the cited to_bcd and from_bcd ranges, then read the existing BCD tests and the numeric representation limits they rely on. Run the reproductions in the issue and check the test suite's conventions for errors. Done means unsupported inputs or results raise rather than round, the largest supported width round-trips exactly, the next width raises, and docs/STDLIB.md:406 states the limit.

由索引模型根据 Issue 内容生成。

描述

area:stdlib bug found-by:duet-audit kind:silent-wrong status:held

Found by the read-only lib/ audit (hq RULES.md, audit area 4). Reproduced on main at d3ec498.

What's wrong

docs/STDLIB.md:406 and lib/bcd.eigs say the codec works at "any width", and the module's own rule is that bad input "should fail loudly, not decode to a plausible number". But a 14-digit value packs to 56 bits, past the 2^53 range a double holds exactly. to_bcd (lib/bcd.eigs:35-48) rounds the packed result, and from_bcd (lib/bcd.eigs:19-33) decodes the rounded value to a different number with no error.

Repro

load_file of "lib/bcd.eigs"
print of (from_bcd of (to_bcd of 9999999999999))
print of (from_bcd of (to_bcd of 99999999999999))
print of (to_bcd of 99999999999999)

Actual:

9999999999999
99999999999998
4.323455642275676e+16

Expected: the second line is 99999999999999, and the third is the exact value 0x99999999999999 (43234556422756761). Where the result can't be held exactly, both functions should raise instead of rounding.

Note: Phase 2 (#1776, exact int64) may make widths up to 15 digits exact. The raise is still needed beyond the integer range, and the "any width" claim needs a stated limit either way.

Done when

  • to_bcd and from_bcd raise when the input or the result is outside the exactly representable integer range, and docs/STDLIB.md:406 states that limit instead of "any width".
  • A test round-trips the largest supported width exactly and checks that one digit more raises; the round-trip check of 99999999999999 fails on d3ec498 (or is replaced by the raise check if 14 digits ends up beyond the limit).

— Duet (orchestrator)

主要语言
C
星标
3
派生
7
平均合并
6 小时 32 分钟
30 天内合并 PR
285

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

InauguralSystems/EigenScript 的其他 Issue

查看 InauguralSystems/EigenScript 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。