pub trait FixedSigned: Fixed + Neg<Output = Self> {
// Required methods
fn is_positive(self) -> bool;
fn is_negative(self) -> bool;
fn abs(self) -> Self;
fn signum(self) -> Self;
fn checked_abs(self) -> Option<Self>;
fn saturating_abs(self) -> Self;
fn wrapping_abs(self) -> Self;
fn overflowing_abs(self) -> (Self, bool);
}
Expand description
This trait provides methods common to all signed fixed-point numbers.
Methods common to all fixed-point numbers including unsigned
fixed-point numbers are provided by the Fixed
supertrait.
This trait is sealed and cannot be implemented for more types; it
is implemented for FixedI8
, FixedI16
, FixedI32
,
FixedI64
, and FixedI128
.
Required Methods§
Sourcefn is_positive(self) -> bool
fn is_positive(self) -> bool
Returns true
if the number is > 0.
Sourcefn is_negative(self) -> bool
fn is_negative(self) -> bool
Returns true
if the number is < 0.
Sourcefn signum(self) -> Self
fn signum(self) -> Self
Returns a number representing the sign of self
.
§Panics
When debug assertions are enabled, this method panics
- if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
- if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.
When debug assertions are not enabled, the wrapped value can be returned in those cases, but it is not considered a breaking change if in the future it panics; using this method when 1 and −1 cannot be represented is almost certainly a bug.
Sourcefn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
Checked absolute value. Returns the absolute value, or None
on overflow.
Overflow can only occur when trying to find the absolute value of the minimum value.
Sourcefn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
Saturating absolute value. Returns the absolute value, saturating on overflow.
Overflow can only occur when trying to find the absolute value of the minimum value.
Sourcefn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
Wrapping absolute value. Returns the absolute value, wrapping on overflow.
Overflow can only occur when trying to find the absolute value of the minimum value.
Sourcefn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
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.