fix(libc): avoid premature scaled hyperbolic overflow #8023
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8023"
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 boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-19T17:59:41Z.
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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T18:16:21Z.
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.
docs/dev/debt/libc.mdcore/libs/tests/GuestMath.cppcore/libs/prx/libc/src/Math.cppcore/libs/tests/GuestMath.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Math.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T22:30:03Z.
Accuracy check against a high-precision reference, plus Linux (the description has Windows only).
Accuracy: 143,416 float pairs
(x, y)went through the real_FSinh_nid_postfixand_FCosh_nid_postfixexports of the builtlibc.prx.|x|uniform in [0, 200] withylog-uniform over all finite floats, subnormals included;|x| <= 200;ychosen to put the result near FLT_MAX, FLT_MIN and the smallest subnormal.sinh(x)*y/cosh(x)*ycomputed in mpmath at 160 bits and correctly rounded to binary32 (round-to-nearest-even, subnormals, overflow to inf).main9127ea36dwith and without this PR:main_FSinhmain_FCoshWith this PR every output is the correctly rounded value. Example on
main:_FSinh(89.4219f, 0.000538265f)returns+inf; the reference is1.84243e35(0x7a0def6e), which this PR returns. I can share the probe and comparator if useful.Tests:
guest_mathpasses 3/3. WithMath.cppfrommainit aborts at_FSinh(0x1.68p+6, 0x1.79ca1p-67): got 7f800000, expected 5ea95d6f.guest_mathpasses 3/3, and the reverted control 0/3.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.