Upon writing
$a % 0
I am told that 0 is an illegal modulus.
However, according to "Concrete Mathematics: A Foundation for Computer Science", by Graham, Knuth (yes, that Knuth) and Patashnik 2nd ed. (page 82)
Yes, I know that division by 0 is a Bad Thing, but technically we are not dividing, we are defining the mod operator.
So this is more of a rant than a question, but it annoys me to lose functionality from one of my favourite operators in such an amusing language as Perl.
However, according to "Concrete Mathematics: A Foundation for Computer Science", by Graham, Knuth (yes, that Knuth) and Patashnik 2nd ed. (page 82)
x mod y is defined as x - y{x/y} (where {} is floor) for y!=0, and x mod 0 is defined to be x.This definition is justified; it preserves the property that x mod y always differs from x by a multiple of y, and makes sense if you think of it this way: x mod y means "map y to 0", so if y already is 0, then there is nothing to do, and x mod 0 should be congruent to x.
Yes, I know that division by 0 is a Bad Thing, but technically we are not dividing, we are defining the mod operator.
So this is more of a rant than a question, but it annoys me to lose functionality from one of my favourite operators in such an amusing language as Perl.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 0 illegal modulus?
by Vynce (Friar) on Jun 11, 2001 at 07:11 UTC | |
Re: 0 illegal modulus?
by Zaxo (Archbishop) on Jun 16, 2001 at 12:31 UTC | |
Re: 0 illegal modulus?
by Cybercosis (Monk) on Jun 12, 2001 at 00:59 UTC | |
Re: 0 illegal modulus?
by nella (Novice) on Jun 12, 2001 at 01:04 UTC | |
by Vynce (Friar) on Jun 15, 2001 at 13:33 UTC | |
by Anonymous Monk on Jun 15, 2001 at 14:04 UTC | |
Re: 0 illegal modulus?
by ambrus (Abbot) on Sep 25, 2005 at 21:56 UTC | |
by Anonymous Monk on May 01, 2012 at 03:35 UTC | |
Because it's not computing congruence
by mugwumpjism (Hermit) on Jun 15, 2001 at 14:20 UTC | |
by Tiefling (Monk) on Jun 15, 2001 at 14:33 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Meditations