Skip to content

Fix constexpr remainder and make fmod exact for large quotients - #208

Merged
Rinzii merged 7 commits into
release/0.3.xfrom
fix/constexpr-fmod-remainder
Jun 22, 2026
Merged

Rinzii merged 7 commits into
release/0.3.xfrom
fix/constexpr-fmod-remainder

Conversation

@Rinzii

@Rinzii Rinzii commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

remainder was using the fmod formula (x - trunc(x / y) * y), which truncates the quotient instead of rounding to nearest, so it was wrong even for small inputs. fmod's constexpr kernel used the same formula and lost bits once abs(x / y) hit 2^53. remainder now delegates to remquo.

Fixes #136 and #138.

How tested

Clang and gcc presets, Debug/Release, C++17/20, warnings-as-errors. The kernel is bit-identical to MPFR mpfr_fmod across 278M float and 60M double pairs (large-quotient and subnormal bands included).

@Rinzii Rinzii closed this Jun 21, 2026
@Rinzii Rinzii reopened this Jun 21, 2026
@Rinzii
Rinzii force-pushed the fix/constexpr-fmod-remainder branch from f6802b9 to 5f6c1f6 Compare June 21, 2026 23:08
@Rinzii
Rinzii merged commit 119f4c5 into release/0.3.x Jun 22, 2026
105 checks passed
@Rinzii
Rinzii deleted the fix/constexpr-fmod-remainder branch June 22, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: constexpr fmod/remainder/remquo inexact for large arguments [BUG]: constexpr remainder computes fmod instead of IEEE remainder

1 participant