Due Diligence
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
Due Diligence
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
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