arrow2
arrow2 copied to clipboard
CheckedDiv will not work on float
I was checking that the kernel for checked division wont work for floats. That is because it depends on the trait CheckedDiv and that is only implemented for integers (trait).
I'm wondering if instead of depending on that trait it should implement its own version of the checked operation that will include floats. We can check if the value is Zero and return None if that is the case. At least Zero is implemented for floats
I would say this is too specialized: Rust has no checked_div
for floats because that won't panic:
fn main() {
let a = 1.0f32;
let a = a / 0.0f32;
println!("{}", a);
}
inf
I remember I wrote this because I had the same issue with Polars when implementing it in Nushell. Ritchie was kind enough to add this trait which later was modified to allow floats as well.
I think it will be very common to have a division by zero with floats and it would be better to return a null
cell rather than a panic