Function sp_arithmetic::traits::ensure_pow
source ยท pub fn ensure_pow<T: One + CheckedMul + Clone>(
base: T,
exp: usize,
) -> Result<T, ArithmeticError>
Expand description
Raises a value to the power of exp, returning ArithmeticError
if an overflow occurred.
Check checked_pow
for more info about border cases.
use sp_arithmetic::{traits::ensure_pow, ArithmeticError};
fn overflow() -> Result<(), ArithmeticError> {
ensure_pow(2u64, 64)?;
Ok(())
}
assert_eq!(overflow(), Err(ArithmeticError::Overflow));