Repository navigation
fix(libc): avoid premature scaled hyperbolic overflow - #8023
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Accuracy check against a high-precision reference, plus Linux (the description has Windows only). Accuracy: 143,416 float pairs
With this PR every output is the correctly rounded value. Example on Tests:
Prior art: #2050 (closed, not merged) proposed the same binary64-before-narrowing approach from the MSVC STL sources. AI-assisted: yes (Claude Code); results above were run on this machine. |
macOS: guest_math's scaled-hyperbolic special checks mask FE_DENORMALOPERAND out of fetestexcept. Darwin's FE_ALL_EXCEPT includes the x86 denormal-operand flag (glibc's does not), so the new boykopovar#8023 max-float/denorm-min case reported an extra flag even though the result, errno and the standard exception flags all matched. Linux/Windows keep the upstream check.
What
_FSinh(x, y)and_FCosh(x, y)currently evaluate the hyperbolic function in binary32 before applyingy. This can overflow even when the scaled result fits, or produce NaN for a finitexand a zero scale.Evaluate the finite scaled product in binary64 before the final binary32 rounding. Preserve the PS5 runtime's NaN preference and payloads, signed zeros, infinite operands, sign application and range-error branches. Extend the existing
guest_mathfixture and record the remaining console-precision limits in technical debt.(90.f, 1e-20f)+inf6.10201631e18(0x5ea95d6f)(90.f, 0.f)+0The table compares correctness on the same Windows host. The probe applies 12 float input pairs to both exports and compares with a
long doubleproduct rounded to float:(0,1),(1,1),(-1,2),(20,.25),(90,1e-20),(-90,1e-20),(90,-1e-20),(90,+0),(-90,+0),(90,-0),(100,1e-40),(100,-1e-40).Static disassembly of PRAGMATA's bundled libc established the special-value behavior and the scaled-exponential paths:
_FSinhat original VA0x80ac0,_FCoshat0x80680, and_FExpat0x807c0. I byte-matched the analyzed bodies to the original module. The7.7fand8.675fthresholds preserve the two helpers' original range-error branches. Finite results use host math and are not claimed to be bit-identical to the console; title impact remains unverified.Tested
Windows 11 Pro (build 26300), MinGW-w64 GCC 15.2.0, Ninja Release,
BUILD_TESTING=ON, SPIRV-Tools off. Hardware: AMD Ryzen 9 7900X, approximately 32 GB RAM, NVIDIA RTX 4070 Ti SUPER. These checks use the CPU.Tested base:
8444508241a9e4a6f5d5604d007451ce62d39cc0; tested head:ce81a77d1a21ff534a0ee9db24fecb2805b6c0ed.guest_mathexecutes 1,835 scaled-hyperbolic checks, including adjacent floats at overflow/underflow boundaries, both signs, NaN payloads, error state, and overflow under all four rounding modes.got 7f800000, expected 5ea95d6f.The overlap tool completed with warnings for conflicting older PRs. I manually checked the shared-file patches: they change unrelated functions/debt entries, or only move
GuestMath.cpp(#6044); none implements these two helpers' correction.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)