Strictly speaking is Modulo only defined for positive integers, excluding 0 for the dividend.
Many languages take incompatible liberties in extending this definition by relying on the same implementation/algorithm, but also allowing floats as input.
The rounding errors theory in your case is very convincing. But you should also check results with negative values and error cases
> Surely, the sane thing to do would be to throw an exception.
NB: JS is particularly reluctant to throw exceptions, it rather follows the "quiet" NaN (= not a number) approach, to silently fail.
IMHO it's impossible to translate this behavior to efficient pure Perl.
Update
I have problems imagining a use case for float modulo operations, except reimplementing division.
Any ideas?
|