test(libc): cover pow special values and the signs of its zero and infinite results #15143

Merged
Oscar45397 merged 3 commits from upstream-pr/15143 into main 2026-11-28 03:59:51 +00:00
Oscar45397 commented 2026-11-02 18:23:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Oscar45397 on 2026-11-02T18:23:12Z.


What

pow has no test. CheckPowSpecialValues is added to guest_math_exact, one assertion group per rule of C11 F.10.4.4:

  • exact results: pow(2, 10) == 1024, pow(-2, 3) == -8, pow(-2, 2) == 4, pow(2, -1) == 0.5;
  • pow(x, +-0) == 1 for any x including NaN and +inf; pow(1, y) == 1 for any y including NaN and +-inf; pow(NaN, 1) and pow(2, NaN) are NaN;
  • pow(+-0, y) for y an odd negative integer is +-inf; for y negative and not an odd integer (-2, -inf) it is +inf; for y an odd positive integer it is +-0 with the sign of x; for y positive and not an odd integer (2, 0.5) it is +0;
  • pow(-1, +-inf) == 1; pow(x, +inf) is +0 for |x| < 1 and +inf for |x| > 1; pow(x, -inf) is the reverse;
  • pow(+inf, y) is +0 for y < 0 and +inf for y > 0; pow(-inf, y) is -0 for y an odd negative integer, +0 for other negative y, -inf for y an odd positive integer, +inf for other positive y;
  • pow(-8, 0.5) and pow(-2, -1.5) (finite negative x, finite non-integer y) are NaN;
  • pow(10, 400) overflows to +inf and pow(10, -400) underflows to 0.

errno is not asserted.

Sources: C11 F.10.4.4 for every special value above; the overflow and underflow cases follow from DBL_MAX being about 1.8e308 and the smallest subnormal about 4.9e-324.

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 main b28bb77217 plus this test.

  • ctest --test-dir build -R '^guest_math_exact$' --repeat until-fail:3: passes 3 of 3 runs.
  • Red control: with pow computing std::pow(std::fabs(base), exp), guest_math_exact fails. Restored, it passes again.
  • python tools/check_conventions.py --base upstream/main: passed.

