From: Ken Williams Date: Sat, 16 Feb 2008 23:22:15 +0000 (-0600) Subject: Modulo operator and floating point numbers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f7918450ac2de46c81759dc6b3ec6eb57f5b59f0;p=p5sagit%2Fp5-mst-13.2.git Modulo operator and floating point numbers From: "Ken Williams" Message-ID: <6a7ee8cc0802162122r4e59b93boee18b1f045b8954d@mail.gmail.com> p4raw-id: //depot/perl@33328 --- diff --git a/pod/perlop.pod b/pod/perlop.pod index cf2cfc7..1827757 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -260,9 +260,11 @@ X<*> Binary "/" divides two numbers. X X -Binary "%" computes the division remainder of two numbers. Given integer +Binary "%" is the modulo operator, which computes the division +remainder of its first argument with respect to its second argument. +Given integer operands C<$a> and C<$b>: If C<$b> is positive, then C<$a % $b> is -C<$a> minus the largest multiple of C<$b> that is not greater than +C<$a> minus the largest multiple of C<$b> less than or equal to 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). If the operands @@ -273,14 +275,14 @@ the integer portion of C<$a> and C<$b> will be used in the operation If the absolute value of the right operand (C) is greater than or equal to C<(UV_MAX + 1)>, "%" computes the floating-point remainder C<$r> in the equation C<($r = $a - $i*$b)> where C<$i> is a certain -integer that makes C<$r> should have the same sign as the right operand +integer that makes C<$r> have the same sign as the right operand C<$b> (B as the left operand C<$a> like C function C) and the absolute value less than that of C<$b>. Note that when C is in scope, "%" gives you direct access -to the modulus operator as implemented by your C compiler. This +to the modulo operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster. -X<%> X X X +X<%> X X X Binary "x" is the repetition operator. In scalar context or if the left operand is not enclosed in parentheses, it returns a string consisting