ucrt: set ERANGE when scalbn and its relatives overflow #62

Merged
Repla09 merged 1 commit from upstream-pr/62 into main 2026-11-26 13:26:44 +00:00
Repla09 commented 2026-11-26 12:13:20 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Repla09 on 2026-11-26T12:13:20Z.


Follow-up to the scope note on #52: scalbn, scalbnf, scalbln, scalblnf and _scalb returned infinity on overflow without setting errno, while ldexp (the same operation) sets ERANGE, and Microsoft documents ERANGE for scalbn overflow.

They are now checked the same way as ldexp; the float forms after rounding to a float, so a float overflow that is finite as a double counts.

scalbn_and_its_relatives_set_erange_on_overflow fails on main (errno 0, not 34). It covers all five, and checks that an in-range result and an infinity from an infinite argument leave a seeded errno alone.

fdimf still sets no errno on overflow. Its fix depends on #52's float check, so it will follow once #52 is in.

Testing

  • cargo test --target x86_64-apple-darwin -p victory-hle passes (222 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:6626402177 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62). Originally posted by [Repla09](https://github.com/Repla09) on 2026-11-26T12:13:20Z. --- Follow-up to the scope note on #52: `scalbn`, `scalbnf`, `scalbln`, `scalblnf` and `_scalb` returned infinity on overflow without setting `errno`, while `ldexp` (the same operation) sets `ERANGE`, and Microsoft documents `ERANGE` for `scalbn` overflow. They are now checked the same way as `ldexp`; the float forms after rounding to a float, so a float overflow that is finite as a double counts. `scalbn_and_its_relatives_set_erange_on_overflow` fails on main (`errno` 0, not 34). It covers all five, and checks that an in-range result and an infinity from an infinite argument leave a seeded `errno` alone. `fdimf` still sets no `errno` on overflow. Its fix depends on #52's float check, so it will follow once #52 is in. ## Testing - `cargo test --target x86_64-apple-darwin -p victory-hle` passes (222 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 12:45:32 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Thanks, the logic matches ldexp and the test fails on main. Please:

  1. Rebase on main. #52 landed and adds a test in the same spot in ucrt/math.rs; keep both tests.
  2. Update the errno bullet in docs/native-host.md (~303): list scalbn, scalbnf, scalbln, scalblnf and _scalb alongside ldexpf, leaving only fdimf as not setting errno yet.
  3. Note there that underflow is left alone (no ERANGE), as with ldexp.
    Optional: ldexp/ldexpf could call the new scalbn_checked/scalbnf_checked helpers instead of duplicating them.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074347638 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62#pullrequestreview-6074347638). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:45:32Z. **Review:** CHANGES_REQUESTED --- Thanks, the logic matches `ldexp` and the test fails on main. Please: 1. Rebase on main. #52 landed and adds a test in the same spot in `ucrt/math.rs`; keep both tests. 2. Update the `errno` bullet in `docs/native-host.md` (~303): list `scalbn`, `scalbnf`, `scalbln`, `scalblnf` and `_scalb` alongside `ldexpf`, leaving only `fdimf` as not setting errno yet. 3. Note there that underflow is left alone (no `ERANGE`), as with `ldexp`. Optional: `ldexp`/`ldexpf` could call the new `scalbn_checked`/`scalbnf_checked` helpers instead of duplicating them.
Repla09 commented 2026-11-26 12:56:15 +00:00 (Migrated from github.com)

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


Thanks. In 1fd83c0, rebased on main:

  1. Both tests kept: a_float_that_overflows_sets_erange from #52 as it was, and scalbn_and_its_relatives_set_erange_on_overflow beside it.
  2. The errno bullet in native-host.md lists scalbn, scalbnf, scalbln, scalblnf and _scalb with ldexpf, leaving only fdimf.
  3. It notes that underflow leaves errno alone, and the test checks it (scalbn(1, -2000) and scalbnf(1, -200) give 0 with a seeded errno unchanged).
    Also took the optional one: ldexp/ldexpf now call scalbn_checked/scalbnf_checked.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192656291 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62#issuecomment-7192656291). Originally posted by [Repla09](https://github.com/Repla09) on 2026-11-26T12:56:15Z. --- Thanks. In 1fd83c0, rebased on main: 1. Both tests kept: `a_float_that_overflows_sets_erange` from #52 as it was, and `scalbn_and_its_relatives_set_erange_on_overflow` beside it. 2. The `errno` bullet in native-host.md lists `scalbn`, `scalbnf`, `scalbln`, `scalblnf` and `_scalb` with `ldexpf`, leaving only `fdimf`. 3. It notes that underflow leaves `errno` alone, and the test checks it (`scalbn(1, -2000)` and `scalbnf(1, -200)` give 0 with a seeded errno unchanged). Also took the optional one: `ldexp`/`ldexpf` now call `scalbn_checked`/`scalbnf_checked`.
LakshanSivakumar commented 2026-11-26 13:26:40 +00:00 (Migrated from github.com)

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

Review: APPROVED


All review items are addressed cleanly (scalbn_checked/scalbnf_checked shared with ldexp/ldexpf, docs/native-host.md updated including underflow behavior, both tests kept, and CI green). Merging.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074927961 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62#pullrequestreview-6074927961). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T13:26:40Z. **Review:** APPROVED --- All review items are addressed cleanly (`scalbn_checked`/`scalbnf_checked` shared with `ldexp`/`ldexpf`, `docs/native-host.md` updated including underflow behavior, both tests kept, and CI green). Merging.
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!62
No description provided.