### The "%" operator and its documentation.

by syphilis (Bishop)
 on Jun 14, 2021 at 01:40 UTC Need Help??

```C:\_32>perl -wle "\$m = (2**113) - 1; \$n = 2; print \$m % \$n;"
0
```
```C:\_32>perl -MPOSIX -wle "\$m = (2**113) - 1; \$n = 2; print fmod(\$m, \$n
+);"
1
```
```Binary "%" is the modulo operator, which computes the division remaind
+er
of its first argument with respect to its second argument. Given integ
+er
...
Note that when "use integer" is in scope, "%" gives you direct access
+to
the modulo operator as implemented by your C compiler. This operator i
+s
not as well defined for negative operands, but it will execute faster.
```
```If \$n is positive, then "\$m % \$n" is \$m minus the largest multiple of
+\$n less than or equal to \$m.
....
...
\$n (that is "abs(\$n)") is less than "(UV_MAX + 1)", only the integer
portion of \$m and \$n will be used in the operation (Note: here "UV_MAX
+"
means the maximum of the unsigned integer type)
```
```C:\_32>perl -wle "\$r = 10384593717069655257060992658440191.0 - (519229
+6858534827628530496329220095.0 * 2); print \$r;"
1
```
```C:\_32>perl -wle "\$m = (2**113) - 1; \$n = 2; print \$m % \$n;"
0

C:\_32>perl -MPOSIX -wle "\$m = (2**113) - 1; \$n = 2; print fmod(\$m, \$n
+);"
1
```
```C:\>perl -wle "\$m = (2**64) - 1; \$n = 2; print \$m % \$n;"
0

C:\>perl -MPOSIX -wle "\$m = (2**64) - 1; \$n = 2; print fmod(\$m, \$n);"
1
```
```C:\_32>perl -wle "\$m = (2**53) - 1; \$n = 2; print \$m % \$n;"
1

C:\_32>perl -MPOSIX -wle "\$m = (2**53) - 1; \$n = 2; print fmod(\$m, \$n)
+;"
1
```

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11133829]
Approved by GrandFather
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-09-29 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?