feat(libc): implement the C99 math functions Minecraft Legends imports #1405
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1405"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-08T02:31:56Z.
What
Minecraft Legends (PPSA05510) imports 13 C99 math functions that
libcdoes not export:acosh,asinh,atanh,cosh,sinh,expm1,log1p,ceil,floor,trunc,fabs,sqrtandnan. Their NIDs are in the PPSA05510 import list attached to #268, andtools/nid_names.pyresolves them to these names. A title that imports any of them fails at startup with an unresolved import.libc/src/Math.cppnow exports exactly these 13, each forwarding to the host<cmath>like the existing exports next to them.nanthrows on a null tag. Guesterrnois not set, since FreeBSD's libm reports errors only through the floating-point exceptions.Per review, the float forms and the other C99 functions from the first version (
erf,tgamma,fma,nextafter,rint,lrintand the rest) are dropped until a title is known to import them.Related: #1196 adds
hypot/hypotf, which PPSA05510 also imports. The two PRs are complementary, but both add tocore/libs/tests/GuestMath.cpp, so whichever lands second needs a rebase.Log
I don't own Minecraft Legends, so I can't paste the line where PPSA05510 stops on
main. The evidence is the relinker import list in #268, where these 13 NIDs are among the unresolvedlibSceLibcInternalimports. If someone with the title can post theFAIL: unresolved ELF import ...line frommain, I'll add it here.Tested
aarch64 Debian 13 host. The full project cannot be built here because it needs x86-64.
CheckC99Mathincore/libs/tests/GuestMath.cpp, linked againstMath.cpp, passes natively against glibc. It checks exact results and edge cases: signed zeros,ceilnear 2^52,floorjust below 2, domain and pole results, and the quiet-NaN bits ofnan(""). Transcendental results are compared with known values to 1e-15.Math.cppandGuestMath.cppcompile for x86_64-linux-gnu and x86_64-windows-gnu with-Wall -Wextra(Zig 0.17 clang). The only warning is the existing-Wreturn-type-c-linkagefromGeneral.hpp.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T03:28:36Z.
Review: COMMENTED
Built it, ran it, and verified the NID mapping with your own tool rather than taking the body's word for it.
Linux (CachyOS, GCC, Release):
The functions were genuinely missing, which I checked against the base rather than assuming: on
pr-1405^the file has0implementations ofsinh,asinh,tgammaandlog1p, and after this PR it has them (sinh0 → 2,erf1 → 3for the float form). So this fills a real gap rather than re-exporting something the library already had.The NID mapping round-trips through the project's own hash. I computed the NID for each name with
nid_names.py'scompute_nid, then asked the oracle to name them back:Consistent in both directions for every function in the diff, so the names are the real symbol names for those NIDs and not a plausible-looking guess. Worth stating because it is the one part of a libc export that cannot be verified by a passing test.
Not a duplicate of #1196, and the tool shows why. Asking the same oracle about the two functions #1196 covers:
They are still
rename-ready— unresolved names with no implementation — while everything this PR touches reportsalready-implemented. I expected to find overlap when I sawhypotfmentioned in the body, and the status column shows there is none: #1196 is complementary, and both should land. Since you cite #1196's ground in the body, a pointer to it would save the next reader that check.One practical note for whoever merges second: this PR and #1196 both add to
core/libs/tests/GuestMath.cpp, so expect a conflict between them. Whoever lands first, the other will need a rebase — worth saying in both bodies so it is not a surprise.The forwarding itself is the house pattern used next to it —
std::sinhfor afloatargument selects the float overload, sosinhfreturns a float rather than a narrowed double, which is the thing that would be easy to get wrong here.This is a comment, not an approval — I have no merge rights here.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T05:12:56Z.
Please keep the functions PPSA05510 imports (
acosh,asinh,atanh,cosh,sinh,expm1,log1p,ceil,floor,trunc,fabs,sqrt,nan) and drop the rest until a title reaches them, and add the log line where PPSA05510 stops on main.erf,tgamma,fma,nextafter,rint,lrintand the others have no title named here.Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-08T15:42:48Z.
@oneandonlydean Done: the PR now exports only the 13 functions PPSA05510 imports, double forms only, and the rest are dropped. I don't own Minecraft Legends, so I can't post the line where it stops on main myself. The body points to the PPSA05510 import list in #268 for now, and I'll add the log line if someone with the title can share it.
@Dextroid17 Thanks for checking the NIDs both ways. The body now mentions #1196 and the GuestMath.cpp conflict.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T15:43:56Z.
Progress report (
4b005b2→7278eea)📈 System libraries: 84.82% (+0.06%, +13 implemented functions)
✅ 13 implemented
acosh_nid_postfixasinh_nid_postfixatanh_nid_postfixceil_nid_postfixcosh_nid_postfixexpm1_nid_postfixfabs_nid_postfixfloor_nid_postfixlog1p_nid_postfixnan_nid_postfixsinh_nid_postfixsqrt_nid_postfixtrunc_nid_postfixImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T16:45:18Z.
Checked the trimmed head (
7278eea) against @oneandonlydean's list:Math.cppdeclares exactly the 13 double forms and nothing else —sinh cosh asinh acosh atanh expm1 log1p sqrt fabs ceil floor truncandnan, each adouble …_nid_postfix— so the export half now matches what was asked.The half still missing for the bar is the log line from a title, and I cannot supply it either: I don't have Minecraft Legends (PPSA05510) here. Naming #268's import list in the body is the honest interim state.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:29:12Z.
Closing: the #268 import list shows that PPSA05510 imports these, not that it stops at them on main. Reopen when one is a title's next stop on main, with the log line.
Pull request closed