Skip to content

[VFDLIBM-33] Port atan2 from fdlibm - #121

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

MaxGekk merged 2 commits into
mainfrom
atan2-port

Conversation

@MaxGekk

@MaxGekk MaxGekk commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Purpose

Part of #33. Ports atan2 from fdlibm 5.3's e_atan2.c, the first function of two arguments, on the pair harness (PairFunction, OPERANDS for a lane of two NaNs, pair-passes, --argument, wordGaps). Not added to the nightly's all=: a later PR does that after a night has been read.

What changed

  • Atan2 and VFdlibm.atan2(y, x) / atan2(y, x, live) (a lane that is not live keeps y). The special lanes (NaN, zeros, infinities, the diagonals) are blends over the general path, from the C's last test to its first. The general path is Atan.atan on t = |y/x| where t < 2^66, then the quadrant by sign; the shortcuts k > 60 and hx < 0 && k < -60 and the x = 1.0 early return follow the C. No lane is finished by a call to StrictMath. Two arms (blended, and guarded, which VFdlibm calls provisionally; no timing of atan2 exists, so none is compared).
  • PROOFS.md: what atan's core contract is (read before calling it), L14 (x = 1.0 through the general path is atan(y)) with its hinge test, and the observation that moving either shortcut of k by one changes no bit (so the planted faults move them by ten).
  • Eight planted faults with CATCHERS and pom.xml executions, sized on 2^22 draws (SKILLS.md); hard-cases/atan2.txt read through Inputs.hardCasePairs; Nightly.PairFunction.ATAN2 (two arms, OPERANDS, wordGaps at the k thresholds); the dev/jar-check.sh consumer calls atan2 with the candidates rule; Atan2Benchmark (blended and guarded, *256, *Preferred, *Max, common and mixed, refusing another value); Fuzz.PairEdges.wordGaps() returns a copy, with a test; CHANGELOG, README, PLAN, SKILLS.

How it was tested

Atan2Test (50 cases at every width and SPECIES_MAX, masked and not, three arms, special pairs, k thresholds, x = 1.0, subnormal x, sampled, dense, the 20,820 hard-case pairs, every subset of lanes special) and the eight fault executions pass; the whole mvn test passes locally. bench/alloc-check.py passes on the Atan2Benchmark rows at this host's flags and as an AVX2 host; CI runs it. Sweep of both arguments over 2^24 high words and Fuzz of 4 million draws matched StrictMath.

Compatibility

Adds VFdlibm.atan2. Its lanes equal StrictMath.atan2's by raw bits except a lane where both arguments are NaN with different bits, which is one of the two, quieted (the decision on #33; the CLAUDE.md and CHANGELOG header wording stays the owner's, drafted on #115).

AI tooling

Generated-by: Claude Code (Fable 5.2)

Max Gekk added 2 commits November 21, 2026 21:39
Generated-by: Claude Code (Fable 5.2)
# Conflicts:
#	CHANGELOG.md
#	PLAN.md
#	PROOFS.md
#	README.md
#	SKILLS.md
#	dev/jar-check.sh
#	src/main/java/io/github/vecbricks/vfdlibm/VFdlibm.java
@MaxGekk
MaxGekk merged commit c4abba5 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