Skip to content

A compiled power over double of a value that does not exist has none - #2252

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
a-power-of-nan-over-double-has-no-value
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
a-power-of-nan-over-double-has-no-value

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Compile<double, ...> and Compile<float, ...> took a power with Math.Pow, for which NaN^0 and 1^NaN are 1. So a power of a value that does not exist had one. A power whose base or exponent is NaN is now NaN, as it is in evaluation, in FastExpression and in the compilers over Complex (#2225).

at 0.7, over double 2.6.0 and master this branch, and evaluation
(x provided x > 1)^0 1 NaN
1^(x provided x > 1) 1 NaN
((x provided x > 1)^Im(x)) * sin(-2) -0.909 NaN

Over double, a NaN also stands for a value that is not real. So (sqrt(x - 2))^0 at 0.7, which is 1, was 1 only by Math.Pow's rule and is now NaN, as sqrt(x - 2) + 1 - sqrt(x - 2) already was there. The change trades a coincidental answer for a decline, and removes a value where there is none.

Not changed here: 0^0 and 0^(-1) over double stay Math.Pow's 1 and +oo, just as 1/0 over double is still +oo. FastExpression and Complex have no value at either (#2225, #2235). Whether the double compiler should follow is a separate decision.

PowerOfNaNOverDoubleTest: six cases with no value fail on master, and four cases with a value pass on both. Suite 18177 passed. The F# wrapper suite, the Mcp, Terminal and InteractiveWrapper suites and the AOT smoke test pass.

Fixes #2250.

🤖 Generated with Claude Code

Compile<double, ...> and Compile<float, ...> took a power by Math.Pow,
for which NaN^0 and 1^NaN are 1, so (x provided x > 1)^0 at 0.7 was 1,
and ((x provided x > 1)^Im(x)) * sin(-2) was -0.909, where neither has a
value. Evaluation has none, and FastExpression and the compilers over
Complex have had none since #2225. The power is NaN now where either
side is.

A NaN over double also stands for a value that is not real, so
(sqrt(x - 2))^0 at 0.7, which is 1, is NaN now, where it was 1 by
Math.Pow's NaN^0. That is a decline where there was an answer by
coincidence, as sqrt(x - 2) + 1 - sqrt(x - 2) was already a decline
there; the other way round, a value where there is none, was a wrong
answer.

PowerOfNaNOverDoubleTest takes five powers with no value over double,
by FastExpression and in evaluation, two over float, and four with a
value.

Found by work/compilesweep.

Fixes #2250.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Oct 30, 2026
@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

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.70%. Comparing base (bd750c4) to head (830e844).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2252      +/-   ##
==========================================
- Coverage   86.71%   86.70%   -0.02%     
==========================================
  Files         310      310              
  Lines       67785    67785              
  Branches    19664    19666       +2     
==========================================
- Hits        58781    58773       -8     
- Misses       4892     4899       +7     
- Partials     4112     4113       +1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.25% <50.00%> (-0.02%) ⬇️
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 Δ
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 73.97% <50.00%> (ø)

... 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Compiled over double, a power of a value that does not exist is 1

1 participant