ucrt: step nexttowardf toward its double target #50

Manually merged
github merged 3 commits from gh-pr/50/head into gh-pr/50/base 2026-11-26 14:43:56 +00:00
Owner

@⁠Repla09 on GitHub · 2026-11-26 11:31 UTC · original
Repla09:fix/ucrt-nexttowardf-double-target → main · +49 −1 · 2 files · 3 commits · merged 2026-11-26 12:05 UTC

nexttowardf takes its target as a double (long double is double here) so that a target between two floats still moves x one float toward it. The host rounded the target to a float first, which can round it to x itself: nexttowardf(1.0f, 1.0 + 1e-10) returned 1.0f instead of the next float up, and nexttowardf(0.0f, 1e-300) returned 0.

Now it compares as doubles and steps toward the infinity on the target's side.

nexttowardf_steps_toward_its_double_target fails without the fix (1065353216 != 1065353217) and covers both directions, zero toward a tiny target, equal values, overflow and NaN.

Testing

  • cargo test --target x86_64-apple-darwin -p victory-hle passes (220 unit, 15 native_probe; the D3D12 probe test skipped, no Metal Shader Converter here).
  • Clippy on x86_64-apple-darwin shows no new warnings; rustfmt --check and cargo xtask policy pass.
**@⁠Repla09** on GitHub · 2026-11-26 11:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50) `Repla09:fix/ucrt-nexttowardf-double-target` → `main` · +49 −1 · 2 files · 3 commits · merged 2026-11-26 12:05 UTC `nexttowardf` takes its target as a double (`long double` is `double` here) so that a target between two floats still moves `x` one float toward it. The host rounded the target to a float first, which can round it to `x` itself: `nexttowardf(1.0f, 1.0 + 1e-10)` returned `1.0f` instead of the next float up, and `nexttowardf(0.0f, 1e-300)` returned 0. Now it compares as doubles and steps toward the infinity on the target's side. `nexttowardf_steps_toward_its_double_target` fails without the fix (`1065353216 != 1065353217`) and covers both directions, zero toward a tiny target, equal values, overflow and NaN. ## Testing - `cargo test --target x86_64-apple-darwin -p victory-hle` passes (220 unit, 15 native_probe; the D3D12 probe test skipped, no Metal Shader Converter here). - Clippy on `x86_64-apple-darwin` shows no new warnings; `rustfmt --check` and `cargo xtask policy` pass.
nexttowardf takes its target as a double (long double is double here)
so that a target between two floats still moves x one float toward
it. The host rounded the target to a float first, which can round it
to x itself: nexttowardf(1.0f, 1.0 + 1e-10) returned 1.0f instead of
the next float up, and nexttowardf(0.0f, 1e-300) returned 0.

Compare as doubles and step toward the infinity on the target's side.
A finite float stepping past FLT_MAX to infinity sets ERANGE, also
toward an infinite target; an infinity in does not. The test checks
errno on overflow and opposite-signed zeros, and native-host.md notes
that long double is a 64-bit double on Windows x64.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:43:54 +00:00
github manually merged commit f58be8f299 into gh-pr/50/base 2026-11-26 14:43:56 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:42 UTC · original · requested changes

The double-precision direction fix looks good: the original near-equal case fails on main and passes here. Two things:

  1. Set errno on overflow. When a finite float steps to infinity, set guest errno to ERANGE, including when the target is infinite (ucrt/math.rs:~202; Microsoft documents ERANGE for this). Please extend the overflow assertion to check errno, and add an opposite-signed-zero case.
  2. Docs. Please note the Windows x64 long double = 64-bit double ABI in the UCRT section of docs/native-host.md.
**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:42 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50#pullrequestreview-6073545966) · **requested changes** The double-precision direction fix looks good: the original near-equal case fails on main and passes here. Two things: 1. **Set `errno` on overflow.** When a finite float steps to infinity, set guest `errno` to `ERANGE`, including when the target is infinite (`ucrt/math.rs:~202`; Microsoft documents `ERANGE` for this). Please extend the overflow assertion to check `errno`, and add an opposite-signed-zero case. 2. **Docs.** Please note the Windows x64 `long double` = 64-bit `double` ABI in the UCRT section of `docs/native-host.md`.
Author
Owner

@⁠Repla09 on GitHub · 2026-11-26 11:50 UTC · original

Thanks. In 0557fee a finite float stepping to infinity sets ERANGE, including toward an infinite target (an infinity in does not). The test checks errno for those cases and adds opposite-signed zeros (nexttowardf(0.0, -0.0) is -0.0 and the reverse +0.0). native-host.md notes the Windows x64 long double = 64-bit double ABI. Rebased onto main.

**@⁠Repla09** on GitHub · 2026-11-26 11:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50#issuecomment-7191227766) Thanks. In 0557fee a finite float stepping to infinity sets ERANGE, including toward an infinite target (an infinity in does not). The test checks errno for those cases and adds opposite-signed zeros (`nexttowardf(0.0, -0.0)` is -0.0 and the reverse +0.0). native-host.md notes the Windows x64 `long double` = 64-bit `double` ABI. Rebased onto main.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:01 UTC · original · approved these changes

Thanks for addressing the earlier requests; the regression passes under Rosetta and fails against main. Approved.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50#pullrequestreview-6073790670) · **approved these changes** Thanks for addressing the earlier requests; the regression passes under Rosetta and fails against main. Approved.
This discussion has been locked. Commenting is limited to contributors.
No description provided.