Skip to main content

Signum

Trait Signum 

Source
pub trait Signum: Signed {
    // Required methods
    fn signumt(self) -> Self;
    fn bin_signum(self) -> Self;
}
Expand description

Trait for signum functions.

This logically requires:

  • that if Self can be positive, it can represent 1,
  • that if Self can be negative, it can represent -1.

If this requirement wasn’t met, the signum function would be logically impossible to implement.

Required Methods§

Source

fn signumt(self) -> Self

Returns either 1, -1 or 0 based on the number’s 3-value-sign:

  • self > 0 => 1,
  • self < 0 => -1,
  • self == 0 => 0.

A 3-value-sign can be either positive, negative or zero, In comparison to a 2-value-sign / binary-sign which can be either positive or negative, and cannot be zero.

  • For a 2-value-sign use bin_signum.

  • This function is named signumt and not signum because in the standard-library, f32/f64::signum acts using a 2-value-sign and not a 3-value-sign.

Source

fn bin_signum(self) -> Self

Returns either 1 or -1 based on the number’s 2-value-sign:

  • self > 0 => 1,
  • self < 0 => -1,
  • self == +0 => 1,
  • self == -0 => -1.

A 2-value-sign can be either positive or negative, and cannot be zero. This means that for self = +0, 1 is returned, and for self = -0, -1 is returned. For types that cannot distinguish between +0 and -0, 0 is treated as positive.

  • For a 3-value-sign use signumt.

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 Signum for f32

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for f64

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for i8

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for i16

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for i32

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for i64

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for i128

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for isize

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for u8

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for u16

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for u32

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for u64

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for u128

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Source§

impl Signum for usize

Source§

fn signumt(self) -> Self

Source§

fn bin_signum(self) -> Self

Implementors§