jayzhan211 commented on code in PR #11036: URL: https://github.com/apache/datafusion/pull/11036#discussion_r1648427373
########## datafusion/functions/src/math/gcd.rs: ########## @@ -88,14 +88,15 @@ fn gcd(args: &[ArrayRef]) -> Result<ArrayRef> { /// Computes greatest common divisor using Binary GCD algorithm. pub fn compute_gcd(x: i64, y: i64) -> i64 { - let mut a = x.wrapping_abs(); - let mut b = y.wrapping_abs(); + // because the input values are i64, casting these u64's back to i64 causes no overflow + let mut a = x.unsigned_abs(); + let mut b = y.unsigned_abs(); if a == 0 { - return b; + return b as i64; Review Comment: If we move `unsigned_abs();` below, we don't need to cast ########## datafusion/functions/src/math/gcd.rs: ########## @@ -88,14 +88,15 @@ fn gcd(args: &[ArrayRef]) -> Result<ArrayRef> { /// Computes greatest common divisor using Binary GCD algorithm. pub fn compute_gcd(x: i64, y: i64) -> i64 { - let mut a = x.wrapping_abs(); - let mut b = y.wrapping_abs(); + // because the input values are i64, casting these u64's back to i64 causes no overflow + let mut a = x.unsigned_abs(); + let mut b = y.unsigned_abs(); if a == 0 { - return b; + return b as i64; Review Comment: If we move `unsigned_abs()` below, we don't need to cast -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org