Struct Fixed

Source
pub struct Fixed<const P: usize, const S: usize>(/* private fields */);
Expand description

Fixed-point decimal with fixed precision and scale.

Fixed<P, S>, where P in 1..=38 is the “precision” and S in 0..=P is the “scale”, represents a signed decimal number in which S - P digits precede the decimal point and S digits follow it. The table below shows the maximum values for a few combinations of P and S. For each type, the minimum value is the negation of the maximum:

TypeMaximum Value
Fixed<5,5> 0.99999
Fixed<5,4> 9.9999 
Fixed<5,3> 99.999  
Fixed<5,2> 999.99   
Fixed<5,1> 9,999.9    
Fixed<5,0> 99,999      
Fixed<38,0>99,999,999,999,999,999,999,999,999,999,999,999,999      
Fixed<38,5> 999,999,999,999,999,999,999,999,999,999,999.99999

§Implementation

Fixed<P, S> internally contains a single i128 that represents a value x as x * 10**P. This limits S to 38 because 10**38 ≤ 2**127 - 1 < 10**39. A single i64 would be sufficient for S ≤ 18, and a single i32 for S ≤ 9, but the implementation does not optimize for those cases.

Implementations§

Source§

impl<const P: usize, const S: usize> Fixed<P, S>

Source

pub const MAX: Self

Largest value for this type, e.g. 999.99 for Fixed<5,2>.

Source

pub const MIN: Self

Smallest value for this type, e.g. -999.99 for Fixed<5,2>.

MIN is always -MAX.

Source

pub const ZERO: Self

Zero in this type.

Source

pub const ONE: Self

1 in this type.

§Panic

If S == P, this is undefined because 1 is not a value in this type, and referring to it yields a compile-time error.

Source

pub const fn for_i64(value: i64) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every i64 value.

Source

pub const fn for_u64(value: u64) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every u64 value.

Source

pub const fn for_i32(value: i32) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every i32 value.

Source

pub const fn for_u32(value: u32) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every u32 value.

Source

pub const fn for_i16(value: i16) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every i16 value.

Source

pub const fn for_u16(value: u16) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every u16 value.

Source

pub const fn for_i8(value: i8) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every i8 value.

Source

pub const fn for_u8(value: u8) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every u8 value.

Source

pub const fn for_isize(value: isize) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every isize value.

Source

pub const fn for_usize(value: usize) -> Self

Returns value in this type.

§Panic

Panics if this type cannot hold every usize value.

Source

pub const fn checked_div_integer(self, other: Self) -> Option<i128>

Integer division, as defined for divide-integer in General Decimal Arithmetic. Returns None if other is zero or the result is greater than i128::MAX.

Source

pub const fn strict_div_integer(self, other: Self) -> i128

Integer division like checked_div_integer, but panic on error.

§Panic

Panics if other is zero or the result is greater than i128::MAX.

Source

pub const fn checked_rem_integer(self, _other: Self) -> Option<Self>

Remainder, as defined for remainder in General Decimal Arithmetic. Returns None if other is zero.

Source

pub const fn strict_rem_integer(self, other: Self) -> Self

Integer remainder like checked_rem_integer, but panic on error.

§Panic

Panics if other is zero.

Source

pub const fn abs(self) -> Self

Returns the absolute value. This is an exact calculation that cannot overflow.

Source

pub const fn is_negative(self) -> bool

Returns true if this value is negative, false if it is zero or positive.

Source

pub fn checked_sqrt(self) -> Option<Self>

Returns the square root of this value, rounded down, or None if this value is negative.

It probably makes more sense to convert to f64 and take the floating-point square root.

Source

pub fn sqrt(self) -> Self

Returns the square root of this value, rounded down.

It probably makes more sense to convert to f64 and take the floating-point square root.

§Panic

Panics if this value is negative.

Source

pub fn checked_round(&self, n: i32) -> Option<Self>

Returns this value rounded to n digits after the decimal point, or None if rounding caused overflow, n may be negative.

If the value is halfway between two integers, rounds away from zero.

Source

pub fn round(&self, n: i32) -> Self

Rounds to n digits after the decimal point, like checked_round. If the value is halfway between two integers, rounds away from zero.

§Panic

Panics if rounding causes overflow.

Source

pub fn checked_round_ties_even(&self, n: i32) -> Option<Self>

Returns this value rounded to n digits after the decimal point, or None if rounding caused overflow, n may be negative. If the value is halfway between two integers, rounds toward an even least significant digit.

Source

pub fn round_ties_even(&self, n: i32) -> Self

