findepi commented on code in PR #6906:
URL: https://github.com/apache/arrow-rs/pull/6906#discussion_r1892271421
##########
arrow-arith/src/numeric.rs:
##########
@@ -574,6 +574,17 @@ trait IntervalOp: ArrowPrimitiveType {
fn div_float(left: Self::Native, right: f64) -> Result<Self::Native,
ArrowError>;
}
+/// Helper function to safely convert f64 to i32, checking for overflow and
invalid values
+fn f64_to_i32(value: f64) -> Result<i32, ArrowError> {
+ if !value.is_finite() || value > i32::MAX as f64 || value < i32::MIN as
f64 {
+ Err(ArrowError::ComputeError(
+ "Division result out of i32 range".to_string(),
+ ))
+ } else {
+ Ok(value as i32)
+ }
Review Comment:
is there a builtin faillible version of `float_value as i32` that we could
use instead of implementing the logic ourselves?
--
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]