Skip to content

fix(libc): return the x86 default NaN from acosf for |x| > 1 - #5154

Closed
coltken95 wants to merge 1 commit into
boykopovar:mainfrom
coltken95:fix/libc-acosf-nan
Closed

coltken95 wants to merge 1 commit into
boykopovar:mainfrom
coltken95:fix/libc-acosf-nan

Conversation

@coltken95

Copy link
Copy Markdown

What

guest_math fails on Linux at current main (0f2683c): CheckAcosfErrno from #3688 pins acosf(±2.0f) to 0xffc00000, FreeBSD's (x-x)/(x-x) on x86, but acosf passed out-of-range arguments to the host, and glibc 2.39 (ubuntu-latest) returns 0x7fc00000. acosf now raises FE_INVALID and returns the negative quiet NaN for |x| > 1, as asin does.

Tested

Linux x86-64 (Ubuntu 24.04, glibc 2.39, GCC 13, Release):

  • guest_math aborts with main's Math.cpp and passes with this change; the test now also covers ±infinity and FE_INVALID.
  • All other guest_* tests match main.
    Windows not tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (Linux CI guest_math on main)
  • AI-assisted: yes

acosf passed out-of-range arguments to the host. glibc 2.39 returns
0x7fc00000 for them, where FreeBSD's e_acosf.c computes (x-x)/(x-x),
which is 0xffc00000 on x86, so guest_math fails on Linux at the check
that pins those bits. acosf now raises FE_INVALID and returns the
negative quiet NaN itself, as asin already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VZWLdTjf1S57iLgn2rcaFb
@LeandroLP23

Copy link
Copy Markdown
Contributor

Windows check, since the description covers Linux only: Windows 11 (26300), WinLibs GCC 15.2.0 (UCRT), Release. Head c8872b450 merged onto main 0f2683cb7 with a clean merge.

  • ctest -R '^guest_math$': 1/1 passed. That includes the new ±infinity and FE_INVALID checks.
  • ctest -R '^guest_' -j 4: 379/379 passed.

On unmodified main, guest_math already passes here, because UCRT's acos returns 0xffc00000 for |x| > 1. So the red main is Linux-only, and with this PR both hosts agree.

@coltken95

Copy link
Copy Markdown
Author

Superseded by #5256, which merged the same fix (FreeBSD's 0xffc00000 for |x| > 1, plus the quieted input NaN) into main. Closing.

AI-assisted: yes (Claude Code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants