routine expmod
Documentation for routine expmod assembled from the following types:
class Int
From Int
(Int) routine expmod
Defined as:
multi sub expmod( $x, $y, $mod --> Int:D) multi sub expmod(Int:D $x, Int $y, Int $mod --> Int:D) multi method expmod(Int:D: Int $y, Int $mod --> Int:D)
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»