dimforge / simba

Set of mathematical traits to facilitate the use of SIMD-based AoSoA (Array of Struct of Array) storage pattern.
Apache License 2.0
295 stars 29 forks source link

Add more methods from `num_traits::Float` #2

Open jannschu opened 4 years ago

jannschu commented 4 years ago

There are a couple of occasions where I regularly have to add an additional num_traits::Float bound.

Methods I need from num_traits::Float include the following:

Is the RealField suitable for these methods or is it intended to be more abstract, i.e., it not necessarily represents these floating point semantics?

astraw commented 4 years ago

For what it is worth, here is what I am using for is_nan to avoid adding this bound:


#[inline]
fn is_nan<R: RealField>(x: R) -> bool {
    let zero = R::zero();
    if x < zero {
        false
    } else {
        if x >= zero {
            false
        } else {
            true
        }
    }
}
lelongg commented 3 years ago

same but more succinct

#[inline]
fn is_nan<R: RealField>(x: R) -> bool {
    x.partial_cmp(&R::zero()).is_none()
}
astraw commented 3 years ago

Thanks @lelongg . Also clippy does not complain about your version.