Repository navigation
fix(libc): return infinity from exp and cosh on overflow in every rounding mode - #28177
Conversation
…nding mode Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 811ab75440:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_math_testsbuilt cleanly. - CTest (
guest_math):1/1 Test #1329: guest_math ....................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1329: guest_math .......................Subprocess aborted***Exception: 0.12 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified core/libs/prx/libc/src/Math.cpp:1717-1723 (exp_nid_postfix) sets errno = ERANGE, evaluates volatile huge * huge to raise FE_OVERFLOW and FE_INEXACT across all rounding modes, and returns +infinity
- Verified core/libs/prx/libc/src/Math.cpp:3765-3773 (cosh_nid_postfix) evaluates volatile huge * huge to raise FE_OVERFLOW and FE_INEXACT, sets result to +infinity, and correctly sets errno = ERANGE via std::isinf(result) across all rounding modes
- Verified core/libs/tests/GuestMath.cpp:832-857 restores floating-point environment via RestoreFloatingPointState, iterates over all four rounding modes (FE_TONEAREST, FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO), and validates errno, return values (+inf), and exception flags
- Checked AGENTS.md rules: no prohibited comments added, conventions gate passed, no extra untracked files added, Conventional Commit title used
- Checked LP64 vs LLP64 portability and verified types (double, volatile double, std::size_t) are portable across Linux and Windows
Looks Good To Me
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
|
Linux check of the exact head
AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the inspected overflow paths return positive infinity and preserve overflow flags across rounding modes.
What I ran
Reviewed head 811ab75440cc6f06c07a0b24cae245e491b13762. I read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and the full text of both changed files, core/libs/prx/libc/src/Math.cpp and core/libs/tests/GuestMath.cpp. I used targeted repository searches for the changed functions and their supporting declarations. No commands or tests were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Changed source and test review | passed | Both changed files read |
| Runtime tests | not run | Author reports Windows 11 / MinGW GCC 16.2 results |
| Bundled module behavior | not run | Author reports no local libc.prx |
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the reported test suites or verify behavior against the bundled libc.prx. review/files.json was not available as a review artifact; review/manifest.json identifies both changed files and indicates their full text was included and read.
To get this to a good state
Nothing is required.
kripotker
left a comment
There was a problem hiding this comment.
Review: fix(libc): return infinity from exp and cosh on overflow in every rounding mode
Approve.
What I checked
- Overflow branches. Both now evaluate
huge * hugeinto avolatile, which still raisesFE_OVERFLOWandFE_INEXACT, and return+infindependent of the rounding mode. This matches the #23411 reading the description cites and theexp2change in #24160. errnoincosh. It now getsERANGEin the directed modes too, becausestd::isinf(result)is true.- Unchanged paths.
cosh's0.5 * w * wpath below the overflow threshold is untouched, andcosh(710.4)is pinned as before.- The underflow branch of
expis unchanged.
- Sabotage check: two small branch changes plus a test.
What I ran
Windows 11, MSYS2 UCRT64 GCC 16.2.0, Release/Ninja, with PR head 811ab75's Math.cpp and GuestMath.cpp in a built tree:
| Files | ctest -R '^guest_math$' |
|---|---|
PR's Math.cpp and GuestMath.cpp |
passes |
main's Math.cpp with the PR's test |
fails at GuestMath.cpp:846, the new check |
check_conventions.py: All conventions checks passed.
I don't have the bundled libc.prx, so the console behaviour is taken from #23411.
AI-assisted: yes (Claude Code).
ligmaSec
left a comment
There was a problem hiding this comment.
Built and ran guest_math on Linux with the change applied. The fixture passed the exp and cosh overflow checks in all four rounding modes, including ERANGE, positive infinity, and the overflow and inexact flags. The large finite cosh and exp underflow cases also passed.
AI-assisted: yes.
Plyxen
left a comment
There was a problem hiding this comment.
I read the diff at 811ab75440. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at b97867d3ce6 together with other open PRs (so not an isolated build).
guest_math: pass on both.- Control (same tree and tests, the changed files of those PRs put back to
main's): fails on both atGuestMath.cpp:914.
Not checked: a title.
AI-assisted: yes (Claude Code)
|
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.
|
Part of #23411.
What
expandcoshreturned the largest finite double on overflow when rounding down or toward zero, because their overflow branches returned the run-time producthuge * huge.coshthen also lefterrnoalone, because it setsERANGEonly for an infinite result.Both now evaluate the product for its flags and return +inf, as #24160 did for
exp2. This is the reading in the rounding-mode section of #23411: on overflow thelibc.prxbundled with PPSA10122 returns +inf withERANGE,FE_OVERFLOWandFE_INEXACTin all four modes. The underflow branches are unchanged, since that reading has them follow the rounding mode.expfandcoshfare not touched; open #10113, #21714 and #11109 hold them.The only callers that can pass
expan overflowing argument are outsideMath.cpp:sinh,coshand theerftail stay below the threshold. Open #28071 adds callers ofexpandcoshfor the complex functions; in the two directed modes those would now see +inf where they sawDBL_MAX.In the thread, the overflow rows were asked for on 19 November and
exp2followed as #24160. I found no PR or branch forexporcoshsince, so I took these two; say so if that work is still in progress and I will close this.tools/pr_overlap.pycould not compare #6295 and #21714, which conflict withmain. I read both diffs: #6295 adds thenextafterfamily and #21714 changesexpfandtgammaf; neither changesexporcosh.Tested
Windows 11, MinGW-w64 GCC 16.2, Release.
guest_math,guest_math_exact,guest_math_elementary,guest_complex_trigandguest_complex_trig_longpass. The newCheckExpCoshOverflowRoundingchecksexp(709.9),cosh(711)andcosh(-711)in the four rounding modes, and pinsexp(-745.2)andcosh(710.4)as they were. Without theMath.cppchangeguest_mathaborts in that check.I do not have the bundled
libc.prx, so the module's behaviour is taken from #23411 and was not run here.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
Summary by CodeRabbit
expandcoshbehavior when results overflow, ensuring they return positive infinity consistently.expandcoshinputs.