ucrt: set ERANGE when strtod underflows to zero #72

Manually merged
github merged 2 commits from github-bot/gh-72 into main 2026-11-26 15:57:18 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 13:41 UTC · original
Olima34:fix/ucrt-strtod-underflow-erange → main · +37 −2 · 2 files · 2 commits · merged 2026-11-26 15:53 UTC

What this changes

Microsoft's strtod "returns 0 if no conversion can be performed or an underflow occurs" and "errno is set to ERANGE if overflow or underflow occurs". We set ERANGE only on overflow. Nonzero digits that read as 0 (1e-400, strtof's 1e-50) now set it too; zero digits (0e-400) and subnormals (4.9e-324) do not. scanf's floats, which already set ERANGE on an overflow through the same parser, follow.

New test an_underflow_to_zero_sets_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/72) `Olima34:fix/ucrt-strtod-underflow-erange` → `main` · +37 −2 · 2 files · 2 commits · merged 2026-11-26 15:53 UTC ## What this changes [Microsoft's `strtod`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strtod-strtod-l-wcstod-wcstod-l) "returns 0 if no conversion can be performed or an underflow occurs" and "errno is set to ERANGE if overflow or underflow occurs". We set `ERANGE` only on overflow. Nonzero digits that read as 0 (`1e-400`, `strtof`'s `1e-50`) now set it too; zero digits (`0e-400`) and subnormals (`4.9e-324`) do not. `scanf`'s floats, which already set `ERANGE` on an overflow through the same parser, follow. New test `an_underflow_to_zero_sets_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)
Microsoft's strtod returns 0 and sets ERANGE on an underflow, as on an overflow. Nonzero digits read as 0 (1e-400, strtof's 1e-50) now set it; zero digits and subnormals still do not. scanf's floats, which already set ERANGE on an overflow through the same parser, follow.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:12 +00:00
Author
Owner

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

ERANGE on underflow to zero matches the CRT docs, and zero digits / subnormals correctly leave it alone. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/72#pullrequestreview-6076267902) · **approved these changes** ERANGE on underflow to zero matches the CRT docs, and zero digits / subnormals correctly leave it alone. Thanks.
github manually merged commit 3fd73fd59d into main 2026-11-26 15:57:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.