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
Selfcan be positive, it can represent1, - that if
Selfcan be negative, it can represent-1.
If this requirement wasn’t met, the signum function would be logically impossible to implement.
Required Methods§
Sourcefn signumt(self) -> Self
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-signusebin_signum. -
This function is named
signumtand notsignumbecause in the standard-library,f32/f64::signumacts using a2-value-signand not a3-value-sign.
Sourcefn bin_signum(self) -> Self
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-signusesignumt.
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.