Skip to content

A compiled remainder of two integers by zero has no value - #2328

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-remainder-by-zero-has-no-value
Nov 2, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-remainder-by-zero-has-no-value

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

The LINQ compiler keeps the remainder of two integers over the integers, so that it stays exact, and the runtime's % throws for a divisor of 0. Over double or Complex, integer operands are constants. So 2 mod 0, or abs(2) mod (2 mod (-1)), compiled with Compile<double, double>, threw DivideByZeroException when the function was called. Evaluation and FastExpression give NaN for it.

Where both operands are integers and the divisor is a constant that evaluates to 0, the node is now compiled to NaN. A divisor in x is already compiled over double, where % by 0 is NaN, and the tests pin that it stays so.

Input 2.6.0 master this branch
"x + (2 mod 0)".Compile<double, double>("x")(1) DivideByZeroException DivideByZeroException NaN
"x + (2 mod 0)".Compile<Complex, Complex>("x")(1) DivideByZeroException NaN NaN

The Complex row was answered on master before this branch; the entry records it against 2.6.0, which no entry did.

Found by compilesweep, a check of compiled expressions against evaluation, at seed 10. No issue was filed.

BREAKING-CHANGES.md has an entry, after the one for a compiled division by zero. Tests:

  • ARemainderByZeroHasNoValue, whose three constant-divisor cases fail on master.
  • ARemainderOfIntegersIsTheFlooredOne, which pins the integer path's sign convention and passes on master.

Both are in DivisionByZeroOverDoubleTest.

🤖 Generated with Claude Code

The LINQ compiler keeps the remainder of two integers over the integers, so
that it stays exact, and the runtime's % throws for a divisor of 0. Over
double or Complex, integer operands are constants, so 2 mod 0, or
abs(2) mod (2 mod (-1)), threw DivideByZeroException when the compiled
function was called. Where the divisor is a constant that evaluates to 0 the
node is NaN, as evaluation and FastExpression answer. A divisor in x is
compiled over double already, where % by 0 is NaN.

"x + (2 mod 0)".Compile<double, double>("x")(1): DivideByZeroException ->
NaN. 2.6.0 threw over Complex too, which master already answers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Nov 2, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.75%. Comparing base (3bb0355) to head (46db81e).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2328   +/-   ##
=======================================
  Coverage   86.74%   86.75%           
=======================================
  Files         312      312           
  Lines       68439    68447    +8     
  Branches    19907    19909    +2     
=======================================
+ Hits        59369    59380   +11     
+ Misses       4913     4908    -5     
- Partials     4157     4159    +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.29% <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 Δ
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 93.82% <100.00%> (+0.11%) ⬆️

... and 10 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 93a52f0 into master Nov 2, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Nov 2, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-compiled-remainder-by-zero-has-no-value branch November 2, 2026 07:05
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