feat(libc): implement _Exp and _FExp #10786
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10786"
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 00xDisaster on 2026-10-25T00:36:18Z.
What
Add
_Expand_FExp, the double and float Dinkumware helpers that computey * exp(x) * 2^offsetand return the result classification. The special-value precedence and range cutoffs follow PRAGMATA PPSA02530's bundledlibc.prx(static disassembly).Both operands are classified before shortcuts, and only finite/denormal pairs take the finite path. The strict cutoffs use
xalone: below -229/-1842 the helpers store0.0 * yand returnZerowithouterrnoor floating-point exceptions; above 229/1842 they storey * infand raise overflow. An offset does not move the cutoff. A zero multiplier keeps its sign, a NaN multiplier leaves*pxunchanged,+infwith zero or-infwith infinity is invalid, and finite multipliers with+inf/-infreturn signed infinity/zero without flags. Inside the cutoffs, subnormal results returnFinitewithout flags; a zero result from scaling raises underflow. Thex == 1, y == 1, offset == 0fast path stores the exact consoleebits._FExpuses the measured reduction constantsc1 = 0.69287109375,c2 = 0.00027608682,invln2 = 1.4426950216, with the rational constants folded asQ = 0.09997485578andP = 0.5 + 0.0083208261 z. The_Expfinite coefficients, exact bit-for-bit_Expresults, signaling NaNs, directed-rounding behavior and non-default flush-to-zero modes remain unverified and are recorded in the libc debt entry.This PR intentionally leaves
_Dsign/_FDsignto open PR #6085 and_Fpcomp/_FFpcompto open PR #8397; those exports are not duplicated here.Tested
Linux CachyOS 7.3.0-2-cachyos, GCC 16.2.1. Base
941ace5f34; head35c38ce8d5; mergeable with currentmain6bc1139698.cmake --build build --target guest_dinkumware_internals_tests guest_math_tests guest_math_exact_tests libs --parallel 8: passed.ctest --test-dir build -R '^(guest_dinkumware_internals|guest_math|guest_math_exact)$' --output-on-failure: 3/3 passed.guest_dinkumware_internalscovers double and float known values, finite/scale sweeps, zero multipliers, overflow/underflow and non-finite inputs. The special-value cases assert output,errnoand floating-point state, including signed zero, NaN write-back, both infinities with zero and finite multipliers,+inf/-infoperand combinations, x-only cutoffs with compensating offsets, subnormal results, scaling underflow, and the exactefast path.guest_mathandguest_math_exactare the neighboring libm suites and pass unchanged.tools/check_conventions.py --base upstream/main --head HEADandgit diff --check: clean.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 MarcZX10 on 2026-10-25T00:38:40Z.
Review: CHANGES_REQUESTED
The focused finite-value tests and current automated checks I could inspect pass, but the range fast paths and scaling status handling have observable correctness gaps. I ran a focused GCC 12.2 harness against this exact head; details are attached inline. Please add regression coverage and address these before merge.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T00:58:56Z.
Review: CHANGES_REQUESTED
The updated head still has a range-handling bug in both precision paths. I compiled
DinkumwareInternals.cppfrom this exact head with GCC 12.2 (-std=c++20 -Wall -Wextra -Werror) and linked a focused harness directly to these functions (function-section garbage collection used only to discard unrelated unresolved imports). For_Exp,x = 710,y = 1e-100,offset = 0returns a finite value around2.2339947661617108e208and classificationFinite, but setserrnotoERANGEand raises overflow/inexact flags. Thex > HugeExpearly return is based only onx, even though the actual operation isy * exp(x) * 2^offset; small nonzeroycan bring that product back into range. Conversely, thex < -HugeExpshortcut returns zero forx = -710,y = 1e300, although the product is finite (~4.47628622567513e-9)._FExphas the same shape of defect around itsHugeExpthreshold. Please base range decisions and error signaling on the final scaled product (includingyandoffset), and add both-direction regressions for double and float. If these thresholds intentionally model measured console behavior, please attach evidence showing these products are classified/range-signaled this way on-console; the current debt text says the thresholds and exception behavior are unverified.The implementation file compiles cleanly with
-Wall -Wextra -Werror;git diff --checkandtools/check_conventions.pyalso pass. I did not run the project's full CMake/CTest suite in this environment, and the hosted product Linux/Windows jobs are path-skipped; several hosted cross-platform checks are still pending. These checks do not resolve the numerical cases above.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T01:59:07Z.
Review: COMMENTED
I rechecked the exact current head
878124772c13c76de4e180bc7e801a7c4abb0525after your update. The added subnormal/error tests address the cases listed in your reply, but the two threshold branches remain unchanged: forx > 1842, the function returns signed infinity based only onx; forx < -1842, it returns signed zero based only onx. They still do not account foryoroffset, and the tests shown do not cover compensating multipliers near those cutoffs (my earlierx=710/-710repros are actually below the shortcut threshold, so they expose a separate intermediate/range issue in the scaler path). Please rerun those exact cases against this head and add double/float regressions, or provide console measurements that establish the early-cutoff behavior. I am keeping the existing request for changes until the result range and errno/fenv state are validated for those cases.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T03:06:42Z.
Review: CHANGES_REQUESTED
The sign and status additions address the previous findings, but the x-only cutoffs still violate this helper’s documented
y * exp(x) * 2^offsetbehavior whenoffsetcompensates the exponent. I checked finite reference values independently with the stated formula:_Exp(x=1843, y=1, offset=-2660)is about 0.4623 and_Exp(x=-1843, y=1, offset=2660)is about 2.1630, while the currentx > 1842/x < -1842branches return infinity / zero. The analogous float cases_FExp(x=230, y=1, offset=-332)and_FExp(x=-230, y=1, offset=332)are about 0.8826 and 1.1330; the currentx > 229/x < -229branches also return infinity / zero. Please add these compensating-scale regressions for both precision paths and base the range/error decisions on the final result. Assert the returned classification, stored value, errno and fenv flags. Hosted conventions, eligibility, labels and cross-platform policy jobs pass; product Linux/Windows jobs are skipped, so the reported focused tests do not currently cover this boundary.