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

Manually merged
github merged 1 commit from gh-pr/62/head into gh-pr/62/base 2026-11-26 14:44:46 +00:00
Owner

@⁠Repla09 on GitHub · 2026-11-26 12:13 UTC · original
Repla09:fix/ucrt-scalbn-fdim-errno → main · +40 −8 · 2 files · 1 commits · merged 2026-11-26 13:26 UTC

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.
**@⁠Repla09** on GitHub · 2026-11-26 12:13 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62) `Repla09:fix/ucrt-scalbn-fdim-errno` → `main` · +40 −8 · 2 files · 1 commits · merged 2026-11-26 13:26 UTC 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.
scalbn, scalbnf, scalbln, scalblnf and _scalb returned infinity on
overflow without setting errno, while ldexp, the same operation, set
ERANGE. Check them the same way (the float forms after rounding to a
float), through scalbn_checked and scalbnf_checked, which ldexp and
ldexpf now use too.

The test covers each, and that an in-range result, an infinity in and
an underflow to zero leave errno alone. native-host.md lists them with
ldexpf, notes that underflow sets no errno, and leaves only fdimf.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:44:46 +00:00
github manually merged commit 1fd83c04da into gh-pr/62/base 2026-11-26 14:44:46 +00:00
Author
Owner

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

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.
**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:45 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62#pullrequestreview-6074347638) · **requested changes** 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.
Author
Owner

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

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.
**@⁠Repla09** on GitHub · 2026-11-26 12:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62#issuecomment-7192656291) 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`.
Author
Owner

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

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.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 13:26 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/62#pullrequestreview-6074927961) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.