Skip to content

Compile a real remainder over double and float with one rounding - #2333

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-real-remainder-is-not-taken-twice
Nov 2, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-real-remainder-is-not-taken-twice

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Found by compilesweep at seed 11, where pi / floor(2 mod e) compiled to pi. No issue was filed.

The LINQ compiler wrote the floored remainder as ((a % b) + b) % b. Over the integers that is exact. Over double the second % rounds, even where the first remainder already had the divisor's sign.

compiled over double, 2.6.0 and master now evaluated
2 mod e = 1.9999999999999996 2 2
floor(2 mod e) = 1 2 2

Over double and float, the remainder is now taken once, and the divisor is added only where the signs differ, as RealOnly.Mod already does for Complex. The integer types keep the exact expression.

Tests: three of the seven in ACompiledRealRemainderTest fail on master. The 1,191 compile tests pass. There is a BREAKING entry, A compiled remainder of two reals is rounded once.

🤖 Generated with Claude Code

The LINQ compiler wrote the floored remainder as ((a % b) + b) % b. Over
the integers that is exact; over double the second % rounds even where the
first remainder already had the divisor's sign. 2 mod e compiled to
1.9999999999999996, and floor(2 mod e) to 1, where both evaluate to 2.

Over double and float the remainder is now taken once and the divisor
added only where the signs differ, as RealOnly.Mod already did for Complex.
The integer types keep the exact expression.

Found by compilesweep at seed 11: pi / floor(2 mod e) compiled to pi.

Co-Authored-By: Claude Opus 5.5 <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

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.76%. Comparing base (93a52f0) to head (d8b33ee).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...rces/AngouriMath/Functions/Compilation/RealOnly.cs 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2333   +/-   ##
=======================================
  Coverage   86.75%   86.76%           
=======================================
  Files         312      312           
  Lines       68447    68460   +13     
  Branches    19909    19913    +4     
=======================================
+ Hits        59379    59396   +17     
+ Misses       4908     4904    -4     
  Partials     4160     4160           
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.30% <92.30%> (+<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.94% <100.00%> (+0.12%) ⬆️
...rces/AngouriMath/Functions/Compilation/RealOnly.cs 94.44% <75.00%> (-5.56%) ⬇️

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

@Rafael-SOWNet
Rafael-SOWNet merged commit d2fc4dc 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-real-remainder-is-not-taken-twice branch November 2, 2026 16:51
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