Perl Monk, Perl Meditation  
PerlMonks 
Comment on 
( #3333=superdoc: print w/ replies, xml )  Need Help?? 
Actually, if I recall my number theory classes correctly, the intent of the modulus operator (x mod y) is to return the smallest number possible by repeatedly subtracting y from x.
The shortcut is to divide x by y, but not all modular sets support a division operator  the natural numbers, for instance. In these cases, you have to go with the original definition. Since x  0  0  0  0  0... is clearly x, x mod 0 = x is the correct answer. People care what Knuth says about math, because he was a mathematician. Mathematicians are notoriously 'tight' about definitions, so if Knuth said that x mod 0 should return x then he had a good reason for it  one that might take some advanced math to explain. Incidentally a 'mapping' is the mathematical term given to an algorithm, very similar to what a perl programmer would think of as a function. It is a collection of rules that turns one set of numbers into another set of numbers. The perl function map is very similar in spirit to the mathematical map, except that (I don't think) it can generate new array elements for a onetomany mapping. There is often a 'null' map  a function that leaves the original set untouched. This is important for a number of reasons that may strike you as silly All these ideas are covered in very rigorous detail in any book that has 'Number Theory' in the title. ____________________ In reply to Re: Re: 0 illegal modulus?
by jepri

