ucrt: keep remquo's quotient bits when the quotient is huge #51
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!51
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/51/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Repla09 on GitHub · 2026-11-26 11:31 UTC · original
Repla09:fix/ucrt-remquo-quotient-bits→main· +66 −2 · 2 files · 3 commits · merged 2026-11-26 12:08 UTCremquostores the sign and the low bits (at least three) of the integral quotientx / y. The host took them from(x - r) / y, which is no exact integer once the quotient passes 2^53:remquo(7.32e218, 1.23e62)gave 7 where the low bits are 100, and 83,412 of 199,812 random finite pairs disagreed with the host libm.Now they come from
|x| mod 8|y|, whichfmodcomputes exactly (when8|y|overflows,|x / y|is below 8 and|x|is used directly).remquo_keeps_the_low_bits_of_a_huge_quotientfails without the fix (bits 7 instead of 4) and checks the sign and low three bits against the host'sremquoover 300,000 pairs across every exponent.Testing
cargo test --target x86_64-apple-darwin -p victory-hlepasses (220 unit, 15 native_probe; the D3D12 probe test skipped, no Metal Shader Converter here).x86_64-apple-darwinshows no new warnings;rustfmt --checkandcargo xtask policypass.@LakshanSivakumar on GitHub · 2026-11-26 11:42 UTC · original · requested changes
The huge-quotient regression catches the original bug, but one boundary case still fails.
remquo(f64::MAX, 1.0e308, &q)stores7instead of2, because the intermediatem - remainder(m, ay)overflows before the division (ucrt/math.rs:~305). That bug is on main too. Please add that case, and avoid the overflowing intermediate, or take the quotient bits straight from the hostremquo. Please also document the quotient-bit guarantee in the UCRT notes: the low three bits of the magnitude, plus the sign.@Repla09 on GitHub · 2026-11-26 11:50 UTC · original
Thanks, good catch. In
28f0c54the quotient bits divide by |y| before subtracting (m / ay - remainder(m, ay) / ay), so nothing overflows near DBL_MAX:remquo(DBL_MAX, 1e308)now stores 2, and that case is in the test. The UCRT notes state the guarantee (sign plus the low three bits of the magnitude). Rebased onto main.@LakshanSivakumar on GitHub · 2026-11-26 12:01 UTC · original · approved these changes
Thanks for addressing the earlier requests; the regression passes under Rosetta and fails against main. Approved.