libc: double and float libm against the libc.prx bundled with PPSA10122 (SDK 5.00): flags and errno on Windows #23411

Open
opened 2026-11-19 00:49:10 +00:00 by DerKarussellbremser · 0 comments
DerKarussellbremser commented 2026-11-19 00:49:10 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by DerKarussellbremser on 2026-11-19T00:49:10Z.


The double and float counterpart of #22838: the same harness, the same module (sce_module/libc.prx of PPSA10122 01.101.000, SDK 5.00, run natively on Windows), 43 functions in each precision, 200,000 arguments or pairs per function, this libc at main 9ffa95e7d9.

Arguments are a quarter raw bit patterns (NaNs, infinities and subnormals included), a quarter uniform in ±4, a quarter uniform in ±40 and a quarter with exponents from 2^-20 to 2^20. Compared are the result bits (two NaNs count as equal), the union of the x87 and MXCSR exception flags, and errno. A row counts under "flags" only if its bits agree, and under "errno" only if bits and flags agree.

Identical in all three (57 of 86): sin, cos, tan, acos, sinh, cosh, tanh, asinh, acosh, atanh, exp, exp2, expm1, log, log2, log10, log1p, cbrt, sqrt, ceil, floor, trunc, rint, logb, fabs, pow, hypot, remainder, fmax, fmin, copysign, nextafter, and for float sinf, cosf, tanf, sinhf, asinhf, acoshf, atanhf, exp2f, expm1f, log2f, log10f, cbrtf, sqrtf, ceilf, floorf, truncf, rintf, logbf, fabsf, hypotf, remainderf, fmaxf, fminf, copysignf, nextafterf.

Different

function bits flags errno what differs in the examples I looked at
round, roundf 0 23,891 / 20,383 0 module raises FE_INEXACT from 2^53 / 2^24 up. Fixed in #23410.
fdim, fdimf 0 22 / 195 0 signaling NaN: module raises nothing. Fixed in #23410.
asin, atan 0 24,201 / 24,156 0 tiny argument: module raises FE_INEXACT, this libc nothing
asinf, atanf 0 34,484 / 53,427 0 same; for a very small argument (2^-97) the module's atanf also raises FE_UNDERFLOW
coshf 0 34,484 39,096 tiny argument: module raises FE_INEXACT. Overflow: module sets ERANGE
tanhf 0 116,993 0 tiny argument: module raises FE_INEXACT. Large argument (result ±1): this libc raises it, the module does not
erf, erfc 0 87,924 / 28,738 0 saturated result (±1, 2): this libc raises FE_INEXACT, the module nothing
atan2f 0 33,702 0 module also raises FE_UNDERFLOW (seen with results ±pi and with tiny results)
powf 0 1,428 0 module also raises FE_OVERFLOW (seen with a huge base and a small or negative exponent)
logf 0 57 0 NaN argument: module raises FE_INVALID and sets EDOM
lgamma 0 12 0 NaN argument: this libc raises FE_INVALID, the module nothing
atan2, fmod, nearbyint, acosf, nearbyintf, fmodf, tgammaf 0 155, 84, 31, 189, 189, 651, 3,127 0 only the denormal-operand bit, which is not a C exception flag (this libc sets it, the module does not; for atan2 the other way round)
tgamma 75,693 27,619 0 last bits; overflow raises FE_DIVBYZERO in the module and FE_OVERFLOW here
lgammaf 64,576 122 0 last bit
expf 11,543 101 19,235 open in #10113
log1pf 14,489 154 0 open in #10007
erff, erfcf 46,882 / 26,921 9,430 / 60,852 0 open in #10226

How I read it. Apart from the last five rows this is all exception flags, and most of it looks like compiler output rather than different algorithms: where msun writes if (huge + x > one) return x; the module's build really does the addition, and where msun writes one - tiny with two constants the module's build has folded it, so no flag is raised. The round family is the same kind of thing (the unselected t + 1 is computed).

I have not changed any of these beyond #23410. Several debt entries state the current flag behaviour on purpose or say flags are not compared (asinf and atanf: "Tiny arguments return x without raising FE_INEXACT"; asin, atan, tanhf: flags not compared), and those entries rest on other titles' modules. Whether a different title's build folds the same expressions is exactly what one module cannot tell. If the flags of this module are wanted for some of these rows, say which, and I will do them one function per pull request.

Limits. One module, one SDK version, a Windows host. MXCSR left at round-to-nearest. NaN payloads are not compared. The examples column is from the first few differing arguments of each row, not from all of them.

