ucrt: step nexttowardf toward its double target #50

Merged
Repla09 merged 3 commits from upstream-pr/50 into main 2026-11-26 12:05:19 +00:00
Repla09 commented 2026-11-26 11:31:01 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Repla09 on 2026-11-26T11:31:01Z.


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6625721693 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50). Originally posted by [Repla09](https://github.com/Repla09) on 2026-11-26T11:31:01Z. --- `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.
LakshanSivakumar commented 2026-11-26 11:42:42 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:42:42Z.

Review: CHANGES_REQUESTED


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073545966 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50#pullrequestreview-6073545966). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:42:42Z. **Review:** CHANGES_REQUESTED --- 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`.
Repla09 commented 2026-11-26 11:50:15 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Repla09 on 2026-11-26T11:50:15Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7191227766 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50#issuecomment-7191227766). Originally posted by [Repla09](https://github.com/Repla09) on 2026-11-26T11:50:15Z. --- 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.
LakshanSivakumar commented 2026-11-26 12:01:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:01:56Z.

Review: APPROVED


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073790670 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/50#pullrequestreview-6073790670). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:01:56Z. **Review:** APPROVED --- Thanks for addressing the earlier requests; the regression passes under Rosetta and fails against main. Approved.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
LakshanSivakumar/Native-Victory-macOS!50
No description provided.