### Re^2: Find if a number is a multiple of a number.

by blazar (Canon)
 on Mar 03, 2005 at 07:41 UTC ( #436112=note: print w/replies, xml ) Need Help??

use % for positive integer values.
What does make you think that the use % of is limited to positive integers?
```\$ perl -le 'print for map \$_%-3, -18..-15'
0
-2
-1
0

Replies are listed 'Best First'.
Re^3: Find if a number is a multiple of a number.
by borisz (Canon) on Mar 03, 2005 at 10:26 UTC
The docs: from perlop
```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 tha
+n
\$a (i.e. the result will be less than or equal to zero).  Note that
when "use integer" is in scope "%" gives you direct access to the mod-
ulus operator as implemented by your C compiler.  This operator is not
as well defined for negative operands, but it will execute faster.
Boris
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
And... so what?
\$a (i.e. the result will be less than or equal to zero). Note that when "use integer" is in scope "%" gives you direct access to the mod- ulus operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster.
Is this the particular point on which you meant to draw the attention? If so, then it actually is a good point, however IMHO it belongs more to the realm of side notes...

Create A New User
Node Status?
node history
Node Type: note [id://436112]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-07-15 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

Results (326 votes). Check out past polls.

Notices?