diff options
| author | HarmoGlace <23212967+HarmoGlace@users.noreply.github.com> | 2023-04-13 21:08:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 21:08:54 +0200 |
| commit | 29b36d487609b6a291c3847703f36928082cc8a2 (patch) | |
| tree | 1e684d67757a6b2885e1027d1e74a60912db0b48 /library | |
| parent | 6d596da72b16e486a4ca9c69a416bf21b88d30f0 (diff) | |
Fix `pow` overflow (#784)
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/compute/calc.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index f4695675..d5166449 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())), }; |
