I have a program in C++ (compiled using g++). I'm trying to apply two doubles as operands to the modulus function, but I get the following error:
error: invalid operands of types 'double' and 'double' to binary 'operator%'
Here's the code:
int main() {
double x = 6.3;
double y = 2;
double z = x % y;
}
fmod
may cause unexpected behaviors. For example,fmod(1, 0.1);
should mathematically be zero, but will in fact be almost 0.1. The extent of error goes up with the magnitude of the quotient. For example,fmod(9E14, 0.1);
evaluates to about 0.05, which is from a mathematical standpoint just plain wrong. – Chaineyfmod(x,0.1)
will divide x by that precise fraction and take the remainder, rather than dividing by the numerical value "one tenth". – Chainey