Rounds to n digits after the decimal point, like checked_round_ties_even. If the value is halfway between two integers, rounds toward an even least significant digit.

§Panic

Panics if rounding causes overflow.

Source

pub fn checked_floor(&self) -> Option<Self>

Returns this value rounded down to the nearest integer, or None if rounding caused overflow.

Source

pub fn floor(&self) -> Self

Rounds down to the nearest integer, like checked_floor.

§Panic

Panics if rounding causes overflow.

Source

pub fn truncate(&self) -> Self

Returns the integer part of this value, truncating non-integers toward zero. This is an exact calculation that cannot overflow.

Source

pub fn checked_ceil(&self) -> Option<Self>

Returns this value rounded up to the nearest integer, or None if rounding caused overflow.

Source

pub fn ceil(&self) -> Self

Rounds up to the nearest integer, like checked_ceil.

§Panic

Panics if rounding causes overflow.

Source

pub fn sign(&self) -> Fixed<1, 0>

Returns -1 if this value is less than zero, 0 if this value is zero, and 1 if this value is greater than zero, as Fixed<1,0>.

Source

pub fn checked_recip(&self) -> Option<Self>

Returns the reciprocal (inverse) of this value, 1/x, or None if x is zero or 1/x is out of range.

Source

pub fn recip(&self) -> Self

Returns the reciprocal (inverse) of this value, 1/x. This works even if 1 is out of range for this type, as long as 1/x is in range.

§Panic

Panics if x is zero or 1/x is out of range.

Source

pub fn checked_powi(&self, exp: i32) -> Option<Self>

Returns this value raised to exp power, rounding toward zero, or None if the result is out of range or if this value is 0 and exp is nonpositive.

§Accuracy

For exp > 0, this computes intermediate results with more than S digits of precision, if possible, to allow to better accuracy in the result. For exp < 0, this isn’t implemented yet.

Source

pub fn powi(&self, exp: i32) -> Self

Returns this value raised to exp power, rounding toward zero.

For exp > 0, this computes intermediate results with more than S digits of precision, if possible, to allow to better accuracy in the result. For exp < 0, this isn’t implemented yet.

§Panics

Panics if the result is out of range or if this value is 0 and exp is nonpositive.

Source

pub fn next_up(&self) -> Option<Self>

Returns the least number greater than self, or None if this is Self::MAX.

Source

pub fn next_down(&self) -> Option<Self>

Returns the greatest number less than self, or None if this is Self::MAX.

Source

pub fn encode(&self) -> (i128, u8)

Encodes this value in a form that can be later deserialized into a new Fixed with possibly a different precision and scale.

Source

pub fn decode(value: i128, scale: u8) -> Option<Self>

Returns a new value from the serialized form returned by encode. If successful, returns the original value from before serialization. If S < scale, then some trailing decimals are lost, by rounding toward zero. Returns None if the value is out of range for this type.

Source§

impl<const P0: usize, const S0: usize> Fixed<P0, S0>

Source

pub fn convert<const P1: usize, const S1: usize>(&self) -> Option<Fixed<P1, S1>>

Returns this value converted into another type Fixed<P1, S1>, or None if this value is outside the range of the target type. If the conversion is successful, then the result is exactly the same as the original value if S1 >= S0, and rounded down otherwise.

This should be implemented as TryFrom but that conflicts with the standard library implementation.

Source

pub fn convert_round_even<const P1: usize, const S1: usize>( &self, ) -> Option<Fixed<P1, S1>>

Returns this value converted into another type Fixed<P1, S1>, or None if this value is outside the range of the target type. If the conversion is successful, then the result is exactly the same as the original value if S1 >= S0, and rounded to even otherwise.

Source

pub fn checked_sign_generic<const P1: usize, const S1: usize>( &self, ) -> Option<Fixed<P1, S1>>

Returns -1 if this value is less than zero, 0 if this value is zero, and 1 if this value is greater than zero, in an arbitrary Fixed type. Returns None on overflow (if this value is nonzero and S1 >= P1).

Source

pub fn checked_add_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Option<Fixed<P2, S2>>

Calculates self + other, for operands with scale and precision (S0,P0) and (S1,P1), respectively, producing a result with scale and precision (S2,P2). The result is calculated exactly if possible and otherwise rounded toward zero. Returns None if the result is not representable in the result type.

Source

pub fn checked_sub_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Option<Fixed<P2, S2>>

Calculates self - other, for operands with scale and precision (S0,P0) and (S1,P1), respectively, producing a result with scale and precision (S2,P2). The result is calculated exactly if possible and otherwise rounded toward zero. Returns None if the result is not representable in the result type.

