fix(libc): retain finite scaled hyperbolic results #2050

Closed
STUPIDCONTEM wants to merge 1 commit from upstream-pr/2050 into main
STUPIDCONTEM commented 2026-10-09 05:59:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by STUPIDCONTEM on 2026-10-09T05:59:00Z.


Evidence review (2026-10-09)

Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness.

Game/title ID: none verified. No PS5 title execution is claimed.

What

_FSinh and _FCosh evaluated the unscaled float hyperbolic function before multiplication, so representable scaled results overflowed. For example, _FSinh(100.0f, 0x1p-40f) returned infinity instead of a finite result near 1.22e31.

Evaluate finite intermediates in double and narrow only after scaling. Handle zero, NaN and infinite arguments explicitly according to the scaled CRT routines, including signed-zero behavior, and report ERANGE for actual final float overflow. Tiny products that round to zero preserve errno.

Semantics are sourced from Microsoft's primary CRT implementations xsinh.cpp, _FSinh and xcosh.cpp, _FCosh, whose stated scale domain is |y| <= 1. No implementation code or polynomial tables were copied. PS5 hardware behavior has not been measured.

Tested

Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Independent branch from f145139676a48306681d3a4d5fabf83938759daf. Open #1844 adds ordinary libm test coverage without changing these implementations; this regression has a separate test file and target.

  • New guest_scaled_hyperbolic built and run against unchanged upstream: failed finite scaled-result, errno, and special-value assertions.
  • Six finite reference cases (x=0.25, 1, 90, 100, 150, 192), all argument/scale signs, including subnormal scales. Fixed expected float values independently verified with 100-digit decimal arithmetic.
  • Signed zero, tiny products, NaN/infinite arguments, zero scale with huge finite arguments, and actual overflow at x=100/y=1 and x=193/minimum-subnormal scale.
  • Parent independently reviewed the implementation, corrected tiny-product errno behavior, and ran the new regression in the full project runtime.
  • Full default and explicit libs builds passed.
  • Full CTest suite: 489/489 passed, 26.87 s.
  • Committed-head conventions, whitespace and test-registration checks passed.

Linux and PS5 hardware/titles were not run. Tests use the default floating-point rounding mode; alternate rounding modes were not validated.

Checklist

  • Based on current main; no other open PR implements the same change (historical base; current readiness not asserted)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes — OpenAI Codex agents assisted with implementation; the parent agent independently reviewed and tested the final change.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796615648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2050). Originally posted by [STUPIDCONTEM](https://github.com/STUPIDCONTEM) on 2026-10-09T05:59:00Z. --- ### Evidence review (2026-10-09) Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness. Game/title ID: **none verified**. No PS5 title execution is claimed. ### What `_FSinh` and `_FCosh` evaluated the unscaled float hyperbolic function before multiplication, so representable scaled results overflowed. For example, `_FSinh(100.0f, 0x1p-40f)` returned infinity instead of a finite result near `1.22e31`. Evaluate finite intermediates in double and narrow only after scaling. Handle zero, NaN and infinite arguments explicitly according to the scaled CRT routines, including signed-zero behavior, and report ERANGE for actual final float overflow. Tiny products that round to zero preserve errno. Semantics are sourced from Microsoft's primary CRT implementations [xsinh.cpp, _FSinh](https://github.com/microsoft/STL/blob/main/stl/src/xsinh.cpp) and [xcosh.cpp, _FCosh](https://github.com/microsoft/STL/blob/main/stl/src/xcosh.cpp), whose stated scale domain is `|y| <= 1`. No implementation code or polynomial tables were copied. PS5 hardware behavior has not been measured. ### Tested Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Independent branch from `f145139676a48306681d3a4d5fabf83938759daf`. Open #1844 adds ordinary libm test coverage without changing these implementations; this regression has a separate test file and target. - New `guest_scaled_hyperbolic` built and run against unchanged upstream: failed finite scaled-result, errno, and special-value assertions. - Six finite reference cases (x=0.25, 1, 90, 100, 150, 192), all argument/scale signs, including subnormal scales. Fixed expected float values independently verified with 100-digit decimal arithmetic. - Signed zero, tiny products, NaN/infinite arguments, zero scale with huge finite arguments, and actual overflow at x=100/y=1 and x=193/minimum-subnormal scale. - Parent independently reviewed the implementation, corrected tiny-product errno behavior, and ran the new regression in the full project runtime. - Full default and explicit `libs` builds passed. - Full CTest suite: **489/489 passed**, 26.87 s. - Committed-head conventions, whitespace and test-registration checks passed. Linux and PS5 hardware/titles were not run. Tests use the default floating-point rounding mode; alternate rounding modes were not validated. ### Checklist - [ ] Based on current `main`; no other open PR implements the same change (historical base; current readiness not asserted) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes — OpenAI Codex agents assisted with implementation; the parent agent independently reviewed and tested the final change.
MarcZX10 commented 2026-10-09 06:04:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T06:04:40Z.

Review: APPROVED


Reviewed the full diff and the referenced Microsoft CRT behavior. The implementation keeps the scale-before-narrowing behavior, handles the documented special cases, and adds direct regression coverage for finite results, signed zero, errno, and overflow. I built the exact head on Linux with GCC 12; guest_scaled_hyperbolic passed (1/1). Conventions and diff checks pass. Upstream Build, Conventions, and Progress workflows are still action_required, so they have not run on this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5466309218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2050#pullrequestreview-5466309218). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T06:04:40Z. **Review:** APPROVED --- Reviewed the full diff and the referenced Microsoft CRT behavior. The implementation keeps the scale-before-narrowing behavior, handles the documented special cases, and adds direct regression coverage for finite results, signed zero, errno, and overflow. I built the exact head on Linux with GCC 12; guest_scaled_hyperbolic passed (1/1). Conventions and diff checks pass. Upstream Build, Conventions, and Progress workflows are still action_required, so they have not run on this PR.

Pull request closed

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!2050
No description provided.