Skip to content

fix(libc): compute pow with fdlibm's algorithm, as titles' libc.prx does - #10265

Merged
oneandonlydean merged 7 commits into
boykopovar:mainfrom
JJenkx:windows/libc-pow-fdlibm
Nov 4, 2026
Merged

oneandonlydean merged 7 commits into
boykopovar:mainfrom
JJenkx:windows/libc-pow-fdlibm

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

pow returned the host's pow, so its last bit, a few special values and its errno depended on the host. On Windows (UCRT) it differs from the libc.prx that titles ship on 17,275,531 of 320 million random pairs. For example, pow(0x3feafced736ee4fe, 0xc0361f9e443ea358) (about 0.843^-22.12) is 0x4045a8e0115e099a in the bundled libc.prx and 0x4045a8e0115e099b here.

The titles' copy (NID 9LCjpWyQ5Zc) is FreeBSD msun's e_pow.c, except for two special cases where it keeps the original fdlibm rules. msun later changed both to C99's, in 11.4 and already in 59bc2f0952:

call bundled libc msun 11.4 and C99
pow(1, NaN), pow(1, ±inf) NaN 1
pow(-1, ±inf) NaN (y - y) 1

Without the x == 1 shortcut, a NaN argument reaches msun's (x + 0.0) + (y + 0.0), and an infinite y with |x| == 1 returns y - y. pow now computes msun's algorithm with those two rules:

  • the yisint classification;
  • the special-value table;
  • the |y| > 2^31 path, with its huge-y shortcuts;
  • the log2(|x|) expansion with the bp, dp_h and dp_l tables;
  • the y1 * t1 split;
  • the final 2^(p_h + p_l) reconstruction.

errno: msun sets none. The titles' copy sets it in exactly these places:

  • EDOM at the two returns where a negative base meets a non-integer exponent: the general (x - x) / (x - x), and the (z - z) / (z - z) for -1 raised to a non-integer;
  • ERANGE only in the final overflow (z >= 1024) and underflow (z <= -1075) checks, including their exact-boundary cases.

The huge-y shortcuts (|y| > 2^31) overflow or underflow without errno, and so does pow(±0, negative) returning ±inf. This port sets errno in the same places.

Tested

Current-main integration — 2026-11-03. Head 3bf30fd4920e751df3825b9abb75f7a0832ecf37 includes main 4f41f4c375f5abb487dbd184fbc150f31994d762 and retains the prior public history and attribution/licence notices. Main’s newer math implementations and fixtures remain alongside this topic.

Linux x86-64 Release, GCC 16.2.1, Ninja, BUILD_TESTING=ON: rebuilt actual libc and math executables. guest_math, guest_math_exact, and guest_dinkumware_internals each pass 3/3 (9 passes, zero skips); public_headers and conventions pass. The same three groups pass 3/3 plus headers on pinned main. All 34 recursive dependency trees and 31,551 tracked blobs verify with zero errors; the update=none QuickJS test262 corpus is excluded from these library inputs. Whitespace check passes.

Source/parent/gitlink proofs, exact library/test hashes, raw logs/JUnit, and head-leased push receipts: qualification archive, SHA-256 e6a50522bc28e30871fdc2c12a88d2537515914239e8166f6237f48895126a06 (download verified). Older platform/reference reports retain their original pins; no new Windows/macOS, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).

Earlier dated qualifications below retain their recorded source/platform pins.

Current-main integration (2026-11-02): 1c4650937d284044ea1f26ea386e21289e8c20e9 includes main a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8 and retains the existing public commits. Conflicts preserve main’s math implementations, regression checks and debt entries alongside this topic. Linux x86-64 Release, GCC 16.2.1: rebuilt libc and the three math executables; guest_math, guest_math_exact and guest_dinkumware_internals each pass three times (9 passes, zero skips), and public_headers passes. The same baseline groups pass on main; conventions and whitespace pass. Source and dependency blobs, executable/library hashes, raw logs and JUnit are retained. This refresh adds no new console, Windows, title, GPU or numerical-reference measurement. Qualification evidence, SHA-256 22866bd2a060ba69cd4387d471605afe20ed644e3257174b2d1488635f8c9b52 (download verified).

