num_traits::sign

Trait Signed

Source
pub trait Signed:
    Sized
    + Num
    + Neg<Output = Self> {
    // Required methods
    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§

Source

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.

Source

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.

Source

fn signum(&self) -> Self

Returns the sign of the number.

For f32 and f64:

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NaN if the number is NaN

For signed integers:

  • 0 if the number is zero
  • 1 if the number is positive
  • -1 if the number is negative
Source

fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative.

Source

fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Signed for f32

Source§

fn abs(&self) -> f32

Computes the absolute value. Returns NAN if the number is NAN.

Source§

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.

Source§

fn signum(&self) -> f32

§Returns
  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NaN
Source§

fn is_positive(&self) -> bool

Returns true if the number is positive, including +0.0 and INFINITY

Source§

fn is_negative(&self) -> bool

Returns true if the number is negative, including -0.0 and NEG_INFINITY

Source§

impl Signed for f64

Source§

fn abs(&self) -> f64

Computes the absolute value. Returns NAN if the number is NAN.

Source§

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.

Source§

fn signum(&self) -> f64

§Returns
  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NaN
Source§

fn is_positive(&self) -> bool

Returns true if the number is positive, including +0.0 and INFINITY

Source§

fn is_negative(&self) -> bool

Returns true if the number is negative, including -0.0 and NEG_INFINITY

Source§

impl Signed for i8

Source§

fn abs(&self) -> i8

Source§

fn abs_sub(&self, other: &i8) -> i8

Source§

fn signum(&self) -> i8

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

impl Signed for i16

Source§

fn abs(&self) -> i16

Source§

fn abs_sub(&self, other: &i16) -> i16

Source§

fn signum(&self) -> i16

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

impl Signed for i32

Source§

fn abs(&self) -> i32

Source§

fn abs_sub(&self, other: &i32) -> i32

Source§

fn signum(&self) -> i32

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

impl Signed for i64

Source§

fn abs(&self) -> i64

Source§

fn abs_sub(&self, other: &i64) -> i64

Source§

fn signum(&self) -> i64

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

impl Signed for i128

Source§

fn abs(&self) -> i128

Source§

fn abs_sub(&self, other: &i128) -> i128

Source§

fn signum(&self) -> i128

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

impl Signed for isize

Source§

fn abs(&self) -> isize

Source§

fn abs_sub(&self, other: &isize) -> isize

Source§

fn signum(&self) -> isize

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

impl<T: Signed> Signed for Wrapping<T>
where Wrapping<T>: Num + Neg<Output = Wrapping<T>>,

Source§

fn abs(&self) -> Self

Source§

fn abs_sub(&self, other: &Self) -> Self

Source§

fn signum(&self) -> Self

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Implementors§