Skip to content

fix(math): stop the internal abs helper from leaking negative zero - #3937

Merged
Kaida-Amethyst merged 2 commits into
moonbitlang:mainfrom
Lfan-ke:fix/atan2-neg-zero
Aug 4, 2026
Merged

fix(math): stop the internal abs helper from leaking negative zero#3937
Kaida-Amethyst merged 2 commits into
moonbitlang:mainfrom
Lfan-ke:fix/atan2-neg-zero

Conversation

@Lfan-ke

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

Copy link
Copy Markdown
Contributor

For a tiny negative y and a large x, y / x underflows to -0.0. The internal abs helper is if x < 0.0 { -x } else { x }, and since -0.0 < 0.0 is false it returns -0.0 unchanged instead of +0.0. atan2 then does atan(-0.0) = -0.0 and negates it for the quadrant, flipping the result to +0.0 when it should stay -0.0.

Fixed the helper to defer to the builtin .abs(), which clears the sign bit. Added a regression test for the underflow case.

Closes #3914

Closes moonbitlang#3914

Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
@Kaida-Amethyst
Kaida-Amethyst enabled auto-merge (squash) August 4, 2026 07:05
@Kaida-Amethyst
Kaida-Amethyst merged commit 8a61090 into moonbitlang:main Aug 4, 2026
19 checks passed
@Kaida-Amethyst

Copy link
Copy Markdown
Contributor

Good job

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] atan2 loses the sign of an underflowed negative result

2 participants