routine expmod
1 | class Int |
1.1 | (Int) routine expmod |
Documentation for routine expmod
assembled from the following types:
class Int
From Int
(Int) routine expmod
Defined as:
multi sub expmod( , , --> Int)multi sub expmod(Int , Int , Int --> Int)multi method expmod(Int: Int , Int --> Int)
Returns the given Int
raised to the $y
power within modulus $mod
, that is gives the result of ($x ** $y) mod $mod
. The subroutine form can accept non-Int
arguments, which will be coerced to Int
.
say expmod(4, 2, 5); # OUTPUT: «1»say 7.expmod(2, 5); # OUTPUT: «4»
$y
argument can also be negative, in which case, the result is equivalent to ($x ** $y)
mod $mod.
say 7.expmod(-2, 5); # OUTPUT: «4»