Repository navigation
Compiled arithmetic of a complex number is evaluation's at a whole power and at an infinity - #2249
Merged
Merged
Conversation
…wer and at an infinity A compiled whole power of a number that is not real went through Complex.Pow, which takes e^(n ln z) and leaves a rounded part: i^2 was (-1, 1.2e-16), which is not real, so iverson((x i)^2 < 0) at 3 was NaN where it is 1. RealProducts.Power now takes such a power as a product of its factors, by squaring, as evaluation's BinaryIntPow does. Past 2^62 it is left to Complex.Pow. System.Numerics.Complex's product takes 0 * oo as NaN in every part, so i * x at +oo was (NaN, oo) and (x + i) * 2 at -oo was (-oo, NaN). Number.OpMul takes a zero part times an infinite part as 0, and a whole zero times an infinity as NaN (#1186), and RealProducts.Product now does the same. A quotient by a real number other than 0 is taken part by part, where Complex multiplied each part by the divisor's imaginary 0: ln(x) / 2 at -oo was (NaN, NaN), and ln(ln(x)) at 0 was (oo, NaN), through ComplexBranches.Log's quotient by ln(e). The compiled sgn was z / |z|, which is oo / oo at an infinity. A real number's is now its sign, as evaluation's is. ComplexArithmeticCompilationTest compares 22 values under both compilers with evaluation, and 19 fail on master. The other three pin what has not changed: x * (2 + 3i) at -oo, and a zero times an infinity, which has no value. CompilationIntoLinqTest.TestUpcastDowncast5 compared (4 + 3i)^2 with Complex.Pow's (7.000000000000001, 24). It is 16 - 9 + 24i exactly, as evaluation has it, and the compiled power is that now. Found by work/compilesweep. Fixes #2247. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2249 +/- ##
==========================================
- Coverage 86.71% 86.71% -0.01%
==========================================
Files 310 310
Lines 67785 67809 +24
Branches 19664 19674 +10
==========================================
+ Hits 58781 58799 +18
- Misses 4892 4896 +4
- Partials 4112 4114 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Compiled arithmetic of numbers that are not real now gives evaluation's value at a whole power and at an infinity, in FastExpression and in
Compile<Complex, Complex>alike.BinaryIntPowtakes it.Complex.Pow'se^(n ln z)left a rounded part, soi^2was not real, andiverson((x i)^2 < 0)at 3 wasNaN.NaN, asNumber.OpMuldoes (limit answers 1 for z/abs(z) whatever the phase of z #1186).Complextook0 · ∞asNaNin every part.sgnof a real infinity is its sign, wherez / |z|was∞ / ∞.x^2ati(-1, 1.2246467991473532E-16)(-1, 0)x^3at1 + i(-2.0000000000000004, 2.0000000000000004)(-2, 2)iverson((x * i)^2 < 0)at 3(NaN, 0)(1, 0)i * xat+oo(NaN, Infinity)(0, Infinity)(x + i) * 2at-oo(-Infinity, NaN)(-Infinity, 2)ln(x) / 2at-oo(NaN, NaN)(Infinity, 1.5707963267948966)ln(ln(x))at 0(NaN, NaN)(Infinity, NaN)(Infinity, 3.141592653589793)sgn(x)at+oo(NaN, NaN)(1, 0)ComplexArithmeticCompilationTestchecks 22 values under both compilers against evaluation. 19 of them fail on master. The other 3 pin what did not change:x * (2 + 3i)at-oo, and a zero times an infinity, which has no value. Found bywork/compilesweep.CompilationIntoLinqTest.TestUpcastDowncast5pinnedComplex.Pow's(7.000000000000001, 24)for(4 + 3i)^2, which is7 + 24iexactly, and now expects that. Suite 18189 passed. The F# wrapper suite, the Mcp, Terminal and InteractiveWrapper suites and the AOT smoke test pass.Fixes #2247.
🤖 Generated with Claude Code