BUG: ellipeinc, ellipkinc: fix the AGM phase near odd multiples of `pi/2` #648
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 165 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.306
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #648"
general
weight: 0.35
jorenham
Reference issue
scipy/scipy#19498 (from the wish list in #629)
What does this implement/fix?
For example,
ellipeinc(0.5549990348297819, 0.12706025328636256)returned0.6465545336219746instead of0.551576816785566, andellipkincreturned0.6599968962116932instead of0.5584589121791251.In the Landen/AGM loop of
ellieandellik, the rational update oftcomputedmod(the multiple ofpiin the phase) from the phase alone, apart fromt. When the phase lands on an odd multiple ofpi/2,tis huge and the two can end up on opposite sides of the pole, so the phase is off bypi. Nowmodisround((phi - atan(t)) / pi)after both branches, so it always matchest.Additional information
The new test fails on
mainwith GCC and Clang (relative error 0.18) and passes with the fix; theellipkincandellipeincxsref table tests pass. Over 1.4M pairs of adjacent doubles next to such points, the number of jumps above1e-8went from about 46k per function to 0, and 500k random points give bitwise identical results.AI Generation Disclosure
Claude Opus 5.5 (Claude Code) wrote the fix, the test, and this description, following the plan in this comment. GPT-6.2 Sol (Codex CLI) reviewed it.