Trait num_traits::sign::Signed
source · [−]pub trait Signed: Sized + Num + Neg<Output = Self> {
fn abs(&self) -> Self;
fn abs_sub(&self, other: &Self) -> Self;
fn signum(&self) -> Self;
fn is_positive(&self) -> bool;
fn is_negative(&self) -> bool;
}
Expand description
Useful functions for signed numbers (i.e. numbers that can be negative).
Required Methods
sourcefn abs(&self) -> Self
fn abs(&self) -> Self
Computes the absolute value.
For f32
and f64
, NaN
will be returned if the number is NaN
.
For signed integers, ::MIN
will be returned if the number is ::MIN
.
sourcefn abs_sub(&self, other: &Self) -> Self
fn abs_sub(&self, other: &Self) -> Self
The positive difference of two numbers.
Returns zero
if the number is less than or equal to other
, otherwise the difference
between self
and other
is returned.
sourcefn signum(&self) -> Self
fn signum(&self) -> Self
Returns the sign of the number.
For f32
and f64
:
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NaN
if the number isNaN
For signed integers:
0
if the number is zero1
if the number is positive-1
if the number is negative
sourcefn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Returns true if the number is positive and false if the number is zero or negative.
sourcefn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Returns true if the number is negative and false if the number is zero or positive.
Implementations on Foreign Types
sourceimpl Signed for isize
impl Signed for isize
fn abs(&self) -> isize
fn abs_sub(&self, other: &isize) -> isize
fn signum(&self) -> isize
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
sourceimpl Signed for i8
impl Signed for i8
fn abs(&self) -> i8
fn abs_sub(&self, other: &i8) -> i8
fn signum(&self) -> i8
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
sourceimpl Signed for i16
impl Signed for i16
fn abs(&self) -> i16
fn abs_sub(&self, other: &i16) -> i16
fn signum(&self) -> i16
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
sourceimpl Signed for i32
impl Signed for i32
fn abs(&self) -> i32
fn abs_sub(&self, other: &i32) -> i32
fn signum(&self) -> i32
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
sourceimpl Signed for i64
impl Signed for i64
fn abs(&self) -> i64
fn abs_sub(&self, other: &i64) -> i64
fn signum(&self) -> i64
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
sourceimpl<T: Signed> Signed for Wrapping<T>where
Wrapping<T>: Num + Neg<Output = Wrapping<T>>,
impl<T: Signed> Signed for Wrapping<T>where
Wrapping<T>: Num + Neg<Output = Wrapping<T>>,
fn abs(&self) -> Self
fn abs_sub(&self, other: &Self) -> Self
fn signum(&self) -> Self
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
sourceimpl Signed for f32
impl Signed for f32
sourcefn abs_sub(&self, other: &f32) -> f32
fn abs_sub(&self, other: &f32) -> f32
The positive difference of two numbers. Returns 0.0
if the number is
less than or equal to other
, otherwise the difference betweenself
and other
is returned.
sourcefn signum(&self) -> f32
fn signum(&self) -> f32
Returns
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number is NaN
sourcefn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Returns true
if the number is positive, including +0.0
and INFINITY
sourcefn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Returns true
if the number is negative, including -0.0
and NEG_INFINITY
sourceimpl Signed for f64
impl Signed for f64
sourcefn abs_sub(&self, other: &f64) -> f64
fn abs_sub(&self, other: &f64) -> f64
The positive difference of two numbers. Returns 0.0
if the number is
less than or equal to other
, otherwise the difference betweenself
and other
is returned.
sourcefn signum(&self) -> f64
fn signum(&self) -> f64
Returns
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number is NaN
sourcefn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Returns true
if the number is positive, including +0.0
and INFINITY
sourcefn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Returns true
if the number is negative, including -0.0
and NEG_INFINITY