fix(libc): compute exp with FreeBSD msun's algorithm, as titles' libc.prx does #10234
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10234"
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 JJenkx on 2026-10-23T15:08:49Z.
What
expreturned the host'sexp, so its last bit and itserrnodepended on the host. On Windows (UCRT), it differs from thelibc.prxthat titles ship on 9,892,285 of 320 million random arguments. For example,exp(0x4033ddceb4331e0a)is0x41b94d703f21e868in the bundledlibc.prxand0x41b94d703f21e869here, andexp(0xbfcc83b6d471607d)is0x3fe99c0d1b777558there and0x3fe99c0d1b777559here.The titles' copy (NID
NVadfnzQhHQ) is FreeBSD msun'se_exp.c.expnow computes it:k = invln2*x + halF[xsb]truncated toint;P1–P5rational and the2^kscaling, with thek == 1024andk < -1021paths;hugeandtwom1000read at run time, as msun'svolatilereads do.exp(1): the titles' copy departs from msun at exactly one argument.exp(1.0)returns the correctly roundede,0x4005bf0a8b145769, where msun's algorithm gives0x4005bf0a8b14576a. The 4,000 floats on each side of 1 and −1, every integer from −745 to 709, and everyi/jfor|i| ≤ 64and1 ≤ j ≤ 16all follow msun. This port returns that constant forx == 1and is msun everywhere else. No FreeBSD release I checked (11.4, 12.0,mainand59bc2f0952) has that case, so it is Sony's.errno: msun sets none, but the titles' copy setsERANGEin exactly msun's overflow (x > o_threshold) and underflow (x < u_threshold) branches. A result that rounds to a subnormal on the general path leaveserrnoalone. NaN and the infinities never set it. This is the double-precision counterpart of theexpfbehaviour in #10113, and it does not touch that code.Tested
Rebased without merge commits onto main
73f4f7e06e4f210a8c6570e335fd654dc0a86134. Tested exact headd6c2d09c9542061afd19afffbb7aea4818fd9b79on Linux x86-64 (AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON, bundled dependencies).Rebuilt
libc,guest_math_tests,guest_math_exact_testsandguest_dinkumware_internals_tests.guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three consecutive times on both pinned main and this exact head: 12 passes per side, zero skips. Conventions and whitespace checks pass. GitHub current-main integration is now backed by these local tests; the latest fetched main also has a clean merge preview.Original authored executable code and tests are preserved. The exp parent retains its FreeBSD notice; trailing whitespace was removed from three copyright-notice lines. No new Windows, macOS, bundled-SDK/console reference, GPU/title, performance or full-suite execution is claimed. Earlier reference comparisons retain their original source pins.
Source patches, source-preservation proof, exact pins, build logs, raw CTest logs, JUnit and binary hashes; SHA-256
46b6a1579d909a279510564f346f32b61073cc5d090decd6acc0684bfe6d706c. Uploaded copy downloaded and verified. AI-assisted: yes (Codex).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)sinhfentry didImported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:56:17Z.
Review: APPROVED
Checked against main
99feaf0eb8and FreeBSD release/11.4.0 lib/msun/src/e_exp.c:e_exp.cline for line. All 14 constants match msun's hex comments bit for bit. Apart from theexp(1)constant, theERANGElines and the dropped inexact trigger (all documented), I found no other change.CheckExpConsoleBitsexpectations, bits and errno. The remaining one is the documentedexp(1)case (msun gives 0x4005bf0a8b14576a), which I can't check against the bundled module.expis stillstd::exp.1 + xis itself inexact and raisesFE_INEXACT, so the flag is only missed where1 + xis exact (e.g. x = 2^-30). Maybe "may not raise".GuestMath.cppandlibc.md(additive only).Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.