diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index f46956754..d5166449e 100644 --- a/library/src/compute/calc.rs +++ b/library/src/compute/calc.rs @@ -108,7 +108,11 @@ pub fn pow( }; let result = match (base, exponent.v) { - (Num::Int(a), Num::Int(b)) if b >= 0 => Num::Int(a.pow(b as u32)), + (Num::Int(a), Num::Int(b)) if b >= 0 => a + .checked_pow(b as u32) + .map(Num::Int) + .ok_or("the result is too large") + .at(args.span)?, (a, Num::Int(b)) => Num::Float(a.float().powi(b as i32)), (a, b) => Num::Float(a.float().powf(b.float())), }; diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ index 905520e68..c9e235426 100644 --- a/tests/typ/compute/calc.typ +++ b/tests/typ/compute/calc.typ @@ -90,6 +90,10 @@ // Error: 14-31 exponent is too large #calc.pow(2, 10000000000000000) +--- +// Error: 10-25 the result is too large +#calc.pow(2, 2147483647) + --- // Error: 14-36 exponent may not be infinite, subnormal, or NaN #calc.pow(2, calc.pow(2.0, 10000.0))