Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Tymm Twillman wrote:
>
> you know, this then caused me to go look at perlop(1); description there:
>
> Binary ``%'' computes the modulus of two numbers. Given integer operands
> $a and $b: If $b is positive, then $a % $b is $a minus the largest
> multiple of $b that is not greater
> than $a. If $b is negative, then $a % $b is $a minus the smallest multiple
> of $b that is not less than $a (i.e. the result will be less than or equal
> to zero).
>
> (got that?)
>
> which means that perl is broken as re: documentation. Probably so many
> people expect modulus to always return a positive # that they broke it.
>
> -Tymm
Nope. As per above: $a = -98, $b = 100. Since $b is positive, rule one
applies. Therefore, $a % $b = %a - $b * x, where $b * x < $a. Thus, x
= -2, $b * x = -200, and $a % $b = -98 - (-200) = 2.
Looks like what perl returned for me.
Chris
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christopher J. Kaiser
Assistant Professor
Animal Sciences Unit
University of Missouri
Columbia, MO 65211
EMAIL:PROTECTED
phone: 573.882.5479
fax: 573.884.4606
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~