Why so many programs return wrong remainder?
Please before continue read what remainder is, th1.1.3. ***
Why many programs including all C flavours compilers, windows calc, Excel....
Code:
#include <iostream> /* TEST, SEE WITH YOUR EYES */
int main()<% std::cout << -3 % 2; %>
...return wrong result? (-1 instead of 1, in this case)
I guess it is something about how to the machine compare less significant bits.
But I'd like to know where is the problem exactly.
Do someone know? Thanks.
*** Note: actually there is a small imprecision, b CAN be negative and 0 <= r < abs(b). Probably it is wrote that wat because it won't affect remainder.