It's well defined for JavaScript:
The result of an ECMAScript floating-point remainder operation is
determined by the rules of IEEE arithmetic: [...]
If the dividend is an infinity, or the divisor is a zero, or both, the
result is NaN
.
Now about the other languages. The common approach (Java, C#, Python, Ruby) is to throw some kind of ZeroDivisionError
at you when you attempt to evaluate somenum % 0
expression.
For Perl, it's a bit more interesting:
use Data::Dumper;
print Dumper 0 % 0;
print 'Something else';
Now, this code results in Illegal modulus zero
error; but had you put 0 / 0
instead, you would have seen Illegal division by zero
message. Both are errors (stop execution of the remaining code), of course, not warnings.
Now PHP chooses a bit different stance on this:
var_dump(0 % 0); // it's the same for any numeric dividend
// Warning: Division by zero in ...
// bool(false)
As you see, you get false
(sic) as a result, but warning is triggered. It's ignorable, though; have you set error_reporting
level to E_ERROR
, you wouldn't have even seen it.