Repository navigation
fix(libc): split modfl as the bundled libc.prx does - #23447
Merged
Merged
Conversation
modfl went to the host's modf, which on Windows returns +0 as the fraction of a negative integral value and raises FE_INEXACT. It now follows FreeBSD msun's s_modfl.c, whose results and flags equal those of the libc.prx bundled with PPSA10122 01.101.000. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011TXsSW8zeAgKgHLCFsYwM3
PrivacyOnion
approved these changes
Nov 19, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against eba24c99dd:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_math_exact_testsbuilt cleanly. - CTest (
guest_math_exact):1/1 Test #1230: guest_math_exact ................. Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/MathExact.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1230: guest_math_exact ................. Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 - Code reading:
- Verified modfl_nid_postfix correctly splits integer and fractional parts across exponent ranges (< 0, in [0, 62], >= 63, and special values like Inf/NaN) matching IEEE 754 / x87 extended precision.
- Verified GuestCopyOut_nid_no_patch is used properly to store the integral part into guest memory.
- Verified sign preservation for negative zeros and exact flag behavior (no spurious FE_INEXACT).
- Checked AGENTS.md rules, technical debt fragment at docs/dev/debt/changes/fix-modfl-ld.md, and test coverage in GuestMathExact.cpp.
Looks Good To Me
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
modflhanded the work to the host'smodf. On Windows that differs from thelibc.prxbundled with PPSA10122 01.101.000 (SDK 5.00,modflat 0x4d200) in two ways:modfl(-3.0L, &i)returned +0 where the module, and C, give -0;FE_INEXACTwas raised for values that are not integral, where the module raises nothing.On 200,000 random inputs 20,555 results differed in their bits and 158,891 more only in the flags.
It is now written out after FreeBSD msun's
s_modfl.c(release/11.4.0, named above the function): below 1 the integral part is a zero with the sign ofxand the fraction isx; from 2^63 up, and for a value without fraction bits, the integral part isxand the fraction a zero with its sign; otherwise the fraction bits are cleared for the integral part and the fraction is the difference, which is exact. A NaN is returned as it is. The integral part is still stored through the checked guest copy.Tested
Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Release, on
maine9ff851.guest_math_exactgetsCheckModflPartsAndFlags: eight values with both parts and no flag raised (-3, 3, 2.5, -0.75, -0, -(2^62 + 0.5), -2^63, negative infinity). Red on the base: withMathExact.cppas onmain,guest_math_exactaborts at the fraction of the first case (GuestMathExact.cpp:145, the -0 ofmodfl(-3)). Green: with the changeguest_math_exact,guest_mathandguest_math_elementarypass. Trial merges with my open libc pull requests (fix(libc): compute expm1l as the bundled libc.prx does #23265, fix(libc): compute powl as the bundled libc.prx does #23367, fix(libc): raise the flags of the unselected value in roundl and fdiml #23401, fix(libc): generate printf's decimal digits as the bundled libc.prx does #23444) are clean.tools/check_conventions.py --base origin/mainandtools/debt_fold.py --checkpass.tools/pr_overlap.py --branch fix/modfl-ld: no overlap with open pull requests.modfreturned was not measured, they now run the same code as Windows.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
https://claude.ai/code/session_011TXsSW8zeAgKgHLCFsYwM3