AI-assisted (Claude Code); the runs are from my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6479839308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/23411). Originally posted by [DerKarussellbremser](https://github.com/DerKarussellbremser) on 2026-11-19T00:49:10Z. --- The `double` and `float` counterpart of #22838: the same harness, the same module (`sce_module/libc.prx` of PPSA10122 01.101.000, SDK 5.00, run natively on Windows), 43 functions in each precision, 200,000 arguments or pairs per function, this libc at `main` 9ffa95e7d9. Arguments are a quarter raw bit patterns (NaNs, infinities and subnormals included), a quarter uniform in ±4, a quarter uniform in ±40 and a quarter with exponents from 2^-20 to 2^20. Compared are the result bits (two NaNs count as equal), the union of the x87 and MXCSR exception flags, and `errno`. A row counts under "flags" only if its bits agree, and under "`errno`" only if bits and flags agree. **Identical in all three** (57 of 86): `sin`, `cos`, `tan`, `acos`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, `exp`, `exp2`, `expm1`, `log`, `log2`, `log10`, `log1p`, `cbrt`, `sqrt`, `ceil`, `floor`, `trunc`, `rint`, `logb`, `fabs`, `pow`, `hypot`, `remainder`, `fmax`, `fmin`, `copysign`, `nextafter`, and for `float` `sinf`, `cosf`, `tanf`, `sinhf`, `asinhf`, `acoshf`, `atanhf`, `exp2f`, `expm1f`, `log2f`, `log10f`, `cbrtf`, `sqrtf`, `ceilf`, `floorf`, `truncf`, `rintf`, `logbf`, `fabsf`, `hypotf`, `remainderf`, `fmaxf`, `fminf`, `copysignf`, `nextafterf`. **Different** | function | bits | flags | `errno` | what differs in the examples I looked at | |---|---|---|---|---| | `round`, `roundf` | 0 | 23,891 / 20,383 | 0 | module raises `FE_INEXACT` from 2^53 / 2^24 up. Fixed in #23410. | | `fdim`, `fdimf` | 0 | 22 / 195 | 0 | signaling NaN: module raises nothing. Fixed in #23410. | | `asin`, `atan` | 0 | 24,201 / 24,156 | 0 | tiny argument: module raises `FE_INEXACT`, this libc nothing | | `asinf`, `atanf` | 0 | 34,484 / 53,427 | 0 | same; for a very small argument (2^-97) the module's `atanf` also raises `FE_UNDERFLOW` | | `coshf` | 0 | 34,484 | 39,096 | tiny argument: module raises `FE_INEXACT`. Overflow: module sets `ERANGE` | | `tanhf` | 0 | 116,993 | 0 | tiny argument: module raises `FE_INEXACT`. Large argument (result ±1): this libc raises it, the module does not | | `erf`, `erfc` | 0 | 87,924 / 28,738 | 0 | saturated result (±1, 2): this libc raises `FE_INEXACT`, the module nothing | | `atan2f` | 0 | 33,702 | 0 | module also raises `FE_UNDERFLOW` (seen with results ±pi and with tiny results) | | `powf` | 0 | 1,428 | 0 | module also raises `FE_OVERFLOW` (seen with a huge base and a small or negative exponent) | | `logf` | 0 | 57 | 0 | NaN argument: module raises `FE_INVALID` and sets `EDOM` | | `lgamma` | 0 | 12 | 0 | NaN argument: this libc raises `FE_INVALID`, the module nothing | | `atan2`, `fmod`, `nearbyint`, `acosf`, `nearbyintf`, `fmodf`, `tgammaf` | 0 | 155, 84, 31, 189, 189, 651, 3,127 | 0 | only the denormal-operand bit, which is not a C exception flag (this libc sets it, the module does not; for `atan2` the other way round) | | `tgamma` | 75,693 | 27,619 | 0 | last bits; overflow raises `FE_DIVBYZERO` in the module and `FE_OVERFLOW` here | | `lgammaf` | 64,576 | 122 | 0 | last bit | | `expf` | 11,543 | 101 | 19,235 | open in #10113 | | `log1pf` | 14,489 | 154 | 0 | open in #10007 | | `erff`, `erfcf` | 46,882 / 26,921 | 9,430 / 60,852 | 0 | open in #10226 | **How I read it.** Apart from the last five rows this is all exception flags, and most of it looks like compiler output rather than different algorithms: where msun writes `if (huge + x > one) return x;` the module's build really does the addition, and where msun writes `one - tiny` with two constants the module's build has folded it, so no flag is raised. The `round` family is the same kind of thing (the unselected `t + 1` is computed). I have not changed any of these beyond #23410. Several debt entries state the current flag behaviour on purpose or say flags are not compared (`asinf` and `atanf`: "Tiny arguments return `x` without raising `FE_INEXACT`"; `asin`, `atan`, `tanhf`: flags not compared), and those entries rest on other titles' modules. Whether a different title's build folds the same expressions is exactly what one module cannot tell. If the flags of this module are wanted for some of these rows, say which, and I will do them one function per pull request. **Limits.** One module, one SDK version, a Windows host. MXCSR left at round-to-nearest. NaN payloads are not compared. The examples column is from the first few differing arguments of each row, not from all of them. AI-assisted (Claude Code); the runs are from my machine.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#23411
No description provided.