Skip to content

[BUG]: constexpr fmod/remainder/remquo inexact for large arguments #138

Description

@Rinzii

Due Diligence

  • I have searched for similar issues before starting this bug report

Describe the bug

The shared x - trunc(x/y)*y reduction loses the integer quotient to floating-point rounding, so the result is wrong for large |x/y|.

Steps to reproduce

#include <ccmath/ccmath.hpp>
#include <cmath>
#include <cstdio>
int main() {
  constexpr double v = ccm::fmod(1e18, 7.0);
  printf("ccm=%.17g std=%.17g\n", v, std::fmod(1e18, 7.0));
}

Output: ccm=0 std=1 (also affects remainder and the remquo remainder).

Expected behavior

fmod(1e18, 7) should be 1 (exact reduction).

Compiler version and type

Apple clang 17.0.0 (clang-1700.4.4.1)

Operating System

No response

Screenshots

Not applicable

Activity

  1. added
    Bug: ReplicatedReproduced by at least one other person.
    and removed on Jun 13, 2026
  2. added this to the Road to v1.0.0 milestone on Jun 16, 2026
  3. added
    D3: MediumRequires a fair amount of numeric and codebase knowledge.
    on Jun 19, 2026
  4. self-assigned this
    on Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug: ReplicatedReproduced by at least one other person.D3: MediumRequires a fair amount of numeric and codebase knowledge.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions