fix(libc): compute jnf and ynf with FreeBSD msun's algorithm #18792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18792"
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 AlexWhitehouse on 2026-11-12T09:47:54Z.
What
libc
jnf(NIDM5KJmq-gKM8) andynf(NIDwdPaII721tY) returned the host's doublejn/ynrounded to float. The console's libc uses FreeBSD msun's floate_jnf.c, which runs its own float recurrences on top ofj0f,j1f,y0fandy1f, so results differ from the host's in the last bits. For example, on glibc 2.43,ynf(0, 0x3f000000)(0.5) is0xbee397f6onmainand0xbee397f5in msun.This PR ports
e_jnf.cat FreeBSD release/10.0.0 (__ieee754_jnfand__ieee754_ynf) into a newcore/libs/prx/libc/src/Jnf.cpp. It keeps the upstream notice byte for byte, along with the thresholds, the forward and backward recurrences, the continued-fraction start and thelogfrescaling branch.Bessel.cpp, #7998) and of myj0f,j1f/y1fandy0fports (#16747, #16847, #16866). #21013 has since movedj0f,j1f,y0fandy1ftoa737ef56ab;e_jnf.cdid not change between release/10.0.0 and that commit.j0f,j1f,y0f,y1fandlogf, not the host's.-n,n+nandi+ioverflow atINT_MIN. Here they wrap explicitly at 32 bits, which gives the same result as upstream's two's-complement build: forINT_MIN, the recurrence is skipped, so the result isj1f(|x|)ory1f(x)for finite nonzerox.ynf(±0)keeps the measured −∞ (#7906, #8864), witherrnoand exception flags unchanged, as the existing zero checks inGuestBesselrequire.ynfreturn a positive quiet NaN without settingerrnoor raising invalid, asy0fandy1fdo here;ynf(-inf)gives an invalid NaN.jnfandynfmove out of the shared host-results entry into their own entry, which records that console provenance, FMA contraction and nonzero exception flags are unverified, and that huge orders can take billions of steps, as upstream.Tested
guest_bessel(core/libs/tests/GuestBessel.cpp) gains exact-bitjnfandynfcases for 55 order/argument pairs, and every existing assertion is kept. They cover:INT_MINandINT_MAX;x > nrecurrence switch and the 2^-30 tiny-argument (0x30800000) boundary, subnormals,FLT_MAX, and arguments near 3 and 100;errnounchanged on every case;ynffor every order class, witherrnoand existing exception flags unchanged, and invalid forynf(-inf).Expected values come from upstream
e_jnf.ccompiled locally as a C reference, over upstreame_j0f.cande_j1f.cata737ef56ab. After #21013 merged, threejnf(3, x)cases near x = 3 changed (3e9e3d74,3e9e3d78,3e9e3d7a) and every other case matched the reference again, except the documented negative-argument NaN sign andINT_MINwrapping.Linux x86-64 (Ubuntu 26.04, GCC 15, glibc 2.43, Release):
main,guest_besselfails withGuest ynf(0, 3f000000): result bee397f6, expected bee397f5;guest_besselpasses.Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):
guest_besselpasses at 3291444059, with no compiler warnings in the changed files. (Since then this branch was rebased onto currentmainand one debt word was fixed; the code is unchanged.)Mutation check: changing a recurrence constant from 2 to 3 fails the new cases:
jnf(3, 3e000000)returned38aad5a9, expected382a8005.python3 tools/check_conventions.py --base origin/main: no errors. The one warning is about the shared host-results entry, which was already over 1,000 characters; this PR only removesjnfandynffrom it.python3 tools/pr_overlap.py: no open PR changesjnforynf. Lifted-build PRs #15802–#15807 rewrite neighbouringMath.cpplines, and #11634 (hypotl) edits the shared host-results debt line; both conflict textually only.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T11:11:49Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e5774dc877:tools/check_conventions.pypassed;git diff --checkclean.guest_bessel_testsbuilt cleanly.guest_bessel):core/libs/prx/libc/src/Math.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me