arrow2 icon indicating copy to clipboard operation
arrow2 copied to clipboard

CheckedDiv will not work on float

Open elferherrera opened this issue 3 years ago • 2 comments

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

elferherrera avatar Jun 17 '21 19:06 elferherrera

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

jorgecarleitao avatar Oct 08 '21 05:10 jorgecarleitao

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

elferherrera avatar Oct 08 '21 09:10 elferherrera