Skip to content

fix(math): stop cbrt from misclassifying negative normals as subnormal - #3938

Merged
Kaida-Amethyst merged 2 commits into
moonbitlang:mainfrom
Lfan-ke:fix/cbrt-negative-normal
Aug 4, 2026
Merged

fix(math): stop cbrt from misclassifying negative normals as subnormal#3938
Kaida-Amethyst merged 2 commits into
moonbitlang:mainfrom
Lfan-ke:fix/cbrt-negative-normal

Conversation

@Lfan-ke

@Lfan-ke Lfan-ke commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

cbrt read the high word as a signed int and used it directly for the subnormal test hx < 0x00100000. For a negative normal input the sign bit makes hx negative, so it always compares as less than the threshold and takes the subnormal branch, giving an inaccurate result (about 7741 ULP off for -2^971). The sign is already tracked separately, so masking it off (& 0x7fffffff, as the original musl code does) is enough.

Added a regression test for a large negative normal plus an odd-symmetry check.

Closes #3909

Closes moonbitlang#3909

Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
@Kaida-Amethyst
Kaida-Amethyst enabled auto-merge (squash) August 4, 2026 07:14
@Kaida-Amethyst

Copy link
Copy Markdown
Contributor

Good Job

@Kaida-Amethyst
Kaida-Amethyst merged commit aecb39a into moonbitlang:main Aug 4, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] cbrt misclassifies negative normal inputs as subnormal on non-JS targets

2 participants