fix(libc): compute powl with FreeBSD msun's ld80 algorithm #18481
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18481"
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 AlfaRojo on 2026-11-11T17:50:13Z.
What
powlreturned the host'sstd::pow, so its low bits depended on the host math library (WinLibs'powlis off by up to hundreds of ulps on some inputs, e.g. 1.5^100.75 by 30 ulp, 3^-1234.5 by 540 ulp). It now ports FreeBSD release/11.4.0lib/msun/ld80/e_powl.c(Moshier'spowlandpowil, lines 135-662): https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/msun/ld80/e_powl.c. The Moshier licence notice is kept. The debt entry indocs/dev/debt/libc.mdis split out of the host-computed list and records that console equivalence is unverified, that errno is untouched, and the msun quirk of +inf on odd negative integer overflow.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, based on upstream/main
f57c971559.guest_math3/3 runs pass: C99 Annex F special cases (bit-exact), plus 14 regular values (decimal exponents, integer-power path, negative bases, denormal result) whose expected bits come from the port and were cross-checked against mpmath at 300 bits (msun within 0.9 ulp on every normal case).Pinned
powlat +-LDBL_MAX(x = +-LDBL_MAX with y = 0.5 and -1, four checks) to msun's results (+inf, +0, +inf, -0), confirmed on the original e_powl.c built with the host gcc; msun treats +-LDBL_MAXas infinite (lines 297 and 321) and the debt entry says so.Port vs the original e_powl.c compiled with the host gcc: 28,000,900 operand pairs including specials, 0 differences.
Negative control: with
std::powrestored the test fails ("Guest powl failed for 10 -3.5"); hostpowlhere differs from msun on most regular values. On a glibc host it may match more of them; the pinned values are from the algorithm, not the host.tools/check_conventions.py --base upstream/mainpasses;tools/check_test_registration.pypasses.Head
d7a8a42294(merged with upstream/main including #11266'sexp2lb975a42ca5):guest_math,guest_math_elementaryandguest_math_exactpass in 3/3 runs. Two new pins,powl(-0.5L, 20001.0L)andpowl(-2.0L, -20001.0L), both +0 as in the original e_powl.c built with the host gcc;tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pyfailed closed (1963 open PRs; 32 not compared because they conflict with main). No open PR implementspowl. #11262 (atanl), #11266 (exp2l) and #18110 (logl, log10l, log2l) edit the samedocs/dev/debt/libc.mdlist entry that this PR splits, and #11266 and #18110 also touch the neighbouring lines ofMath.cpp, so whichever merges second needs a trivial rebase; none changespowl. #18122 forwardspowl_nid_disambig1topowl_nid_no_patch, which callspowl_nid_postfix, so it composes with this change. I grepped the diffs of every reported PR forpowlandpowil: the only hits are those entries, the unchangedstd::powline as context in #11266 and #18110, and the #18122 forwards; #6295, #7544 and #11109 (not compared, touchMath.cpp) do not mention them. #5021's diff is too large forgh pr diff; its per-file patches fordocs/dev/debt/libc.mdand its two math files do not mentionpowl.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 PrivacyOnion on 2026-11-11T18:03:05Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b57be95210:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math,guest_math_elementary,guest_math_exact):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:38:58Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b57be95210:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math,guest_math_elementary,guest_math_exact):core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.x >= std::numeric_limits<long double>::max()using>=against finite LDBL_MAX instead of checking for infinity viastd::isinf(x). For inputpowl_nid_postfix(std::numeric_limits<long double>::max(), 0.5L),x >= max()evaluates to true and the function returnsstd::numeric_limits<long double>::infinity()instead of the finite normal square root approx 1.090748135619426e+2466L. For inputpowl_nid_postfix(std::numeric_limits<long double>::max(), -0.5L), it returns0.0Linstead of 1 / sqrt(LDBL_MAX) approx 9.168019e-2467L.x <= -std::numeric_limits<long double>::max()using<=against finite -LDBL_MAX instead of checking for negative infinity viastd::isinf(x) && x < 0.0L. For inputpowl_nid_postfix(-std::numeric_limits<long double>::max(), 0.5L),x <= -max()evaluates to true and intercepts execution before the non-integer exponent check on line 3980, returningstd::numeric_limits<long double>::infinity()instead ofNaNfor a finite negative base raised to a non-integer exponent as required by ISO C99 7.12.7.4 and Annex F.9.4.4. Forpowl_nid_postfix(-std::numeric_limits<long double>::max(), -1.0L), it returns-0.0Linstead of -1.0L / LDBL_MAX.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:08:16Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e80966de1d:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math,guest_math_elementary,guest_math_exact):core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:27:33Z.
Review: COMMENTED
Reviewed the powl port — no blocking findings
The diff ports FreeBSD msun's ld80
powlinto libc, and the code I read shows no concrete blocking defect; nothing was built or run in this review.What I ran
e80966de1d28ad1afd34bb5940bdd94be28aa49edescription.md,commits.md,manifest.json,files.jsonanddiff.patchfrom the run folder.search):powil,ExtendedBits(,powl_nid_postfix,commentinCONVENTIONS.md.ghwrite.Results
diff.patchfiles/text was readGuestMathruncheck_conventions.py/check_test_registration.pyFindings
Blocking
None.
Non-blocking
core/libs/prx/libc/src/Math.cpp:3997(diff line 163): on underflow with a negative base and an odd integer exponent,PowlIntegerPowerreturns+0. C99 Annex F requires-0there, e.g.pow(-0.5, 20001). The debt entry (docs/dev/debt/libc.md:88) records only the overflow sign quirk, not this one. Read from the code; not executed.docs/dev/debt/libc.md:88(diff line 405): the sentence "Whether Sony wrapspowlasacoslis wrapped is unmeasured" is garbled and should read something like "Whether Sony wrapspowlthe way it wrapsacoslis unmeasured".core/libs/prx/libc/src/Math.cpp:3851(diff line 17): the "Adapted from" line is an extra code comment. The Moshier licence notice must stay, but the PR checklist says "no comments in code except technical debt", so this line needs a decision.core/libs/prx/libc/src/Math.cpp:3975(diff line 141) anddocs/dev/debt/libc.md:88: the text says the port followspowlandpowil, but nopowilsymbol exists in the diff. The integer path isPowlIntegerPower, insidepowl. The wording should say so.Not verified
e_powl.c(28,000,900 pairs), the mpmath cross-check, and the negative control: author-reported, not reproduced.CheckLongDoublePowerexpected values come from the port itself. They pin current behaviour; they do not prove it matches msun or the console.powl(libc.prx): unmeasured, as the debt entry says.core/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cppanddocs/dev/debt/libc.mdwas not read; only the changed hunks and targeted reader lookups were.To get this to a good state
docs/dev/debt/libc.md:88.PowlIntegerPowerto return-0for an odd negative base.powilwording, or add apowilfunction if it is meant to be a separate entry point.GuestMathtest on the new head and attach the output.Pull request closed