Not run on Linux or macOS.

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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded coverage for power calculations involving ordinary values, zero, NaN, signed zero, infinities, negative bases with fractional exponents, and overflow or underflow cases.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5125302528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15143). Originally posted by [Oscar45397](https://github.com/Oscar45397) on 2026-11-02T18:23:12Z. --- ### What `pow` has no test. `CheckPowSpecialValues` is added to `guest_math_exact`, one assertion group per rule of C11 F.10.4.4: - exact results: `pow(2, 10) == 1024`, `pow(-2, 3) == -8`, `pow(-2, 2) == 4`, `pow(2, -1) == 0.5`; - `pow(x, +-0) == 1` for any x including NaN and `+inf`; `pow(1, y) == 1` for any y including NaN and `+-inf`; `pow(NaN, 1)` and `pow(2, NaN)` are NaN; - `pow(+-0, y)` for y an odd negative integer is `+-inf`; for y negative and not an odd integer (-2, `-inf`) it is `+inf`; for y an odd positive integer it is `+-0` with the sign of x; for y positive and not an odd integer (2, 0.5) it is `+0`; - `pow(-1, +-inf) == 1`; `pow(x, +inf)` is `+0` for |x| < 1 and `+inf` for |x| > 1; `pow(x, -inf)` is the reverse; - `pow(+inf, y)` is `+0` for y < 0 and `+inf` for y > 0; `pow(-inf, y)` is `-0` for y an odd negative integer, `+0` for other negative y, `-inf` for y an odd positive integer, `+inf` for other positive y; - `pow(-8, 0.5)` and `pow(-2, -1.5)` (finite negative x, finite non-integer y) are NaN; - `pow(10, 400)` overflows to `+inf` and `pow(10, -400)` underflows to 0. `errno` is not asserted. Sources: C11 F.10.4.4 for every special value above; the overflow and underflow cases follow from DBL_MAX being about 1.8e308 and the smallest subnormal about 4.9e-324. Changed: `core/libs/tests/GuestMathExact.cpp`. Test only, no change to the library. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Home 26200, Ryzen 9 5900X, WinLibs GCC 15.2.0 r7, Release, on `main` b28bb77217 plus this test. - `ctest --test-dir build -R '^guest_math_exact$' --repeat until-fail:3`: passes 3 of 3 runs. - Red control: with `pow` computing `std::pow(std::fabs(base), exp)`, `guest_math_exact` fails. Restored, it passes again. - `python tools/check_conventions.py --base upstream/main`: passed. Not run on Linux or macOS. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Expanded coverage for power calculations involving ordinary values, zero, NaN, signed zero, infinities, negative bases with fractional exponents, and overflow or underflow cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
BunnyFl commented 2026-11-02 19:45:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T19:45:33Z.

Review: APPROVED


The special cases are the C99 Annex F pow table, including pow(x, ±0) = 1 for NaN x, pow(+1, y) = 1 for NaN y, the signed zeros and infinities from pow(±0, y) and pow(-∞, y) by odd/even integer y, pow(-1, ±∞) = 1, and NaN for a negative finite base with a non-integer exponent. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto main: guest_math_exact passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5742375274 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15143#pullrequestreview-5742375274). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T19:45:33Z. **Review:** APPROVED --- The special cases are the C99 Annex F `pow` table, including `pow(x, ±0) = 1` for NaN `x`, `pow(+1, y) = 1` for NaN `y`, the signed zeros and infinities from `pow(±0, y)` and `pow(-∞, y)` by odd/even integer `y`, `pow(-1, ±∞) = 1`, and NaN for a negative finite base with a non-integer exponent. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto `main`: `guest_math_exact` passes.
MarcZX10 commented 2026-11-21 12:56:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:56:27Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this test-only change; the reviewed assertions align with the stated pow special-value cases.

What I ran

Read the prepared diff and the full changed file at head c1832d8e2438615b71f2142bcf846dc4b0c6ac85 using repo_read.py. I did not run tests or other commands.

Results

Check Result Note
Diff and changed file review passed One changed test file read
Automated checks not run No commands run in this review

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests and conventions checks reported in the PR description were not run by me. No files were excluded from review: core/libs/tests/GuestMathExact.cpp was included in the prepared bundle and read in full. The review bundle did not provide files.json; exclusion status beyond the manifest was not verified. No other repository files were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005318574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15143#pullrequestreview-6005318574). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T12:56:27Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this test-only change; the reviewed assertions align with the stated `pow` special-value cases. ## What I ran Read the prepared diff and the full changed file at head `c1832d8e2438615b71f2142bcf846dc4b0c6ac85` using `repo_read.py`. I did not run tests or other commands. ## Results | Check | Result | Note | |---|---|---| | Diff and changed file review | passed | One changed test file read | | Automated checks | not run | No commands run in this review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests and conventions checks reported in the PR description were not run by me. No files were excluded from review: `core/libs/tests/GuestMathExact.cpp` was included in the prepared bundle and read in full. The review bundle did not provide `files.json`; exclusion status beyond the manifest was not verified. No other repository files were read. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-27 21:32:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T21:32:49Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed test change blocks merging; the assertions exercise the stated pow special values and signed results.

What I ran

Reviewed head 6ebaab5c69623a16995ce6bffe1d26b52d16427b. No commands or tests were run; repo_read.py was unavailable as an executable tool in this session. The author reports three passing guest_math_exact runs and a passing conventions check; those were not independently run.

Results

Check Result Note
Diff review passed One test file changed
Runtime checks not run Author reports three passing runs
Conventions check not run Author reports pass

Findings

Blocking

None.

Non-blocking

None.

Not verified

The manifest lists core/libs/tests/GuestMathExact.cpp as reviewed and included; its relevant changed function, invocation, and includes were read. No other changed files were listed. No runtime, build, or conventions checks were performed; the reported test environment was Windows 11 with GCC 15.2.0. Linux, macOS, and console behavior were not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6093510080 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15143#pullrequestreview-6093510080). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T21:32:49Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed test change blocks merging; the assertions exercise the stated `pow` special values and signed results. ## What I ran Reviewed head `6ebaab5c69623a16995ce6bffe1d26b52d16427b`. No commands or tests were run; `repo_read.py` was unavailable as an executable tool in this session. The author reports three passing `guest_math_exact` runs and a passing conventions check; those were not independently run. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | One test file changed | | Runtime checks | not run | Author reports three passing runs | | Conventions check | not run | Author reports pass | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The manifest lists `core/libs/tests/GuestMathExact.cpp` as reviewed and included; its relevant changed function, invocation, and includes were read. No other changed files were listed. No runtime, build, or conventions checks were performed; the reported test environment was Windows 11 with GCC 15.2.0. Linux, macOS, and console behavior were not verified. ## To get this to a good state Nothing is required.
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!15143
No description provided.