diff --git a/datafusion/functions/src/math/common.rs b/datafusion/functions/src/math/common.rs index 9bb6f6fe1e35..f7093eee893c 100644 --- a/datafusion/functions/src/math/common.rs +++ b/datafusion/functions/src/math/common.rs @@ -140,7 +140,9 @@ pub(crate) fn lcm_signed_int(x: i64, y: i64) -> Result { let a = x.unsigned_abs(); let b = y.unsigned_abs(); - let gcd = gcd_helper::(a, b)?; + // Use the binary GCD, matching `gcd_signed_int` and avoiding the + // per-iteration division of the Euclidean `gcd_helper`. + let gcd = unsigned_gcd(a, b); // gcd is not zero since both a and b are not zero, so the division is safe. (a / gcd) .checked_mul(b)