fix(libc): return -inf from y0f, y1f and ynf at zero #7906

Merged
Rajkamalcode merged 1 commit from upstream-pr/7906 into main 2026-10-19 16:52:36 +00:00
Rajkamalcode commented 2026-10-19 13:07:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-19T13:07:55Z.


What

The guest's second-kind Bessel functions return -inf with a divide-by-zero signal at +-0 (y0(+-0), y1(+-0) and yn(n,+-0), see e_jn.c), but the UCRT returns NaN for y1 and yn (and raises wrong flags and errno for y0). y0f, y1f and ynf now return the guest result for x == +-0 through a shared helper, and guest_math gains ynf(2, 0.0f) coverage. The libc technical debt entry for these functions notes the special case; the rest of their behaviour still follows the host.

Overlap: #7524 replaces the std::cyl_bessel_j/std::cyl_neumann comparisons in the same test file, a few lines below the new ynf(2, 0.0f) check; this branch is self-contained and will rebase on it if it lands first.

Tested

Windows 11 (22635.5305), MinGW-w64 GCC 15.2.0 (winlibs), Ryzen 5 5600X, based on main f3bb6a4f8. Host probe of the UCRT: y0(+0) = -inf (with ERANGE), y1(+-0) = NaN, yn(2,+-0) = NaN (the full matrix is in a comment below). With Math.cpp at main, ctest --test-dir build -R '^guest_math$' fails at the y1f(0.0f) == -inf check (exit 0xc0000409, FATAL: abort()); with this change it passes. Only the float variants exist (y0/y1/yn are not implemented yet).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4921430047 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7906). Originally posted by [Rajkamalcode](https://github.com/Rajkamalcode) on 2026-10-19T13:07:55Z. --- ### What The guest's second-kind Bessel functions return -inf with a divide-by-zero signal at `+-0` (`y0(+-0)`, `y1(+-0)` and `yn(n,+-0)`, see e_jn.c), but the UCRT returns NaN for `y1` and `yn` (and raises wrong flags and `errno` for `y0`). `y0f`, `y1f` and `ynf` now return the guest result for `x == +-0` through a shared helper, and `guest_math` gains `ynf(2, 0.0f)` coverage. The libc technical debt entry for these functions notes the special case; the rest of their behaviour still follows the host. Overlap: #7524 replaces the `std::cyl_bessel_j`/`std::cyl_neumann` comparisons in the same test file, a few lines below the new `ynf(2, 0.0f)` check; this branch is self-contained and will rebase on it if it lands first. ### Tested Windows 11 (22635.5305), MinGW-w64 GCC 15.2.0 (winlibs), Ryzen 5 5600X, based on `main` f3bb6a4f8. Host probe of the UCRT: `y0(+0) = -inf` (with `ERANGE`), `y1(+-0) = NaN`, `yn(2,+-0) = NaN` (the full matrix is in a comment below). With `Math.cpp` at `main`, `ctest --test-dir build -R '^guest_math$'` fails at the `y1f(0.0f) == -inf` check (exit 0xc0000409, `FATAL: abort()`); with this change it passes. Only the float variants exist (`y0`/`y1`/`yn` are not implemented yet). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Rajkamalcode commented 2026-10-19 13:08:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-19T13:08:12Z.


Host probe of the UCRT's Bessel functions (MinGW-w64 GCC 15.2.0 winlibs, Windows 11, Ryzen 5 5600X), g++ -O2 -o bessel-probe2.exe bessel-probe2.cpp, against the console behaviour of FreeBSD msun e_j0.c / e_j1.c / e_jn.c:

value      result bits                errno  | console
y0(+0)     -inf   (fff0000000000000)  34     | -inf with divide-by-zero
y0(-0)     -inf   (fff0000000000000)  34     | -inf with divide-by-zero
y1(+0)     NaN    (fff8000000000000)  34     | -inf with divide-by-zero   <- fixed here
y1(-0)     NaN    (fff8000000000000)  34     | -inf with divide-by-zero   <- fixed here
yn(2,+0)   NaN    (fff8000000000000)  34     | -inf with divide-by-zero   <- fixed here
yn(2,-0)   NaN    (fff8000000000000)  34     | -inf with divide-by-zero   <- fixed here
y0(-1)     NaN    (fff8000000000000)  33     | NaN with invalid
y1(-1)     NaN    (fff8000000000000)  33     | NaN with invalid
yn(2,-1)   NaN    (fff8000000000000)  33     | NaN with invalid
j0(+0)     1      (3ff0000000000000)  0      | 1
j1(+0)     0      (0000000000000000)  0      | 0
jn(2,+0)   0      (0000000000000000)  0      | 0

errno 34 is ERANGE, 33 is EDOM. y0(+0) already had the right value but the UCRT still sets errno and raises its own flags there, where e_jn.c documents only the divide-by-zero signal for all three functions.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267962368 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7906#issuecomment-6267962368). Originally posted by [Rajkamalcode](https://github.com/Rajkamalcode) on 2026-10-19T13:08:12Z. --- Host probe of the UCRT's Bessel functions (MinGW-w64 GCC 15.2.0 winlibs, Windows 11, Ryzen 5 5600X), `g++ -O2 -o bessel-probe2.exe bessel-probe2.cpp`, against the console behaviour of FreeBSD msun `e_j0.c` / `e_j1.c` / `e_jn.c`: ```text value result bits errno | console y0(+0) -inf (fff0000000000000) 34 | -inf with divide-by-zero y0(-0) -inf (fff0000000000000) 34 | -inf with divide-by-zero y1(+0) NaN (fff8000000000000) 34 | -inf with divide-by-zero <- fixed here y1(-0) NaN (fff8000000000000) 34 | -inf with divide-by-zero <- fixed here yn(2,+0) NaN (fff8000000000000) 34 | -inf with divide-by-zero <- fixed here yn(2,-0) NaN (fff8000000000000) 34 | -inf with divide-by-zero <- fixed here y0(-1) NaN (fff8000000000000) 33 | NaN with invalid y1(-1) NaN (fff8000000000000) 33 | NaN with invalid yn(2,-1) NaN (fff8000000000000) 33 | NaN with invalid j0(+0) 1 (3ff0000000000000) 0 | 1 j1(+0) 0 (0000000000000000) 0 | 0 jn(2,+0) 0 (0000000000000000) 0 | 0 ``` `errno` 34 is `ERANGE`, 33 is `EDOM`. `y0(+0)` already had the right value but the UCRT still sets `errno` and raises its own flags there, where `e_jn.c` documents only the divide-by-zero signal for all three functions.
github-actions[bot] commented 2026-10-19 13:13:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T13:13:43Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7524 core/libs/tests/GuestMath.cpp L878-881

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestMath.cpp
PR 6158 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 6226 docs/dev/debt/libc.md
PR 6295 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 6469 docs/dev/debt/libc.md
PR 6879 core/libs/prx/libc/src/Math.cpp
PR 7081 docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/src/Math.cpp
PR 7332 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
docs/dev/debt/libc.md
PR 7417 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6268075222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7906#issuecomment-6268075222). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T13:13:43Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7524](https://www.github.com/boykopovar/AnyPS5/pull/7524) | `core/libs/tests/GuestMath.cpp` [L878-881](https://github.com/boykopovar/AnyPS5/blob/b00edd174e2b68886d6c6a02cf8e1a408cb1b152/core/libs/tests/GuestMath.cpp#L878-L881) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestMath.cpp` | | [PR 6158](https://www.github.com/boykopovar/AnyPS5/pull/6158) | `core/libs/prx/libc/src/Math.cpp`<br>`core/libs/tests/GuestMath.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6295](https://www.github.com/boykopovar/AnyPS5/pull/6295) | `core/libs/prx/libc/src/Math.cpp`<br>`core/libs/tests/GuestMath.cpp` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/src/Math.cpp` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Math.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/src/Math.cpp`<br>`core/libs/tests/GuestMath.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` |
Sign in to join this conversation.
No reviewers
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!7906
No description provided.