ucrt: scale hexadecimal floats with scalbn in strtod #71

Manually merged
github merged 2 commits from github-bot/gh-71 into main 2026-11-26 15:51:54 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 13:41 UTC · original
Olima34:fix/ucrt-strtod-hex-scale → main · +22 −2 · 2 files · 2 commits · merged 2026-11-26 15:47 UTC

What this changes

strtod's hexadecimal path multiplied the mantissa by 2f64.powi(exponent). Below 2^-1022 that power is 0, so what printf("%a") writes for small numbers read back as 0 (0x1.0000000000000p-1000, 0x1p-1074). For a zero mantissa with a large exponent it made 0 * inf, a NaN then turned into an infinity with ERANGE, so 0x0p2000 read as +inf. The value is now scaled with one scalbn (libm's, as the math functions use), exact at both ends.

New test hex_doubles_scale_exactly_at_both_ends: %a's 2^-1000, the smallest subnormal, a negative subnormal, DBL_MAX, 0x0p2000 (0, no ERANGE) and 0x1p1024 (inf, ERANGE).

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory (all pass, native probe tests included)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features; clippy for x86_64-apple-darwin reports nothing in the files touched (host_posix is not built for Windows)
  • arm64 cargo test --workspace and cargo xtask policy
  • The new test fails on main and passes with the change
  • Ran the game: not done, no copy of it here

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none here)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Olima34** on GitHub · 2026-11-26 13:41 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/71) `Olima34:fix/ucrt-strtod-hex-scale` → `main` · +22 −2 · 2 files · 2 commits · merged 2026-11-26 15:47 UTC ## What this changes `strtod`'s hexadecimal path multiplied the mantissa by `2f64.powi(exponent)`. Below 2^-1022 that power is 0, so what `printf("%a")` writes for small numbers read back as 0 (`0x1.0000000000000p-1000`, `0x1p-1074`). For a zero mantissa with a large exponent it made `0 * inf`, a NaN then turned into an infinity with `ERANGE`, so `0x0p2000` read as +inf. The value is now scaled with one `scalbn` (libm's, as the math functions use), exact at both ends. New test `hex_doubles_scale_exactly_at_both_ends`: `%a`'s 2^-1000, the smallest subnormal, a negative subnormal, `DBL_MAX`, `0x0p2000` (0, no `ERANGE`) and `0x1p1024` (inf, `ERANGE`). ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory` (all pass, native probe tests included) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features`; clippy for `x86_64-apple-darwin` reports nothing in the files touched (`host_posix` is not built for Windows) - [x] arm64 `cargo test --workspace` and `cargo xtask policy` - [x] The new test fails on `main` and passes with the change - [ ] Ran the game: not done, no copy of it here ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none here) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
The hex path multiplied the mantissa by 2f64.powi(exponent). Below 2^-1022
that power is 0, so what printf's %a writes for small numbers read back
as 0 (0x1.0000000000000p-1000, 0x1p-1074); and for a zero mantissa with a
large exponent it made 0 * inf, a NaN then turned into an infinity with
ERANGE (0x0p2000). One scalbn scales exactly at both ends.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:10 +00:00
Author
Owner

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

One scalbn fixes the underflow-to-zero and 0*inf cases. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/71#pullrequestreview-6076267467) · **approved these changes** One scalbn fixes the underflow-to-zero and 0*inf cases. Thanks.
github manually merged commit 35f6a80999 into main 2026-11-26 15:51:54 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.