Repository navigation
Fix cosine range reduction for large rotation angles - #1948
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1948 +/- ##
=======================================
Coverage 92.33% 92.33%
=======================================
Files 45 45
Lines 9923 9931 +8
=======================================
+ Hits 9162 9170 +8
Misses 761 761 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
All 44 checks for Validation: CI matrix, TSAN, and formatting. The regression cases cover large positive and negative angles while retaining the existing quadrant-boundary controls. This is ready for maintainer review. Please let me know if any additional range-reduction cases would help. |
zmerlynn
left a comment
There was a problem hiding this comment.
I checked this locally against a long double reference and it looks right to me. The old x + 90.0 rounds whenever the sum crosses a power of two, so the error isn't limited to huge angles. Near 4194304 degrees, sin^2 + cos^2 was off by 6.6e-12, and below 3600 degrees the max error was 3.75e-15. With this change the max error is 1.88e-16 everywhere I tried. Multiples of 90 and 45 still come out exact.
One small thing: I think the isfinite check is redundant, since fmod of an infinity is NaN and sind already returns NaN for that. It's harmless though.
elalish
left a comment
There was a problem hiding this comment.
I have no idea when this would be a practical problem, but sure, thanks.
Problem
cosd(x)calculatessind(x + 90). At large finite angles, adding 90 loses precision before range reduction, so sine and cosine no longer form an orthonormal rotation. A rotation can therefore change a solid's volume or a cross section's area.Change
Reduce the absolute angle modulo 360 before applying the cosine-to-sine phase shift. Preserve exact quadrant boundaries and return NaN for nonfinite input.
Validation
git diff --checkpass.