Source

pub fn checked_mul_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Option<Fixed<P2, S2>>

Calculates self * other, for operands with scale and precision (S0,P0) and (S1,P1), respectively, producing a result with scale and precision (S2,P2). The result is calculated exactly if possible and otherwise rounded toward zero. Returns None if the result is not representable in the result type.

Source

pub fn checked_div_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Option<Fixed<P2, S2>>

Calculate self / other, for operands with scale and precision (S0,P0) and (S1,P1), respectively, producing a result with scale and precision (S2,P2). The result is calculated exactly if possible and otherwise rounded toward zero. Returns None if the result is not representable in the result type, or if other is zero.

Source

pub fn strict_add_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Fixed<P2, S2>

Compute self + other, rounding toward zero, panicking if overflow occurs.

Source

pub fn strict_sub_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Fixed<P2, S2>

Compute self - other, rounding toward zero, panicking if overflow occurs.

Source

pub fn strict_mul_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Fixed<P2, S2>

Compute self * other, rounding toward zero, panicking if overflow occurs.

Source

pub fn strict_div_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>( self, other: Fixed<P1, S1>, ) -> Fixed<P2, S2>

Compute self / other, rounding toward zero, panicking if overflow occurs or if other is zero.

Source§

impl<const P: usize, const S: usize> Fixed<P, S>

Source

pub const fn max_i128() -> i128

Returns the maximum i128 that can be converted to this type.

Source

pub const fn min_i128() -> i128

Returns the minimum i128 that can be converted to this type.

Source

pub const fn max_u128() -> u128

Returns the maximum u128 that can be converted to this type.

The minimum is 0.

Source

pub const fn max_isize() -> isize

Returns the maximum isize that can be converted to this type.

Source

pub const fn min_isize() -> isize

Returns the minimum isize that can be converted to this type.

Source

pub const fn max_usize() -> usize

Returns the maximum usize that can be converted to this type.

The minimum is 0.

Source

pub const fn max_i64() -> i64

Returns the maximum i64 that can be converted to this type.

Source

pub const fn min_i64() -> i64

Returns the minimum i64 that can be converted to this type.

Source

pub const fn max_u64() -> u64

Returns the maximum u64 that can be converted to this type.

The minimum is 0.

Source

pub const fn max_i32() -> i32

Returns the maximum i32 that can be converted to this type.

Source

pub const fn min_i32() -> i32

Returns the minimum i32 that can be converted to this type.

Source

pub const fn max_u32() -> u32

Returns the maximum u32 that can be converted to this type.

The minimum is 0.

Source

pub const fn max_i16() -> i16

Returns the maximum i16 that can be converted to this type.

Source

pub const fn min_i16() -> i16

Returns the minimum i16 that can be converted to this type.

Source

pub const fn max_u16() -> u16

Returns the maximum u16 that can be converted to this type.

The minimum is 0.

Source

pub const fn max_i8() -> i8

Returns the maximum i8 that can be converted to this type.

Source

pub const fn min_i8() -> i8

Returns the minimum i8 that can be converted to this type.

Source

pub const fn max_u8() -> u8

Returns the maximum u8 that can be converted to this type.

The minimum is 0.

Trait Implementations§

Source§

impl<const P: usize, const S: usize> Add for &Fixed<P, S>

Source§

fn add(self, other: Self) -> Self::Output

Returns the sum, which is exact if the result is in range.

§Panic

Panics if the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the + operator.
Source§

impl<const P: usize, const S: usize> Add for Fixed<P, S>

Source§

fn add(self, other: Self) -> Self::Output

Returns the sum, rounding toward zero.

§Panic

Panics if the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the + operator.
Source§

impl<const P: usize, const S: usize> AddAssign<&Fixed<P, S>> for Fixed<P, S>

Source§

fn add_assign(&mut self, other: &Fixed<P, S>)

Adds other to self, which is an exact calculation.

§Panic

Panics if the result is out of range.

Source§

impl<const P: usize, const S: usize> AddAssign for Fixed<P, S>

Source§

fn add_assign(&mut self, other: Self)

Adds other to self, which is an exact calculation.

§Panic

Panics if the result is out of range.

Source§

impl<const P: usize, const S: usize> CheckedAdd for Fixed<P, S>

Source§

fn checked_add(&self, other: &Self) -> Option<Self>

Returns the sum, which is exact, or None if the result is out of range.

Source§

impl<const P: usize, const S: usize> CheckedDiv for Fixed<P, S>

Source§

fn checked_div(&self, other: &Self) -> Option<Self>

