expmod
ErrorsCollection

expmod

Synthesised documentation from type/Int

From type/Int

See Original text in context

multi sub    expmod(      $x,     $y,     $mod --> Int:D)
multi sub    expmod(Int:D $xInt $yInt $mod --> Int:D)
multi method expmod(Int:D:    Int $yInt $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(425);    # OUTPUT: «1␤» 
say 7.expmod(25);     # OUTPUT: «4␤»

$y argument can also be negative, in which case, the result is equivalent to ($x ** $y) mod $mod.

say 7.expmod(-25);     # OUTPUT: «4␤»