[PR #3749] [MERGED] fix(core): atan2 matches StrictMath #5191

Closed
opened 2026-11-03 05:10:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3749
Author: @reservedbytes
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: fix/jmath-atan2


📝 Commits (2)

  • d385d18 fix(core): atan2 matches StrictMath
  • 5815bf4 jmath::atan2: use the fdlibm port geometry::trig already has

📊 Changes

1 file changed (+91 additions, -1 deletions)

View changed files

📝 crates/horizon-core/src/jmath.rs (+91 -1)

📄 Description

What and why

jmath::atan2 is documented as StrictMath's (fdlibm) on every platform, but it used the libm crate (musl's port).
musl returns ±π/2 once |y/x| > 2^64, fdlibm above 2^60 and through atan otherwise, so for x < 0 with a large |y/x| the two differ by one ulp.

This ports fdlibm's e_atan2.c (Sun notice kept), like the existing log, log10, cbrt and hypot ports.
atan stays on libm::atan, which already matches StrictMath.atan.

Also, I checked against HotSpot 25.0.4 on x86-64 Linux: bit-identical to StrictMath.atan2 on 2.6 million inputs (random bits, the 2^60–2^64 band, all quadrants, ±0, ±∞, NaN).
Math.atan2 equals StrictMath.atan2 everywhere, so HotSpot has no intrinsic here.

Vanilla reference

java.lang.StrictMath.atan2 (what Math.atan2 returns on HotSpot).
And new unit test atan2_matches_strictmath in jmath.rs: 12 inputs libm got wrong plus 10 controls (±0, ±∞, NaN, upper quadrants), expected bits from HotSpot 25.

Self-check

Check Result
Scope ✅ 1 files, +176 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 416 passed (51 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 51 s)
tests: horizon-core ✅ 115 passed (9 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (no vanilla data here): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3749 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix/jmath-atan2` --- ### 📝 Commits (2) - [`d385d18`](https://github.com/horizon-rust/horizon/commit/d385d188f3ea7a44ebdeaa332927330fd3a10e4c) fix(core): atan2 matches StrictMath - [`5815bf4`](https://github.com/horizon-rust/horizon/commit/5815bf4f11c5be14bd695ea59250bf083553fb5e) jmath::atan2: use the fdlibm port geometry::trig already has ### 📊 Changes **1 file changed** (+91 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-core/src/jmath.rs` (+91 -1) </details> ### 📄 Description ## What and why `jmath::atan2` is documented as `StrictMath`'s (fdlibm) on every platform, but it used the `libm` crate (musl's port). musl returns `±π/2` once `|y/x| > 2^64`, fdlibm above `2^60` and through `atan` otherwise, so for `x < 0` with a large `|y/x|` the two differ by one ulp. This ports fdlibm's `e_atan2.c` (Sun notice kept), like the existing `log`, `log10`, `cbrt` and `hypot` ports. `atan` stays on `libm::atan`, which already matches `StrictMath.atan`. Also, I checked against HotSpot `25.0.4` on x86-64 Linux: bit-identical to `StrictMath.atan2` on 2.6 million inputs (random bits, the `2^60`–`2^64` band, all quadrants, `±0`, `±∞`, `NaN`). `Math.atan2` equals `StrictMath.atan2` everywhere, so HotSpot has no intrinsic here. ## Vanilla reference `java.lang.StrictMath.atan2` (what `Math.atan2` returns on HotSpot). And new unit test `atan2_matches_strictmath` in `jmath.rs`: 12 inputs `libm` got wrong plus 10 controls (`±0`, `±∞`, `NaN`, upper quadrants), expected bits from HotSpot 25. ## Self-check | Check | Result | | --- | --- | | Scope | ✅ 1 files, +176 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 416 passed (51 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 51 s) | | tests: horizon-core | ✅ 115 passed (9 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (no vanilla data here): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:10:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5191
No description provided.