Skip to content

fix(libc): choose the acosf NaN bits instead of the host libm - #5256

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
adriadam10:fix/libc-acosf-nan-bits
Oct 13, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
adriadam10:fix/libc-acosf-nan-bits

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

guest_math has failed on every main push build since #3688: CheckAcosfErrno pins acosf(2.0f) to 0xffc00000, and acosf handed the NaN to the host std::acos. Our glibc 2.44 returns 0xffc00000, but the runner's glibc 2.39 doesn't.

This change picks the bits explicitly, following FreeBSD msun e_acosf.c, which returns (x-x)/(x-x) for |x| > 1 and for NaN inputs:

  • When |x| > 1 (including ±inf), it returns the x86 default NaN 0xffc00000.
  • A NaN input comes back as that NaN with its quiet bit set.

In-domain inputs still go to std::acos, and errno stays untouched.

Tested

The change is a 6-line rewrite of the NaN path only. Merged without waiting for CI to unblock main; the next push build on main is the check.

  • Ran the full test suite locally: no

FreeBSD msun e_acosf.c returns (x-x)/(x-x) for |x| > 1 and NaN inputs: the
x86 default NaN 0xffc00000, or the quieted input NaN. std::acos left it to the
host libm, and guest_math failed on the runner's glibc 2.39.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant