Repository navigation
arcsin and arccos of a real number past 1 have their value - #2245
Merged
Merged
Conversation
For about one real argument past 1 in ten, arcsin and arccos evaluated to NaN: arcsin(6 + pi), arccos(6 + pi), arcsin(1 + sqrt(3)). Of arcsin(k + c) for k from 1 to 40 and c in pi, e, sqrt(2), sqrt(3) and ln(3), 20 of the 200 were NaN, on 2.6.0 as on master. The value exists: sign(x) pi/2 - i arccosh|x|. Number.Arcsin and Number.Arccos share ArcSinCosInner. For w = x + iy it takes beta = (|w + 1| - |w - 1|) / 2, then arcsin(beta) or arccos(beta). By the triangle inequality, beta is in [-1, 1], and for a real x past 1 it is exactly 1. The two square roots are rounded, though, and for some x the difference comes out a little past 1, where the decimal arcsine is NaN. beta is now clamped to [-1, 1], which restores a bound the rounding broke and changes no value it did not. ArcsineOfARealPastOneTest takes arcsin and arccos at plus and minus (k + c) for those 200 arguments. It compares them with sign(x) pi/2 - i arccosh|x| and with 0 or pi plus i arccosh|x|, the library's convention, measured at 9.14 and -9.14. All five constants' cases fail on master. Found by work/compilesweep: the compiled arcsin(arcsin(x + pi)) at 6 had a value, and evaluation had none. Fixes #2244. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2245 +/- ##
==========================================
- Coverage 86.71% 86.71% -0.01%
==========================================
Files 310 310
Lines 67785 67790 +5
Branches 19664 19666 +2
==========================================
+ Hits 58781 58783 +2
- Misses 4892 4894 +2
- Partials 4112 4113 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…-has-a-value # Conflicts: # Sources/.editorconfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2244.
For about one real argument past 1 in ten,
arcsinandarccosevaluated toNaN:arcsin(6 + pi),arccos(6 + pi)andarcsin(1 + sqrt(3))among them. Ofarcsin(k + c)forkfrom 1 to 40 andcinpi,e,sqrt(2),sqrt(3)andln(3), 20 of the 200 wereNaN, on 2.6.0 as on master. The value exists:sign(x) pi/2 - i arccosh|x|.Number.ArcsinandNumber.ArccosshareArcSinCosInner. Forw = x + iyit takesbeta = (|w + 1| - |w - 1|) / 2, thenarcsin(beta)orarccos(beta). By the triangle inequality,betais in[-1, 1], and for a realxpast 1 it is exactly 1. The two square roots are rounded, though, and for somexthe difference comes out a little past 1, where the decimal arcsine isNaN.betais now clamped to[-1, 1]. That restores a bound the rounding broke, and changes no value it did not."arcsin(6 + pi)".ToEntity().EvaledNaN1.5707963267948966 - 2.902976737696685i"arccos(6 + pi)".ToEntity().EvaledNaN2.902976737696685iTests:
ArcsineOfARealPastOneTesttakesarcsinandarccosat plus and minus(k + c)for those 200 arguments. It compares them with the library's convention, measured at9.14and-9.14:sign(x) pi/2 - i arccosh|x|, and0orpiplusi arccosh|x|. All five constants' cases fail on master. Full suite 18161/0, interactive trio, AOT smoke 73/0, all frameworks build.Found by
work/compilesweep: the compiledarcsin(arcsin(x + pi))at 6 had a value, and evaluation had none.🤖 Generated with Claude Code