Can’t Mod Zero?

The C++ Standard(2003) says in ยง5.6/4, […] If the second operand of / or % is zero the behavior is undefined; […] That is, following expressions invoke undefined-behavior(UB): X / 0; //UB X % 0; //UB Note also that -5 % 2 is NOT equal to -(5 % 2) (as Petar seems to suggest in … Read more

Why doesn’t Java throw an Exception when dividing by 0.0?

Java’s float and double types, like pretty much any other language out there (and pretty much any hardware FP unit), implement the IEEE 754 standard for floating point math, which mandates division by zero to return a special “infinity” value. Throwing an exception would actually violate that standard. Integer arithmetic (implemented as two’s complement representation … Read more