Module malachite_base::num::arithmetic::mod_square
source · Expand description
Traits for squaring a number modulo another number.
The traits are ModSquare
, ModSquareAssign
,
and ModSquarePrecomputed
.
ModSquarePrecomputed
is useful when having to make several
squarings modulo the same modulus.
§mod_square
use malachite_base::num::arithmetic::traits::ModSquare;
assert_eq!(2u8.mod_square(10), 4);
assert_eq!(100u32.mod_square(497), 60);
§mod_square_assign
use malachite_base::num::arithmetic::traits::ModSquareAssign;
let mut n = 2u8;
n.mod_square_assign(10);
assert_eq!(n, 4);
let mut n = 100u32;
n.mod_square_assign(497);
assert_eq!(n, 60);
§mod_square_precomputed
use malachite_base::num::arithmetic::traits::{ModPowPrecomputed, ModSquarePrecomputed};
let data = u16::precompute_mod_pow_data(&497);
assert_eq!(100u16.mod_square_precomputed(497, &data), 60);
assert_eq!(200u16.mod_square_precomputed(497, &data), 240);
assert_eq!(300u16.mod_square_precomputed(497, &data), 43);
§mod_square_precomputed_assign
use malachite_base::num::arithmetic::traits::{ModPowPrecomputed, ModSquarePrecomputedAssign};
let data = u32::precompute_mod_pow_data(&497);
let mut x = 100u32;
x.mod_square_precomputed_assign(497, &data);
assert_eq!(x, 60);
let mut x = 200u32;
x.mod_square_precomputed_assign(497, &data);
assert_eq!(x, 240);
let mut x = 300u32;
x.mod_square_precomputed_assign(497, &data);
assert_eq!(x, 43);