Skip to content

[BUG]: constexpr remainder computes fmod instead of IEEE remainder #136

Open

Description

@Rinzii

Due Diligence

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

Describe the bug

The constexpr remainder path uses x - trunc(x/y)*y (truncated quotient, which is fmod), but IEEE remainder must round the quotient to nearest-even. Wrong whenever the fractional part of x/y exceeds 0.5.

Steps to reproduce

#include <ccmath/ccmath.hpp>
#include <cmath>
#include <cstdio>
int main() {
  constexpr double v = ccm::remainder(5.0, 3.0);
  printf("ccm=%g std=%g\n", v, std::remainder(5.0, 3.0));
}

Output: ccm=2 std=-1.

Expected behavior

remainder(5,3) should be -1 (quotient rounds to 2, so 5 - 2*3 = -1).

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. self-assigned this
    on Jun 19, 2026
  4. added
    D3: MediumRequires a fair amount of numeric and codebase knowledge.
    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