Current Linux refresh: 1d7f78cfac7e6ae3ebe20a7ddda35746c7b9b57a on main 6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. Fresh isolated libc/math build passed; guest_math and guest_dinkumware_internals each passed three consecutive runs. Diff and conventions checks pass; Math.cpp and GuestMath.cpp topic changes remain unchanged after rebase. Linux logs and rebase checks.

The Windows module comparisons and negative control below are historical evidence from original head be1f1e6b223e95b0585f63bd104c70c0d38c7b81; Windows was not rerun on the refreshed commit. Results described as console results mean supplied titles' bundled libraries executed on the Windows host, not measurements on a physical console.

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, main 15e71db.

  • Comparison: a scratch loader runs the decrypted libc.prx of PPSA07923, PPSA05916 and PPSA13934 natively and supplies __error. It compared their pow with this PR's code, checking result bits (NaN payloads included) and errno, on:

    • 320 million random pairs per title: a quarter random bit patterns, a quarter [0, 10) to the power [-100, 100), a quarter negative bases with integer exponents, and a quarter with both exponents near 1;
    • all 2,916 pairs of 54 special values: signed zeros, subnormals, 1 and its neighbours, 0.001, 1/3, 0.5, 1.5, 2, 3, 5, 10, 1024, 1231, a large odd integer just below 2^53, 2^31 and its neighbour, 2^53 and 2^64 with their neighbours, DBL_MAX, the infinities, and quiet and signalling NaNs of both signs.

    Results:

    • PPSA07923 and PPSA05916: identical bits and errno on all of them.
    • PPSA13934: identical errno. The bits differ on 85,862 random pairs, because that copy is an FMA-contracted build.
  • How the errno rule was found: I compiled msun's e_pow.c with every return instrumented and tabulated the bundled library's errno per return. Only the two NaN returns set EDOM and only the four final overflow/underflow returns set ERANGE. Direct probes of pow(2, ±1024), pow(2, -1075), pow(10, 308.25…) and pow(-1, 0.5) confirm the edges.

  • guest_math: the new CheckPowConsoleBits has 39 cases with the bundled library's results and errno:

    • x^0, NaN^0, 1^NaN, NaN^1;
    • (-1)^±inf, 0.5^inf, 2^-inf;
    • y = ±1, 2 and 0.5, (-4)^0.5 and (-1)^0.5, (-8)^3 and (-8)^2;
    • ±0^-1, -0^3, -inf^3 and -inf^0.5;
    • 2^1024, 2^1023, 2^-1074, ±2^-1075, 10^308 and 10^309;
    • the huge-y shortcuts with no errno;
    • a subnormal to the 0.5;
    • six pairs where UCRT differs.

    guest_math and guest_dinkumware_internals pass in three runs out of three on the exact head.

  • Negative control: with main's Math.cpp and these tests, guest_math aborts in a Require, while guest_dinkumware_internals still passes.

  • python tools/check_conventions.py --base origin/main and git diff --check pass.

  • Overlap and order: Refreshed as a standalone pow topic on main 6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. The old dependencies described series order and shared source/test/debt anchors, rather than required function implementations. This branch contains only its pow implementation and tests. The pow port uses its own word helpers and existing host sqrt/scalbn; no other open math port is needed.

  • Not tested: macOS, a physical console, floating-point exception flags, and powl. Original module comparison and negative control were Windows-only; the new Linux build and regression checks are scoped separately above.

Current Linux qualification (2026-10-28)

Rebased onto main 2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at 9a47f3f91057dce364da821dd903861dfc3eb4ee (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).

libc, guest_math_tests and guest_math_exact_tests rebuilt from this exact source. guest_math and guest_math_exact each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.

Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256 1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.

Canonical declaration cleanup (2026-10-28)

