Function mod_exp::mod_exp [] [src]

pub fn mod_exp<T>(base: T, exponent: T, modulus: T) -> T where T: Num + PartialOrd + Shr<T, Output=T> + Copy + Bounded

Performs the exponentiation

All parameters are generic, provided they implement the following traits:

  • Num
  • PartialOrd
  • Shr
  • Copy
  • Bounded

You can find the Num and Bounded traits in the num crate.

Examples

use mod_exp::mod_exp;

assert_eq!(mod_exp(5, 3, 13), 8);

Panics

The function does an assert! to verify that the data type of base is large enough that the result won't overflow during the computation