Skip to content

A compiled division by zero over double has no value - #2288

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
a-compiled-division-by-zero-over-double-has-no-value
Oct 31, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
a-compiled-division-by-zero-over-double-has-no-value

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Compiled over double, 1/x at 0 was +Infinity, where evaluation, FastExpression and the compiler over Complex all say NaN. The compiler emitted the IEEE quotient. Math.Pow likewise made 0^(-1) an infinity and 0^0 equal to 1, where evaluation makes both NaN.

A division over double or float now calls MathAllMethods.Divide, which answers a zero divisor with NaN, and Pow answers 0 raised to a power that is not positive with NaN. A compiled matrix argument divided by a scalar now does the same, entry by entry.

Input 2.6.0 and master Now
"1/x".Compile<double, double>("x")(0) +Infinity NaN
"x^(-1)".Compile<double, double>("x")(0) +Infinity NaN
"x^x".Compile<double, double>("x")(0) 1 NaN
"A / x", a matrix A at x = 0 +Infinity entries NaN entries

DivisionByZeroOverDoubleTest: the seven scalar cases fail on master, and the matrix case fails with master's TensorCompilation. The suite (18,286), the trio, F#, AOT and the eight harnesses pass locally. work/compilesweep found 19 of these in 3000 random compositions.

This leaves the other half of #2286 open: the 60 expressions with a real value and a non-real intermediate, which the double compiler gives as NaN. That is a question for the maintainer. Also found while testing, and filed as #2287: compiled x / A, with a matrix argument, divides entry by entry where evaluation multiplies by the inverse.

Part of #2286.

🤖 Generated with Claude Code

Rafael-SOWNet and others added 2 commits October 30, 2026 22:09
Compiled over double, 1/x at 0 was +Infinity, where evaluation,
FastExpression and the compiler over Complex all say NaN. The compiler
emitted the IEEE quotient, and Math.Pow made 0^(-1) an infinity and
0^0 1, where evaluation makes both NaN too.

A division over double or float now calls MathAllMethods.Divide, which
answers a zero divisor with NaN, and Pow answers 0 to a power that is
not positive with NaN. The elementwise division of a compiled matrix
does as the scalar one does.

DivisionByZeroOverDoubleTest takes seven expressions that have no
value, over double and float, and four that have one; the seven fail
on master. The suite, the trio, F#, AOT and the eight harnesses pass.
work/compilesweep found 19 of these in 3000 random compositions.

Fixes #2286.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A matrix written into the expression is divided entry by entry before
it is compiled, and only a matrix argument reaches the compiled matrix
division. AMatrixOverZeroHasNoEntries divides one by 0, and fails with
master's TensorCompilation, whose entries were +Infinity.

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 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.72%. Comparing base (6d2a960) to head (13545a3).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 66.66% 2 Missing ⚠️
...unctions/Compilation/IntoLinq/TensorCompilation.cs 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2288      +/-   ##
==========================================
+ Coverage   86.71%   86.72%   +0.01%     
==========================================
  Files         310      310              
  Lines       67849    67861      +12     
  Branches    19690    19696       +6     
==========================================
+ Hits        58836    58854      +18     
+ Misses       4894     4886       -8     
- Partials     4119     4121       +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.27% <69.23%> (+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 Δ
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 93.52% <100.00%> (+0.07%) ⬆️
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 74.24% <66.66%> (+0.26%) ⬆️
...unctions/Compilation/IntoLinq/TensorCompilation.cs 49.29% <0.00%> (+1.40%) ⬆️

... and 7 files with indirect coverage changes

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

@Rafael-SOWNet
Rafael-SOWNet merged commit e238512 into master Oct 31, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 31, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-compiled-division-by-zero-over-double-has-no-value branch October 31, 2026 04:22
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.

1 participant