diff --git a/lib/src/fnc/math.rs b/lib/src/fnc/math.rs index f01a107a..ee5d2f7c 100644 --- a/lib/src/fnc/math.rs +++ b/lib/src/fnc/math.rs @@ -13,7 +13,7 @@ use crate::fnc::util::math::top::Top; use crate::fnc::util::math::trimean::Trimean; use crate::fnc::util::math::variance::Variance; use crate::sql::number::{Number, Sort}; -use crate::sql::value::Value; +use crate::sql::value::{TryPow, Value}; pub fn abs((arg,): (Number,)) -> Result { Ok(arg.abs().into()) @@ -95,7 +95,7 @@ pub fn percentile((mut array, n): (Vec, Number)) -> Result } pub fn pow((arg, pow): (Number, Number)) -> Result { - Ok(arg.pow(pow).into()) + Ok(arg.try_pow(pow)?.into()) } pub fn product((array,): (Vec,)) -> Result { diff --git a/lib/tests/function.rs b/lib/tests/function.rs index 115619ea..85960288 100644 --- a/lib/tests/function.rs +++ b/lib/tests/function.rs @@ -2428,6 +2428,15 @@ async fn function_math_pow() -> Result<(), Error> { let tmp = res.remove(0).result?; let val = Value::from(1045678.375); assert_eq!(tmp, val); + + let sql = r#" + RETURN math::pow(101, 50); + "#; + let res = &mut dbs.execute(sql, &ses, None).await?; + assert_eq!(res.len(), 1); + + let res = res.remove(0).result; + assert!(matches!(res, Err(Error::TryPow(_, _)))); // Ok(()) }