Front page | perl.perl6.language |
Postings from May 2005
May 30, 2005 02:15
Message ID: 429AD9C4.firstname.lastname@example.org
Mark Reed wrote:
> I would really like to see ($x div $y) be (floor($x/$y))
That is: floor( 8 / (-3) ) == floor( -2.6666.... ) == -3
Or do you want -2?
> and ($x mod $y) be ($x - $x div $y).
Hmm, since 8 - (-3) == 11 this definition hardly works.
But even with $q = floor( $x / $y ) and $r = $x - $q * $y
we get 8 - (-3) * (-3) == -1 where I guess you expect -2.
Looks like you want some case distinction there on the
sign of $x.
> If the divisor is positive the modulus should be
> positive, no matter what the sign of the dividend.
The problem is that with two numbers $x and $y you get
four combinations of signs which must be considered when
calculating $q and $r such that $x == $q * $y + $r holds.
> Avoids lots of special case code across 0 boundaries.
If there is a definition that needs no special casing
then it is the euclidean definition that 0 <= $r < abs $y.
TSa (Thomas Sandlaß)