pub fn exp(op1: i32, op2: i32) -> i32Expand description
Raises the first operand to the power of the second operand, saturating on
overflow. Produces correct answers for base 0 or 1 even for negative
exponents, otherwise treats x^y when y<0 as 0. This serves as the
definition of exponentiation in the dice expression language.
§Parameters
op1: The base.op2: The exponent.
§Returns
The result of op1 raised to the power of op2.
§Examples
assert_eq!(exp(2, 3), 8);
assert_eq!(exp(2, 0), 1);
assert_eq!(exp(0, 0), 1);
assert_eq!(exp(0, 1), 0);
assert_eq!(exp(0, -1), 0);
assert_eq!(exp(1, 0), 1);
assert_eq!(exp(1, 1), 1);
assert_eq!(exp(1, -1), 1);
assert_eq!(exp(-1, 0), 1);
assert_eq!(exp(-1, 1), -1);
assert_eq!(exp(-1, 2), 1);
assert_eq!(exp(-1, 3), -1);
assert_eq!(exp(-1, -1), -1);
assert_eq!(exp(-1, -2), 1);
assert_eq!(exp(-1, -3), -1);
assert_eq!(exp(2, -1), 0);
assert_eq!(exp(10, 20), i32::MAX);
assert_eq!(exp(-10, 20), i32::MAX);
assert_eq!(exp(-10, 21), i32::MIN);