From 98a232cb8c0b4b2dcd69bf00053087ac837b9be5 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 23 May 2021 11:54:40 +0800 Subject: [PATCH] Prevent exp underflow. --- src/packages/math_basic.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index cd2c6091..130c36a5 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -319,6 +319,8 @@ mod decimal_functions { if cfg!(not(feature = "unchecked")) { if x > Decimal::from_parts(117578, 0, 0, false, 4) { Err(make_err(format!("Exponential overflow: e ** {}", x,))) + } else if x < Decimal::from_parts(8, 0, 0, true, 0) { + Err(make_err(format!("Exponential underflow: e ** {}", x,))) } else { Ok(x.exp()) }