Returns the quotient, rounding toward zero, or None if other is zero or the result is out of range.

Source§

impl<const P: usize, const S: usize> CheckedMul for Fixed<P, S>

Source§

fn checked_mul(&self, other: &Self) -> Option<Self>

Returns the product, rounding toward zero, or None if the result is out of range.

Source§

impl<const P: usize, const S: usize> CheckedSub for Fixed<P, S>

Source§

fn checked_sub(&self, other: &Self) -> Option<Self>

Returns the difference, which is exact, or None if the result is out of range.

Source§

impl<const P: usize, const S: usize> Clone for Fixed<P, S>

Source§

fn clone(&self) -> Fixed<P, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const P: usize, const S: usize> Debug for Fixed<P, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const P: usize, const S: usize> Default for Fixed<P, S>

Source§

fn default() -> Fixed<P, S>

Returns the “default value” for a type. Read more
Source§

impl<const P: usize, const S: usize> Display for Fixed<P, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const P: usize, const S: usize> Div for &Fixed<P, S>

Source§

fn div(self, other: Self) -> Self::Output

Returns the quotient, rounding toward zero.

§Panic

Panics if other is zero or the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the / operator.
Source§

impl<const P: usize, const S: usize> Div for Fixed<P, S>

Source§

fn div(self, other: Self) -> Self::Output

Returns the quotient, rounding toward zero.

§Panic

Panics if other is zero or the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the / operator.
Source§

impl<const P: usize, const S: usize> DivAssign for Fixed<P, S>

Source§

fn div_assign(&mut self, other: Self)

Divides self by other, rounding toward zero.

§Panic

Panics if other is zero or the result is out of range.

Source§

impl<const P: usize, const S: usize> From<Fixed<P, S>> for f64

Source§

fn from(value: Fixed<P, S>) -> Self

Converts to this type from the input type.
Source§

impl<const P: usize, const S: usize> From<Fixed<P, S>> for i128

Source§

fn from(value: Fixed<P, S>) -> Self

Convert from Fixed to integer, rounding toward zero (the same semantics as Rust casts from float to integer).

Source§

impl<const P: usize, const S: usize> FromStr for Fixed<P, S>

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses s as Fixed.

This accepts the same forms as f64::from_str, except that it rejects infinities and NaNs (which Fixed does not support), as well as out-of-range values. Rounds overprecise values to the nearest representable value, rounding halfway values to even.

Source§

type Err = ParseFixedError

The associated error which can be returned from parsing.
Source§

impl<const P: usize, const S: usize> Hash for Fixed<P, S>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const P: usize, const S: usize> Mul for &Fixed<P, S>

Source§

fn mul(self, other: Self) -> Self::Output

Returns the product, rounding toward zero.

§Panic

Panics if the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the * operator.
Source§

impl<const P: usize, const S: usize> Mul for Fixed<P, S>

Source§

fn mul(self, other: Self) -> Self::Output

Returns the product, rounding toward zero.

§Panic

Panics if the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the * operator.
Source§

impl<const P: usize, const S: usize> MulAssign for Fixed<P, S>

Source§

fn mul_assign(&mut self, other: Self)

Multiplies self by other, rounding toward zero.

§Panic

Panics if the result is out of range.

Source§

impl<const P: usize, const S: usize> Neg for &Fixed<P, S>

Source§

fn neg(self) -> Self::Output

Returns -self. This is an exact calculation that cannot overflow.

Source§

type Output = Fixed<P, S>

The resulting type after applying the - operator.
Source§

impl<const P: usize, const S: usize> Neg for Fixed<P, S>

Source§

fn neg(self) -> Self::Output

Returns -self. This is an exact calculation that cannot overflow.

Source§

type Output = Fixed<P, S>

The resulting type after applying the - operator.
Source§

impl<const P: usize, const S: usize> One for Fixed<P, S>

Source§

fn one() -> Self

This will panic at compile time if 1 isn’t in the range of this type.

Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<const P: usize, const S: usize> Ord for Fixed<P, S>

Source§

