ucrt: keep remquo's quotient bits when the quotient is huge #51
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/51"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Repla09 on 2026-11-26T11:31:04Z.
remquostores 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.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:42:43Z.
Review: CHANGES_REQUESTED
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.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Repla09 on 2026-11-26T11:50:13Z.
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.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:01:57Z.
Review: APPROVED
Thanks for addressing the earlier requests; the regression passes under Rosetta and fails against main. Approved.