Yuvraj-cyborg commented on code in PR #19369:
URL: https://github.com/apache/datafusion/pull/19369#discussion_r2633977021
##########
datafusion/functions/src/math/power.rs:
##########
@@ -149,22 +151,118 @@ where
/// Binary function to calculate a math power to float exponent
/// for scaled integer types.
-/// Returns error if exponent is negative or non-integer, or base invalid
fn pow_decimal_float<T>(base: T, scale: i8, exp: f64) -> Result<T, ArrowError>
where
T: From<i32> + ArrowNativeTypeOp,
{
- if !exp.is_finite() || exp.trunc() != exp {
+ if exp.is_finite() && exp.trunc() == exp && exp >= 0f64 && exp < u32::MAX
as f64 {
+ return pow_decimal_int(base, scale, exp as i64);
+ }
+
+ if !exp.is_finite() {
return Err(ArrowError::ComputeError(format!(
- "Cannot use non-integer exp: {exp}"
+ "Cannot use non-finite exp: {exp}"
+ )));
+ }
+
+ pow_decimal_float_fallback(base, scale, exp)
+}
+
+/// Fallback implementation using f64 for negative or non-integer exponents.
+/// This handles cases that cannot be computed using integer arithmetic.
+fn pow_decimal_float_fallback<T>(base: T, scale: i8, exp: f64) -> Result<T,
ArrowError>
+where
+ T: From<i32> + ArrowNativeTypeOp,
+{
+ if scale < 0 {
+ return Err(ArrowError::NotYetImplemented(format!(
+ "Negative scale is not yet supported: {scale}"
+ )));
+ }
+
+ let scale_factor = 10f64.powi(scale as i32);
+ let base_f64 = format!("{base:?}")
Review Comment:
Yep sorry for that , missed the `ToPrimitive` trait and didn't think abt it.
Fixed now tho.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]