Function sp_runtime::traits::ensure_pow

source ·
pub fn ensure_pow<T>(base: T, exp: usize) -> Result<T, ArithmeticError>where
    T: One + CheckedMul + Clone,
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)?;

assert_eq!(overflow(), Err(ArithmeticError::Overflow));