Skip to content

gh-154146: Fix accuracy of the math.acospi() fallback near 1#154148

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:acospi-fallback
Jul 20, 2026
Merged

gh-154146: Fix accuracy of the math.acospi() fallback near 1#154148
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:acospi-fallback

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 19, 2026

Copy link
Copy Markdown
Member

The fallback computed acos(x)/pi, and some libms (old fdlibm derivatives on NetBSD, OpenBSD and DragonFly) lose precision in acos(x) near x = 1. Compute it as 2*asin(sqrt((1 - x)/2))/pi for x >= 0.5, where 1 - x is exact and asin() is accurate.

Tested on NetBSD 10.1, OpenBSD 7.9 and DragonFly 6.4 (the failing mtest cases pass now) and FreeBSD 15.1 (no regression).

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread Modules/mathmodule.c
@serhiy-storchaka
serhiy-storchaka merged commit 69f0801 into python:main Jul 20, 2026
56 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the acospi-fallback branch July 20, 2026 05:56
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.

2 participants