Skip to content

[VFDLIBM-33] Port acos from fdlibm - #119

Merged
MaxGekk merged 2 commits into
mainfrom
acos-port
Nov 21, 2026
Merged

MaxGekk merged 2 commits into
mainfrom
acos-port

Conversation

@MaxGekk

@MaxGekk MaxGekk commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Part of #33. Ports acos from fdlibm 5.3's e_acos.c: VFdlibm.acos(x) and acos(x, live), the
sibling of asin.

The three ranges below 1 (|x| < 0.5, x <= -0.5, x >= 0.5) share one pass: z is x*x,
(1+x)*0.5 or (1-x)*0.5 by the C's compares, and the polynomials and r = p/q run on z in
every lane. The root is VectorOperators.SQRT; the x >= 0.5 form divides a second time for
c; the step __LO(df) = 0 is the C's own AND of the bits with 0xFFFFFFFF00000000, not
arithmetic. ix <= 0x3c600000 returns the constant pio2_hi+pio2_lo. Lanes of magnitude 1 or
more and NaNs (exactly 1, exactly -1, (x-x)/(x-x)) are finished per lane by
StrictMath.acos. There is one arm, so there is no default to choose.

PROOFS.md gets an acos section: no lemma of its own, which hypotheses H1 to H4 of L13 the
blends meet, and what it does not cover. It also records, as one uncommitted scalar sample,
that the constant return's compare is not told from a neighbouring word by any test of the port,
so acos.tinyMoved moves it far enough to show. Four planted faults, each sized on 2^22 draws before it was wired (pio2_lo dropped, the
0.5 word moved to 0.75's, the low-word clear skipped, the constant return's word moved to
2^-50's; counts in SKILLS.md). Hard cases: the 1569 inputs of the tag acs, from
dev/testlibm-extract.py (the count is pinned in HarnessSelfTest); all are positive, so their
negations reach the x <= -0.5 form. Fuzz has edges at 2^-57, 0.5 and 1.

Not in the nightly yet. acos is in Nightly's function table (so dev/nightly.sh runs it by
hand and the planted-fault tests fuzz it) but not in the night's all= list in nightly.yml, as
asin is: the list changes after the span is read.

Why are the changes needed?

acos is the next function in Varka's order (#33).

Does this PR introduce any user-facing change?

Yes: a new public method, VFdlibm.acos, in both forms. Every lane equals StrictMath.acos by
Double.doubleToRawLongBits. A CHANGELOG.md line is under Unreleased.

How was this patch tested?

mvn -B verify passes locally (every test and the four acos fault runs), and
dev/jar-check.sh passes with acos in its consumer. AcosTest compares every lane with
StrictMath at 128, 256, 512 bits, the preferred species and SPECIES_MAX, masked and unmasked.
bench/alloc-check.py passed on AcosBenchmark's finish256, finishPreferred and finishMax
rows, common and mixed data, at the host's flags and as an AVX2 host (-XX:UseAVX=2 -XX:MaxVectorSize=32); those readings are not committed, and no speed is claimed.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Sonnet 5.5)

Max Gekk added 2 commits November 21, 2026 20:52
VFdlibm.acos, in the two forms acos(x) and acos(x, live), from e_acos.c.
The three ranges below 1 share one pass: z is x*x, (1+x)*0.5 or (1-x)*0.5
by the C's compares, the polynomials and r = p/q run on it in every lane,
the root is VectorOperators.SQRT, the x >= 0.5 form divides a second time,
and the C's own AND clears the root's low word. Lanes of magnitude 1 or
more and NaNs are finished per lane by StrictMath.acos. One arm.

PROOFS.md gets an acos section that says which of L13's hypotheses its
blends meet and what it does not cover. The tests are AcosTest (every
width, masked and unmasked, the 1569 published cases and their negations,
every subset of lanes rare), four planted faults sized on 2^22 draws,
AcosBenchmark for the allocation check, Fuzz's edges for acos and its entry
in Nightly's table, which the night's list does not name yet.

Generated-by: Claude Code (Sonnet 5.5)
Keeps both sides: atan (#108) and the fuzz word gaps (#118) from main, acos
from this branch, in the lists and tables both extend. The PROOFS.md
sentence on the constant return's compare now says only what the one
scalar sample shows.

Generated-by: Claude Code (Sonnet 5.5)
@MaxGekk
MaxGekk merged commit d0e4a58 into main Nov 21, 2026
14 checks passed
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