You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Returns true if the number is positive and false if the number is zero or negative.fnis_positive(&self) -> bool;/// Returns true if the number is negative and false if the number is zero or positive.fnis_negative(&self) -> bool;
However, for signed integer types, we have the following, which matches the documentation:
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`#[inline]fnis_positive(&self) -> bool{FloatCore::is_sign_positive(*self)}/// Returns `true` if the number is negative, including `-0.0` and `NEG_INFINITY`#[inline]fnis_negative(&self) -> bool{FloatCore::is_sign_negative(*self)}
I'm not sure what the best approach here (i.e. should 0 count as positive or not for floating point).
But the behavior should be consistent between floats and ints, and match the documentation on the Signed trait.
Otherwise it leads to really subtle and dangerous arithmetic errors.
The text was updated successfully, but these errors were encountered:
Based on the documentation:
However, for signed integer types, we have the following, which matches the documentation:
But then for floating point types we have:
And so with a simple test like this:
We get:
I'm not sure what the best approach here (i.e. should 0 count as positive or not for floating point).
But the behavior should be consistent between floats and ints, and match the documentation on the
Signed
trait.Otherwise it leads to really subtle and dangerous arithmetic errors.
The text was updated successfully, but these errors were encountered: