diff options
author | Gisle Aas <gisle@aas.no> | 1998-05-12 08:58:58 +1200 |
---|---|---|
committer | Tim Bunce <Tim.Bunce@ig.co.uk> | 1998-05-12 08:58:58 +1200 |
commit | 4ec9372ef8b322596f1c5e9118795fe908fe4ab7 (patch) | |
tree | ad2fed303229f4fb5e5b92163df0065302a768b7 | |
parent | c580bd34c5b00f144691f16a8cde563d14277368 (diff) | |
download | perl-4ec9372ef8b322596f1c5e9118795fe908fe4ab7.tar.gz |
Document integer pragma effect on % operator
Jon Orwant <orwant@media.mit.edu> writes:
> Of course I expect "use integer" to use integers for everything.
> I don't see why that should change the value of -534 % 210.
>
> Here's what perlmod says:
>
> 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).
>
> $a is -534. $b is 210. The largest multiple of 210 not greater than -534
> is -630. Ergo, -534 % 210 is -534 - -630, or 96.
>
> But if you "use integer", you get -114. Arithmetic Most Foul.
I think it should stay the way it is. Perhaps we should apply this
documentation patch.
p5p-msgid: m3yawjmzhx.fsf@furu.g.aas.no
-rw-r--r-- | pod/perlop.pod | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/pod/perlop.pod b/pod/perlop.pod index e4088ec9c4..538745dd6a 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -186,6 +186,11 @@ C<$a>. If C<$b> is negative, then C<$a % $b> is C<$a> minus the smallest multiple of C<$b> that is not less than C<$a> (i.e. the result will be less than or equal to zero). +Note than when C<use integer> is in scope "%" give you direct access +to the modulus operator as implemented by your C compiler. This +operator is not as well defined for negative operands, but it will +execute faster. + Binary "x" is the repetition operator. In a scalar context, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In a list context, if the left |