fix(libc): compute erf and erfc with FreeBSD msun's algorithm, as titles' libc.prx does #10321
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10321"
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-23T17:41:51Z.
What
erfanderfcreturned the host's functions, so their last bits anderfc'serrnodepended on the host. For example:erf(0x3ff6c0af626eed43)is0x3fee94f29b14a377in the bundledlibc.prxand0x3fee94f29b14a376on Windows (UCRT);erfc(0x400ff61d33b37096)is0x3e5139a57ee24a43in the bundledlibc.prxand0x3e5139a57ee24a40on Windows.On 4 million random arguments, UCRT differs from the titles' copies on 613,611 for
erfand 352,691 forerfc.The titles' copies (NIDs
oXgaqGVnW5oandarIKLlen2sg) are FreeBSD msun'ss_erf.c, computed through msun'sexp. The double functions are the same in 11.4 and in the older fdlibm version thatlog10andlog2follow. Both functions now compute that algorithm over this file'sexp_nid_postfix, the msun port from #10234, which this PR is stacked on:erfand 2^-56 forerfc;pp/qqratio below 0.84375;pa/qaratio up to 1.25;ra/saandrb/sbtail ratios, split at about 1/0.35, over the twoexpcalls withxsplit at its low word;±(1 - tiny)from 6 forerf,2 - tinyfrom −6 down andtiny * tinyfrom 28 up forerfc, withtinyread at run time.The two functions share the ratio helpers and the tail.
errno: msun sets none itself. The titles'erfnever sets it. The titles'erfcsetsERANGEexactly where one of its two innerexpcalls underflows, which happens for arguments just below 28. For example,erfc(0x403bffffffffffff)returns 0 withERANGE, whileerfc(28)returnstiny * tinyand leaveserrnoalone. Calling the exportedexpport gives the same rule.Tested
Exact-head Linux qualification (2026-11-02): unchanged public head
ba092462d3fc1269d45367e64cc4ef3a7f399d6a, rebuilt libc and the math/exact/Dinkumware executables. All three groups pass three times (9 passes, zero skips); public headers, conventions and whitespace pass. Module/test hashes, source/dependency verification, logs and JUnit are in the verified evidence, SHA-256525ccb31a5d3d0f5adced5fda58818d8432f06c0afa7290139adb60ae6664b54. This is new independent Linux qualification; prior Windows/reference measurements keep their stated source pins.Rebased without merge commits onto main
73f4f7e06e4f210a8c6570e335fd654dc0a86134. Tested exact headb93bef15c035d172436c8b8809ca587d3bc1ad53on Linux x86-64 (AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON, bundled dependencies). This branch contains the refreshed #10234 parent followed by the erf/erfc topic; That parent has since merged as #10234 (2026-11-03); no open prerequisite remains.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 functions. #10325 and #10328 add their test functions and debt entries at the same places incore/libs/tests/GuestMath.cppanddocs/dev/debt/libc.md, so whichever of these PRs lands later needs those lines mergedNotImplemented_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:47:43Z.
Review: APPROVED
Checked against main
39a36bbec8and FreeBSD release/11.4.0 lib/msun/src/s_erf.c and e_exp.c:exp,erfanderfcto the host, so this isn't duplicated.s_erf.cande_exp.cexactly. The ra/sa and rb/sb split points (0x4006DB6E for erf, 0x4006DB6D for erfc) and the hoistedx < -6and|x| >= 28returns in erfc are equivalent to msun's control flow.s_erf.cande_exp.cinto Python on my own, adding ERANGE only in exp's overflow/underflow branches. It reproduces every expected value inCheckExpConsoleBits(29) andCheckErfConsoleBits(35), including the erfc ERANGE at 0x403bffffffffffff. It also confirms that plain msun givesexp(1)= 0x4005bf0a8b14576a, as the debt entry says.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:09:57Z.
Review: DISMISSED
The arithmetic review and exact-head Linux tests are substantial, and the earlier review already checked the constants and FreeBSD source. I cannot recommend merging this version yet: its merge base is
1e20650, 6,822 commits behind currentmain, and the #10234 dependency is based on that same old merge base. The hosted product test jobs are skipped, so the three exact-head runs do not establish behavior against current integration. Please refresh #10234 and this dependent branch onto currentmain, preserve theDepends on: #10234order, then rerunguest_mathandguest_dinkumware_internalson the final head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T12:55:42Z.
Review: DISMISSED
Re-checked — changes requested
The new Linux qualification is valid evidence for
476e0558339ebf0c423c69e5e32e3ebbb320ed7f, but that head is still based on2227f136…, not currentmain.What I ran
Reviewed PR head
476e0558339ebf0c423c69e5e32e3ebbb320ed7fagainst its base2227f1366188cda5699dd20e2e756a18006a5d4b. Currentmainis60bdb061356db736928eee431cd8bd4c9ba68036, 3,334 commits ahead of that base. I downloaded the author-provided Linux qualification archive and verified its SHA-256 and the10321result and test logs.Results
guest_dinkumware_internalsartifact2227f136…, 3,334 commits behind current mainUnedited Linux test-log excerpt
Negative control
Not run for this re-check. The supplemental report adds positive tests and does not claim a new negative control.
Findings
Blocking
CONTRIBUTING.mdrequires branches to stay up to date withmain; current main has advanced by 3,334 commits. Please refresh this branch onto current main and rerun the focused tests on the resulting head before approval. For #10321, refresh its open prerequisite #10234 first, then update the dependent branch.Non-blocking
Sources
Not verified
I did not rebuild or rerun the C++ tests locally. Windows evidence is author-reported. No console, SDK, title, GPU, or full-suite testing was performed in this re-check.
To get this to a good state
Rebase onto current
main, preserving declared dependency order, then provide exact-head results for the focused math and Dinkumware tests. I will re-run the same source and integration checks on the refreshed heads.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T12:57:10Z.
Review: DISMISSED
Re-checked — changes requested
The supplemental Linux evidence is pinned to the current PR head, but it does not test the combination with current
main, which has since changed the same source, test, and debt files.What I ran
Reviewed PR head
476e0558339ebf0c423c69e5e32e3ebbb320ed7f(base2227f1366188cda5699dd20e2e756a18006a5d4b) and currentmain60bdb061356db736928eee431cd8bd4c9ba68036. Compared the changed-path lists and fetched file identities forcore/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cpp, anddocs/dev/debt/libc.md. Downloaded the author-provided Linux evidence archive and verified its SHA-256 and10321test log.Results
guest_dinkumware_internalsguest_math/guest_math_exactruns2227f136…Unedited test-log excerpt from the supplied archive
Negative control
Not run in this re-check. The new report supplies positive runs and makes no new negative-control claim.
Findings
Blocking
Math.cpp,GuestMath.cpp, anddocs/dev/debt/libc.mdall changed on currentmainafter the PR's base. For example, currentMath.cppstill has the host-backederf/erfcpath and currentGuestMath.cpphas newer math/environment test changes; the supplied archive was built from the older tree. A passing old-base run does not establish the result when these changes are combined. Please refresh this branch onto currentmainand rerun the focused math and Dinkumware tests on the resulting head. For #10321, update its open prerequisite #10234 first, then refresh the dependent branch.Non-blocking
Sources
Math.cppat mainGuestMath.cppat mainNot verified
I did not rebuild or rerun C++ tests locally, and did not test the combined tree on current
main. Console, SDK, title, GPU, and full-suite behavior were not verified in this re-check.To get this to a good state
Refresh onto current
main(respecting dependency order), then provide exact-head results forguest_math,guest_math_exact, andguest_dinkumware_internals. I will rerun the relevant source, test, and integration checks on that head.