At 7d51a8b3314a, removed 93 duplicate local export declarations from GuestMath.cpp; its included Api.hpp supplies them. Production code and numeric test bodies are unchanged. Original fails the actual header audit; candidate passes. Per-branch affected-test syntax compilation and conventions/whitespace pass; full standalone-header compilation passed once for the byte-identical header tree shared by the four affected PRs. Source/proofs/logs, SHA256 44f560018e4f6b52e8dda4158383f64fc3059fcdb6444840fe5c04fb2c884f11. No new numerical-runtime/platform claim; earlier runs retain original pins. Normal fast-forward only, no rebase. AI-assisted: Codex.

Checklist

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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 5303 docs/dev/debt/libc.md
PR 6295 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 10405 docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11724 docs/dev/debt/libc.md
PR 11831 docs/dev/debt/libc.md
PR 12849 docs/dev/debt/libc.md
PR 13449 docs/dev/debt/libc.md
PR 13486 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 13809 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md

@JJenkx

JJenkx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head be1f1e6b22 (be1f1e6b223e95b0585f63bd104c70c0d38c7b81), not merged onto anything else; its base on main is 15e71dbe11.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON.

  • guest_math: passed in each of 3 runs, exit code 0 each time, with no failed, skipped or not-run tests.

This is the focused test only; no title, console or floating-point exception flags were checked.

AI-assisted: yes (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@JJenkx
JJenkx force-pushed the windows/libc-pow-fdlibm branch from be1f1e6 to 1d7f78c Compare October 24, 2026 05:01
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
JJenkx pushed a commit to JJenkx/AnyPS5 that referenced this pull request Oct 24, 2026
Additive conflicts with main's newer libc math changes: the debt list keeps
both sides' entries (per entry), the GuestMath.cpp test functions and calls
from both sides are kept, and Math.cpp keeps both sides' independent changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main 1e20650e84 into this branch as d2e8ace216 (was 1d7f78cfac), a merge commit rather than a rebase. Done on Linux while the Windows session is paused.

  • The conflicts were additive, next to main's newer libc math changes.
  • The docs/dev/debt/libc.md entry list keeps both sides' entries, checked per entry: this PR's entries keep their exact text, and so do main's.
  • GuestMath.cpp keeps both sides' test functions and calls.
  • New head, Linux only: guest_math and guest_math_exact pass (Arch Linux, kernel 7.2.9, GCC 16.2.1, glibc 2.44, Release, BUILD_TESTING=ON). tools/check_conventions.py --base origin/main reports no errors.
  • Earlier Windows and comparison evidence in this thread stays pinned to the heads it was measured on.

AI-assisted: yes (Claude Code)

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main 6cd36e6 and FreeBSD release/11.4.0 lib/msun/src/e_pow.c:

  • Compared pow_nid_postfix with e_pow.c line by line. The algorithm, every constant (identical literals) and the overflow/underflow checks match. The only changes are the two documented fdlibm rules: no x == 1 shortcut, and y - y for |x| == 1 with infinite y.
  • errno is set only at the two NaN returns (EDOM) and the final overflow/underflow returns (ERANGE), matching the description and the debt entry.
  • Ran all 39 CheckPowConsoleBits cases through an independent Python port of the 11.4 source with the same two changes; every result and errno matches.
  • It merges cleanly onto current main. With the other open msun PRs it only conflicts at the shared insertion points in GuestMath.cpp, and nothing is defined twice. Looks good to me.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

@ycbuzi

ycbuzi commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Windows run of d2e8ace merged onto main fa515de (f50ed6a11c, clean), since Windows was not run on this head. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libc, guest_math_tests and guest_dinkumware_internals_tests with no errors or warnings. ctest --repeat until-fail:2 on guest_math and guest_dinkumware_internals: both pass on both repeats. Negative control: with src/Math.cpp taken from main and the rest of this head, guest_math aborts (exit code 0xc0000409) and guest_dinkumware_internals still passes. Not run: a title.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@JJenkx

JJenkx commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Merged main 5bc84038c4 into this branch as bcac32c81b (was da6f196542), a merge commit rather than a rebase, after today's main changes conflicted again.

  • The conflicts were additive. docs/dev/debt/libc.md keeps each side's entry changes, checked per entry including deletions. GuestMath.cpp keeps both sides' test functions and calls. Where Math.cpp conflicted, the merged file differs from main by exactly this branch's own changes.
  • New head, Linux only: guest_math and guest_math_exact pass (Arch Linux, GCC 16.2.1, Release, BUILD_TESTING=ON). tools/check_conventions.py --base origin/main adds no new findings, and the branch still merges cleanly with main 801d5b9bc1.
  • Earlier Windows and comparison evidence in this thread stays pinned to the heads it was measured on.

AI-assisted: yes (Claude Code)

JJenkx pushed a commit to JJenkx/AnyPS5 that referenced this pull request Oct 27, 2026
Conflicts with main's newer libc changes resolved without changing either
side: the debt list keeps each side's entry changes (per entry, deletions
included), GuestMath.cpp keeps both sides' test functions and calls, and
Math.cpp differs from main by exactly this branch's own changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@JJenkx heads-up: the last "merge main" here also moved submodule pointers back (3rdparty/SPIRV-* / 3rdparty/vorbis), undoing recent main updates. I pushed one commit on top that resets them to main's (build: restore submodule pointers to main); nothing else changed. Please pull before your next push.

