Trait fixed::traits::FixedSigned
source · pub trait FixedSigned: Fixedwhere
Self: Neg<Output = Self>,{
const TRY_NEG_ONE: Option<Self>;
Show 29 methods
// Required methods
fn signed_bits(self) -> u32;
fn is_positive(self) -> bool;
fn is_negative(self) -> bool;
fn abs(self) -> Self;
fn unsigned_abs(self) -> Self::Unsigned;
fn unsigned_dist(self, other: Self) -> Self::Unsigned;
fn signum(self) -> Self;
fn add_unsigned(self, rhs: Self::Unsigned) -> Self;
fn sub_unsigned(self, rhs: Self::Unsigned) -> Self;
fn checked_abs(self) -> Option<Self>;
fn checked_signum(self) -> Option<Self>;
fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
fn saturating_abs(self) -> Self;
fn saturating_signum(self) -> Self;
fn saturating_add_unsigned(self, rhs: Self::Unsigned) -> Self;
fn saturating_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
fn wrapping_abs(self) -> Self;
fn wrapping_signum(self) -> Self;
fn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self;
fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
fn unwrapped_abs(self) -> Self;
fn unwrapped_signum(self) -> Self;
fn unwrapped_add_unsigned(self, rhs: Self::Unsigned) -> Self;
fn unwrapped_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
fn overflowing_abs(self) -> (Self, bool);
fn overflowing_signum(self) -> (Self, bool);
fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);
fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (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 Associated Constants§
sourceconst TRY_NEG_ONE: Option<Self>
const TRY_NEG_ONE: Option<Self>
Negative one if the fixed-point number can represent it, otherwise
None
.
Required Methods§
sourcefn signed_bits(self) -> u32
fn signed_bits(self) -> u32
Returns the number of bits required to represent the value.
See also FixedI32::signed_bits
.
sourcefn is_positive(self) -> bool
fn is_positive(self) -> bool
Returns true
if the number is > 0.
See also FixedI32::is_positive
.
sourcefn is_negative(self) -> bool
fn is_negative(self) -> bool
Returns true
if the number is < 0.
See also FixedI32::is_negative
.
sourcefn unsigned_abs(self) -> Self::Unsigned
fn unsigned_abs(self) -> Self::Unsigned
Returns the absolute value using an unsigned type without any wrapping or panicking.
See also FixedI32::unsigned_abs
.
sourcefn unsigned_dist(self, other: Self) -> Self::Unsigned
fn unsigned_dist(self, other: Self) -> Self::Unsigned
Returns the distance from self
to other
using an unsigned type
without any wrapping or panicking.
See also
FixedI32::unsigned_dist
.
sourcefn signum(self) -> Self
fn signum(self) -> Self
Returns a number representing the sign of self
.
See also FixedI32::signum
.
§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 add_unsigned(self, rhs: Self::Unsigned) -> Self
fn add_unsigned(self, rhs: Self::Unsigned) -> Self
Addition with an unsigned fixed-point number.
See also FixedI32::add_unsigned
.
sourcefn sub_unsigned(self, rhs: Self::Unsigned) -> Self
fn sub_unsigned(self, rhs: Self::Unsigned) -> Self
Subtraction with an unsigned fixed-point number.
See also FixedI32::sub_unsigned
.
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.
See also FixedI32::checked_abs
.
sourcefn checked_signum(self) -> Option<Self>
fn checked_signum(self) -> Option<Self>
Checked signum. Returns a number representing the sign of
self
, or None
on overflow.
Overflow can only occur
- 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.
See also
FixedI32::checked_signum
.
sourcefn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>
fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>
Checked addition with an unsigned fixed-point number. Returns the sum,
or None
on overflow.
See also
FixedI32::checked_add_unsigned
.
sourcefn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>
fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>
Checked subtraction with an unsigned fixed-point number. Returns the
difference, or None
on overflow.
See also FixedI32::checked_sub_unsigned
.
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.
See also
FixedI32::saturating_abs
.
sourcefn saturating_signum(self) -> Self
fn saturating_signum(self) -> Self
Saturating signum. Returns a number representing the sign of
self
, saturating on overflow.
Overflow can only occur
- 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.
See also
FixedI32::saturating_signum
.
sourcefn saturating_add_unsigned(self, rhs: Self::Unsigned) -> Self
fn saturating_add_unsigned(self, rhs: Self::Unsigned) -> Self
Saturating addition with an unsigned fixed-point number. Returns the sum, saturating on overflow.
See also
FixedI32::saturating_add_unsigned
.
sourcefn saturating_sub_unsigned(self, rhs: Self::Unsigned) -> Self
fn saturating_sub_unsigned(self, rhs: Self::Unsigned) -> Self
Saturating subtraction with an unsigned fixed-point number. Returns the difference, saturating on overflow.
See also
FixedI32::saturating_sub_unsigned
.
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.
See also FixedI32::wrapping_abs
.
sourcefn wrapping_signum(self) -> Self
fn wrapping_signum(self) -> Self
Wrapping signum. Returns a number representing the sign of
self
, wrapping on overflow.
Overflow can only occur
- 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.
See also
FixedI32::wrapping_signum
.
sourcefn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self
fn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self
Wrapping addition with an unsigned fixed-point number. Returns the sum, wrapping on overflow.
See also
FixedI32::wrapping_add_unsigned
.
sourcefn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self
fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self
Wrapping subtraction with an unsigned fixed-point number. Returns the difference, wrapping on overflow.
See also
FixedI32::wrapping_sub_unsigned
.
sourcefn unwrapped_abs(self) -> Self
fn unwrapped_abs(self) -> Self
Unwrapped absolute value. Returns the absolute value, panicking on overflow.
Overflow can only occur when trying to find the absolute value of the minimum value.
See also
FixedI32::unwrapped_abs
.
§Panics
Panics if the result does not fit.
sourcefn unwrapped_signum(self) -> Self
fn unwrapped_signum(self) -> Self
Unwrapped signum. Returns a number representing the sign of
self
, panicking on overflow.
Overflow can only occur
- 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.
See also
FixedI32::unwrapped_signum
.
§Panics
Panics if the result does not fit.
sourcefn unwrapped_add_unsigned(self, rhs: Self::Unsigned) -> Self
fn unwrapped_add_unsigned(self, rhs: Self::Unsigned) -> Self
Unwrapped addition with an unsigned fixed-point number. Returns the sum, panicking on overflow.
See also
FixedI32::unwrapped_add_unsigned
.
§Panics
Panics if the result does not fit.
sourcefn unwrapped_sub_unsigned(self, rhs: Self::Unsigned) -> Self
fn unwrapped_sub_unsigned(self, rhs: Self::Unsigned) -> Self
Unwrapped subtraction with an unsigned fixed-point number. Returns the difference, panicking on overflow.
See also
FixedI32::unwrapped_sub_unsigned
.
§Panics
Panics if the result does not fit.
sourcefn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
Overflowing absolute value.
Returns a tuple of the fixed-point number and a bool
,
indicating whether an overflow has occurred. On overflow, the
wrapped value is returned.
See also
FixedI32::overflowing_abs
.
sourcefn overflowing_signum(self) -> (Self, bool)
fn overflowing_signum(self) -> (Self, bool)
Overflowing signum.
Returns a tuple of the signum and a bool
, indicating
whether an overflow has occurred. On overflow, the wrapped
value is returned.
Overflow can only occur
- 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.
See also
FixedI32::overflowing_signum
.
sourcefn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool)
fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool)
Overflowing addition with an unsigned fixed-point number.
Returns a tuple of the sum and a bool
, indicating whether an
overflow has occurred. On overflow, the wrapped value is returned.
See also
FixedI32::overflowing_add_unsigned
.
sourcefn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool)
fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool)
Overflowing subtraction with an unsigned fixed-point number.
Returns a tuple of the difference and a bool
, indicating whether
an overflow has occurred. On overflow, the wrapped value is returned.
See also
FixedI32::overflowing_sub_unsigned
.