[BUG]: `number/float16/base/to-word` mis-rounds subnormals at the 11-bit shift boundary
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js
- 领域
- backend
调研方向
The issue identifies lib/main.js and the subnormal rounding branch as the starting point. Check the conversion against native Float16Array around the 11-bit shift boundary, including positive and negative values and the exact halfway value. Done means the reported mismatches are fixed and focused regression coverage confirms the expected half-precision words; pull request #16511 is already open.
由索引模型根据 Issue 内容生成。
描述
Description
@stdlib/number/float16/base/to-word returns zero for float32 values just above 2^-25 that should round to the smallest positive half-precision subnormal. Native Float16Array rounds these to 0x0001.
var toWord = require( '@stdlib/number/float16/base/to-word' );
toWord( 2.98038125038147e-8 ); // returns 0x0000, expected 0x0001
toWord( -2.98038125038147e-8 ); // returns 0x8000, expected 0x8001
Comparing against new Float16Array over 20,000 values in [2^-25, 2^-24) shows 10,015 mismatches; the values that should round to 0x0001 are returned as zero. The exact halfway value 2^-25 correctly ties to zero in both implementations.
Root Cause
In lib/main.js, the subnormal rounding path branches on:
if ( shift < 11 ) {
When shift === 11, the code falls into the else branch, which extracts the round bit from the original 23-bit mantissa at the wrong position. With shift = 11 the 11-bit mantissa is shifted out entirely, and the round bit is its lowest bit (bit 10), which the first branch already handles correctly. Values requiring shift > 11 return zero earlier via the f16Exponent < -10 check, so the else branch is only reachable for shift === 11.
Changing the condition to shift <= 11 fixes all mismatches in a 50,000-value sweep.
Environment
- Version:
develop(7cf56423a) - Node.js with native
Float16Arraysupport - The bug is platform-independent and affects the JavaScript path only; the C path returns the bits of an already-encoded
stdlib_float16_t.
Checklist
- Read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- 主要语言
- JavaScript
- 星标
- 6k
- 派生
- 1.3k
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 224
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
stdlib-js/stdlib 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
stdlib-js/stdlib#16655 · 1 条评论 ·
维护者通常 1 天内回复
-
Fix JavaScript lint errors可能已有人在做 @protestershankar 于 5 天前认领。 未关闭Good First Issue
难度 2/5 1-3 小时 新手友好度 82/100
stdlib-js/stdlib#16563 · 3 条评论 ·
维护者通常 1 天内回复
-
Fix C lint errors可能已有人在做 @raus7n 于 14 天前认领。 未关闭Good First Issue
难度 1/5 1 小时以内 新手友好度 82/100
stdlib-js/stdlib#16454 · 1 条评论 ·
维护者通常 1 天内回复
-
Fix JavaScript lint errors可能已有人在做 @Devansh-18155 于 39 天前认领。 未关闭Good First Issue
难度 1/5 1 小时以内 新手友好度 82/100
stdlib-js/stdlib#15970 · 1 条评论 ·
维护者通常 1 天内回复
-
Fix JavaScript lint errors可能已有人在做 @lb1192176991-lab 于 44 天前认领。 未关闭Good First Issue
难度 1/5 1 小时以内 新手友好度 90/100
stdlib-js/stdlib#15831 · 2 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 69/100
维护者通常 1 天内回复
-
automation chore ci-cd consistency developer-experience difficulty: easy discoverability documentation enhancement github-actions good first issue help wanted hygiene priority: P3 seo shell yaml
难度 1/5 1 小时以内 新手友好度 76/100
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
swc-project/swc-next-issues#394 ·
-
难度 1/5 1-3 小时 新手友好度 88/100
githubnext/gh-aw-workshop#5790 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
adobe/helix-tools-website#480 ·
维护者通常 1 天内回复