@JJenkx

JJenkx commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, and sorry for the noise. The cause was on my side: I merged main in a worktree whose submodules were still checked out at older commits, then staged everything, so the merge recorded those older checkouts over main's SPIRV-Headers, SPIRV-Tools and vorbis pointers. Your commit is right; this branch's own changes touch no submodules.

The same refresh hit five more branches (#10345, #10229, #10222, #10226, #10113). Each now has the same one-commit pointer restore on top, and none differs from main's gitlinks. I've changed my merge script to stage only the resolved files, and it now rejects any merge whose submodule pointers differ from what a three-way merge gives. No earlier merges of mine were affected.

AI-assisted: yes (Claude Code)

@JJenkx

JJenkx commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head 2c988d8268 (2c988d82684b9f4cbb4b3c9f5960cfd1032feb59), not merged onto anything else; its base on main is 5bc84038c4.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON.

Passed in each of 3 runs, exit code 0 each time, with no failed, skipped or not-run tests:

  • guest_math

These are the focused tests only; no title or console was used.

AI-assisted: yes (Claude Code).

Titles' libc.prx raises FE_UNDERFLOW and FE_INEXACT when pow underflows
for 2^31 < |y| <= 2^64 and at the final range check, and raises nothing
for |y| > 2^64, where its huge * huge and tiny * tiny were folded into
constants. Here GCC folded every tiny * tiny product, so no underflow
flag was raised, while huge * huge for |y| > 2^64 raised FE_OVERFLOW.

Return +inf directly for |y| > 2^64 and compute the other underflowing
products through a volatile, so the flags match on every path. Results
and errno are unchanged. CheckPowRangeFlags covers each path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx
JJenkx force-pushed the windows/libc-pow-fdlibm branch from ea959ec to 9a47f3f Compare October 28, 2026 12:31
@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at 9a47f3f91057dce364da821dd903861dfc3eb4ee (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).

libc, guest_math_tests and guest_math_exact_tests rebuilt from this exact source. guest_math and guest_math_exact each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.

Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256 1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.

AI-assisted: yes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 28, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@JJenkx the pow change itself is unchanged in substance since the last review. One regression came in with the restack: at 9a47f3f, core/libs/tests/GuestMath.cpp lines 39-131 add 93 local declarations (logbf_nid_postfix, ilogb_nid_postfix, exp2_nid_postfix, ... the whole block) for exports that core/libs/prx/libc/include/Api.hpp already declares and the test already includes. The head I reviewed before (2c988d8) had none of them, and main's test has none.

The project rule is exactly one declaration per export, in the library header, and the public_headers audit (core/libs/tests/test_public_headers.py) counts every declaration under core/ and reports "expected exactly one header declaration; found 2" for each of these names, so public_headers and public_headers_compile_* should go red on this head. Please drop that block; the test only needs the declarations it already gets from Api.hpp. Nothing else in the file needs to change.

@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Fixed in 7d51a8b3314a, a normal fast-forward on 9a47f3f91057. Removed the 93 local export function declarations from GuestMath.cpp; it uses the canonical declarations from its existing libc/include/Api.hpp include. Production Math.cpp, the branch base and numeric test bodies are unchanged.

The repository's actual header audit rejects the original duplicate block and passes after removal. This branch's GuestMath.cpp syntax-compiles against its real headers; conventions and whitespace checks pass. All four affected PRs have byte-identical tracked header trees (logical path + blob SHA), so full standalone-header compilation was run once against that common tree and passed; per-branch definition audits and affected-test compilation were checked individually.

All four source deltas/pins, negative controls, audits and compilation logs, SHA256 44f560018e4f6b52e8dda4158383f64fc3059fcdb6444840fe5c04fb2c884f11 (download verified). Linux/GCC16.2.1; no fresh numeric-runtime, Windows, title or performance claim. Earlier numerical reports retain their original pins. Public rebasing remains with the separately assigned worker; preserve this test-only follow-up.

AI-assisted: yes (Codex).

@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

A remaining flag-only difference, recorded for completeness; the values and errno match. In a special-value run against PPSA07923's libc.prx, I combined this PR with my other open math PRs. For a huge base with a negative exponent, for example pow(1e300, -2) or pow(1e300, -0.5), the titles' pow raises FE_OVERFLOW in addition to the underflow, while this PR raises only FE_UNDERFLOW (and nothing for -0.5). That's 9 of 441 special-value pairs.

fdlibm's e_pow.c reaches those results through s*tiny*tiny, which can't raise overflow. So the titles' copy must take a different internal step, and pinning it down needs the disassembly. I haven't done that, and this PR's description doesn't claim exception-flag fidelity for these inputs.

AI-assisted: yes (Claude Code).

@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head 7d51a8b331 (7d51a8b3314a3db490738d2a2a739561588e6733), not merged onto anything else; its base on main is 2227f13661.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON, Ninja -j4, private worktree.

  • ctest -R '^guest_(math|math_exact|dinkumware_internals)$': passes in each of 3 runs (9 passes).

This covers the runtime run that the header-cleanup push at this head did not include.

…es do

The pow of the libc.prx that titles ship (PPSA07923) multiplies |x| by
2^53 for its subnormal normalization on every general-path call and
keeps the product only for subnormal x. For |x| from 2^971 up the
unused product overflows, so pow raises FE_OVERFLOW there for any
exponent that reaches the general path, even when the result is
finite (pow(1e300, -0.25)). The product is now computed the same way;
it is exact below 2^971, so only that flag changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up to my note above: the cause is found, and pushed as b5dc3b4296 (a fast-forward on 7d51a8b331).

Cause. The titles' pow (PPSA07923, at 0x4d950) raises FE_OVERFLOW for any exponent that reaches the general path once |x| >= 2^971 (DBL_MAX / 2^53), positive or negative, even when the result is finite:

  • pow(1e300, -0.25), pow(1e300, 0.75) and pow(1e300, -1.5) all raise it.
  • pow(0x1p970, y) and pow(1e200, y) never do.
  • The special cases y = ±1 and y = 0.5 don't.

That threshold is fdlibm's subnormal normalization ax *= two53. The titles' build evaluates the product on every general-path call and keeps it only for subnormal x, so for huge x the unused product overflows. Their over- and underflow exits also go through _Feraise (0x11f70), which writes exactly the requested bits plus inexact, so it isn't the source.

Change. The commit computes the product the same way (volatile double scaled = ax * two53;, used only when ix < 0x00100000). It is exact below 2^971, so results don't change.

Tested on Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release:

  • Native comparison: the titles' special-value probe for pow now gives values 0, errno 0 and flags 0 differences of 441 pairs (flags was 9).
  • Regression: guest_math has a new check that pow(1e300, y) raises FE_OVERFLOW and pow(0x1p970, y) doesn't. With the previous Math.cpp, it fails.
  • Regression set: guest_math, guest_math_exact, guest_dinkumware_internals and public_headers pass 3/3. Conventions pass.

AI-assisted: yes (Claude Code).

@JJenkx

JJenkx commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head b5dc3b4296 (b5dc3b4296ad50a177a3abdae28b2084f1279085), not merged onto anything else; its base on main is 2227f13661.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON, Ninja -j4, private worktree.

  • ctest -R '^guest_(math|math_exact|dinkumware_internals)$': passes in each of 3 runs (9 passes).

This head is newer than my previous Linux run on this PR (7d51a8b331).

@JJenkx

JJenkx commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Integrated current main a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8 as 1c4650937d284044ea1f26ea386e21289e8c20e9, preserving the existing public history. Kept main’s newly merged math ports and tests alongside this topic; prerequisite ancestry is recorded in the description.

Linux Release: rebuilt libc and all three math executables; guest_math, guest_math_exact, guest_dinkumware_internals each pass 3/3 (9 passes, zero skips); public_headers, conventions and whitespace pass. The same baseline groups pass on main. Historical Windows/reference results keep their original pins; no new title/GPU or reference measurement is claimed.

Per-head logs, JUnit, hashes, source/dependency pins and patches · SHA-256 22866bd2a060ba69cd4387d471605afe20ed644e3257174b2d1488635f8c9b52 (download verified). AI-assisted: yes (Codex).

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 2, 2026
pow carries over FreeBSD msun's lib/msun/src/e_pow.c at release/11.4.0. Name that source above the port, in the form the exp port uses, followed by the file's Sun copyright and permission notice copied verbatim from that revision. No code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Added the source note and licence notice this port was missing (9ccd3621ea, on top of 1c4650937d): above SetLowWord a line in the exp port's form naming lib/msun/src/e_pow.c at release/11.4.0, followed by that file's Sun copyright and permission notice copied verbatim from that revision, the same correction oneandonlydean asked for on #10321. No code changes. check_conventions.py --base origin/main passes.

AI-assisted: yes.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 3, 2026
@JJenkx

JJenkx commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Current-main integration — 2026-11-03. Head 3bf30fd4920e751df3825b9abb75f7a0832ecf37 includes main 4f41f4c375f5abb487dbd184fbc150f31994d762 and retains the prior public history and attribution/licence notices. Main’s newer math implementations and fixtures remain alongside this topic.

Linux x86-64 Release, GCC 16.2.1, Ninja, BUILD_TESTING=ON: rebuilt actual libc and math executables. guest_math, guest_math_exact, and guest_dinkumware_internals each pass 3/3 (9 passes, zero skips); public_headers and conventions pass. The same three groups pass 3/3 plus headers on pinned main. All 34 recursive dependency trees and 31,551 tracked blobs verify with zero errors; the update=none QuickJS test262 corpus is excluded from these library inputs. Whitespace check passes.

Source/parent/gitlink proofs, exact library/test hashes, raw logs/JUnit, and head-leased push receipts: qualification archive, SHA-256 e6a50522bc28e30871fdc2c12a88d2537515914239e8166f6237f48895126a06 (download verified). Older platform/reference reports retain their original pins; no new Windows/macOS, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 3, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi JJenkx, the source delta looks sound. Please remove the generated attribution footer below the checklist; the template checkbox can stay.

@JJenkx

JJenkx commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing the source change. I'm keeping the footer. It sits outside the template lines, AGENTS.md asks only that every template line be kept and filled, and pull requests with the same footer have been merged here. If the maintainer wants it removed, I will remove it.

AI-assisted: yes.

@JJenkx

JJenkx commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Removed the generated attribution footer below the checklist. The template’s AI-assisted checkbox remains; source and test claims are unchanged.

@oneandonlydean
oneandonlydean merged commit ee42ed3 into boykopovar:main Nov 4, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants