simba
simba copied to clipboard
Add more methods from `num_traits::Float`
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:
min_positive_valueis_nannaninfinityandneg_infinitymaxandminwith theNaNsemanticscopysign
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?
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
}
}
}
same but more succinct
#[inline]
fn is_nan<R: RealField>(x: R) -> bool {
x.partial_cmp(&R::zero()).is_none()
}
Thanks @lelongg . Also clippy does not complain about your version.