Skip to content

arcsin and arccos of a real number past 1 have their value - #2245

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
an-arcsine-past-one-has-a-value
Oct 30, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
an-arcsine-past-one-has-a-value

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2244.

For about one real argument past 1 in ten, arcsin and arccos evaluated to NaN: arcsin(6 + pi), arccos(6 + pi) and arcsin(1 + sqrt(3)) among them. 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]. That restores a bound the rounding broke, and changes no value it did not.

2.6.0 and master now
"arcsin(6 + pi)".ToEntity().Evaled NaN 1.5707963267948966 - 2.902976737696685i
"arccos(6 + pi)".ToEntity().Evaled NaN 2.902976737696685i

Tests: ArcsineOfARealPastOneTest takes arcsin and arccos at plus and minus (k + c) for those 200 arguments. It compares them with the library's convention, measured at 9.14 and -9.14: sign(x) pi/2 - i arccosh|x|, and 0 or pi plus i 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 compiled arcsin(arcsin(x + pi)) at 6 had a value, and evaluation had none.

🤖 Generated with Claude Code

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>
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.71%. Comparing base (bd750c4) to head (448d773).

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.26% <100.00%> (-0.01%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...uriMath/Core/Entity/Continuous/Number/Operators.cs 90.75% <100.00%> (+0.10%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…-has-a-value

# Conflicts:
#	Sources/.editorconfig
@Rafael-SOWNet
Rafael-SOWNet merged commit b035ed1 into master Oct 30, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 30, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the an-arcsine-past-one-has-a-value branch October 30, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

arcsin and arccos of a real past 1 is NaN for one argument in ten: arcsin(6 + pi)

1 participant