fn cmp(&self, other: &Fixed<P, S>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const P0: usize, const S0: usize, const P1: usize, const S1: usize> PartialEq<Fixed<P1, S1>> for Fixed<P0, S0>

Source§

fn eq(&self, other: &Fixed<P1, S1>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<i128> for Fixed<P0, S0>

Source§

fn eq(&self, other: &i128) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<i16> for Fixed<P0, S0>

Source§

fn eq(&self, other: &i16) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<i32> for Fixed<P0, S0>

Source§

fn eq(&self, other: &i32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<i64> for Fixed<P0, S0>

Source§

fn eq(&self, other: &i64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<i8> for Fixed<P0, S0>

Source§

fn eq(&self, other: &i8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<isize> for Fixed<P0, S0>

Source§

fn eq(&self, other: &isize) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<u128> for Fixed<P0, S0>

Source§

fn eq(&self, other: &u128) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<u16> for Fixed<P0, S0>

Source§

fn eq(&self, other: &u16) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<u32> for Fixed<P0, S0>

Source§

fn eq(&self, other: &u32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<u64> for Fixed<P0, S0>

Source§

fn eq(&self, other: &u64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<u8> for Fixed<P0, S0>

Source§

fn eq(&self, other: &u8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize> PartialEq<usize> for Fixed<P0, S0>

Source§

fn eq(&self, other: &usize) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const P0: usize, const S0: usize, const P1: usize, const S1: usize> PartialOrd<Fixed<P1, S1>> for Fixed<P0, S0>

Source§

fn partial_cmp(&self, other: &Fixed<P1, S1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const P: usize, const S: usize> Sub for &Fixed<P, S>

Source§

fn sub(self, other: Self) -> Self::Output

Returns the difference, which is exact if the result is in range.

§Panic

Panics if the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the - operator.
Source§

impl<const P: usize, const S: usize> Sub for Fixed<P, S>

Source§

fn sub(self, other: Self) -> Self::Output

Returns the difference, which is exact if the result is in range.

§Panic

Panics if the result is out of range.

Source§

type Output = Fixed<P, S>

The resulting type after applying the - operator.
Source§

impl<const P: usize, const S: usize> SubAssign for Fixed<P, S>

Source§

fn sub_assign(&mut self, other: Self)

Subtracts other from self, which is an exact calculation.

§Panic

Panics if the result is out of range.

Source§

impl<const P: usize, const S: usize> TryFrom<f64> for Fixed<P, S>

Source§

fn try_from(value: f64) -> Result<Self, Self::Error>

Convert value to Fixed, rounding toward zero, reporting an error if value is out of range.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<i128> for Fixed<P, S>

Source§

fn try_from(value: i128) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<i16> for Fixed<P, S>

Source§

fn try_from(value: i16) -> Result<Self, Self::Error>

Convert value to Fixed, rounding toward zero, reporting an error if value is out of range.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<i32> for Fixed<P, S>

Source§

fn try_from(value: i32) -> Result<Self, Self::Error>

Convert value to Fixed, rounding toward zero, reporting an error if value is out of range.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<i64> for Fixed<P, S>

Source§

fn try_from(value: i64) -> Result<Self, Self::Error>

Convert value to Fixed, rounding toward zero, reporting an error if value is out of range.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<i8> for Fixed<P, S>

Source§

fn try_from(value: i8) -> Result<Self, Self::Error>

Convert value to Fixed, rounding toward zero, reporting an error if value is out of range.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<isize> for Fixed<P, S>

Source§

fn try_from(value: isize) -> Result<Self, Self::Error>

Convert value to Fixed, rounding toward zero, reporting an error if value is out of range.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<u128> for Fixed<P, S>

Source§

fn try_from(value: u128) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<u16> for Fixed<P, S>

Source§

fn try_from(value: u16) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<u32> for Fixed<P, S>

Source§

fn try_from(value: u32) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<u64> for Fixed<P, S>

Source§

fn try_from(value: u64) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<u8> for Fixed<P, S>

Source§

fn try_from(value: u8) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> TryFrom<usize> for Fixed<P, S>

Source§

fn try_from(value: usize) -> Result<Self, Self::Error>

Convert value to Fixed, reporting an error if value is out of range. This is an exact conversion that cannot lose precision if it succeeds.

Source§

type Error = OutOfRange

The type returned in the event of a conversion error.
Source§

impl<const P: usize, const S: usize> Zero for Fixed<P, S>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<const P: usize, const S: usize> Copy for Fixed<P, S>

Source§

impl<const P: usize, const S: usize> Eq for Fixed<P, S>

Auto Trait Implementations§

§

impl<const P: usize, const S: usize> Freeze for Fixed<P, S>

§

impl<const P: usize, const S: usize> RefUnwindSafe for Fixed<P, S>

§

impl<const P: usize, const S: usize> Send for Fixed<P, S>

§

impl<const P: usize, const S: usize> Sync for Fixed<P, S>

§

impl<const P: usize, const S: usize> Unpin for Fixed<P, S>

§

impl<const P: usize, const S: usize> UnwindSafe for Fixed<P, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.