test(libc): cover exp and expf special values and range errors #15141
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15141"
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 Oscar45397 on 2026-11-02T18:23:07Z.
What
expandexpfhave no test.CheckExpSpecialValuesis added toguest_math_exact:exp(+-0) == 1,exp(+inf) == +inf,exp(-inf) == +0(positive zero),exp(NaN)is NaN;exp(1)andexp(-1)within a relative 1e-15 of e and 1/e (2.718281828459045,0.36787944117144233);exp(710)overflows to+infwitherrno == ERANGE(ln of DBL_MAX is about 709.78);exp(-746)is 0 (below half the smallest subnormal, whose natural logarithm is about -744.44);expf, withexpf(1)within a relative 1e-6,expf(89)overflowing to+infwithERANGE(ln of FLT_MAX is about 88.72) andexpf(-110)equal to 0.Sources: C11 F.10.3.1 (
exp(+-0)returns 1,exp(-inf)returns +0,exp(+inf)returns +inf); POSIXexp: a range error occurs on overflow and the function returns HUGE_VAL, witherrnoset toERANGE. The overflow and underflow thresholds follow from the logarithms of the largest finite and smallest subnormal values of each format.Changed:
core/libs/tests/GuestMathExact.cpp. Test only, no change to the library.Tested
Windows 11 Home 26200, Ryzen 9 5900X, WinLibs GCC 15.2.0 r7, Release, on
mainb28bb77217plus this test.ctest --test-dir build -R '^guest_math_exact$' --repeat until-fail:3: passes 3 of 3 runs.expfreturningstd::exp2(x),guest_math_exactfails. Restored, it passes again.python tools/check_conventions.py --base upstream/main: passed.Not run on Linux or macOS: the
ERANGEchecks rely on the hostexpsettingerrno, which POSIX requires.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 BunnyFl on 2026-11-02T19:45:27Z.
Review: APPROVED
The
errnorows hold for the console's system libc too, not only for the host math libraries. Firmware 13.42'ssystem/common/lib/libSceLibcInternal.sprx(sha256a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285), disassembly only:exp,expf,log,logfandpowall report errors through one helper at0x16450, which stores into the location returned by its call at0x16463and picks0x21(EDOM) when bit 0 of its flag argument is set, otherwise0x22(ERANGE) when any of bits0x1cis set:For example
expcalls it with 8 on overflow (4c323). I haven't read every call site's flag, and I haven't checked thelibc.prxthat titles ship, which the debt file says uses FreeBSD msun. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged ontomain:guest_math_exactpasses.