Skip to main content

Fixed

Struct Fixed 

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

Decimal real number 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 fn mantissa(&self) -> i128

Returns the mantissa of this fixed-point decimal number.

The mantissa is the unscaled integer representation of the decimal value. For a decimal number d with a given scale s, the mantissa m satisfies: d = m × 10^(-s), or equivalently, m = d × 10^s.

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 fn new(value: i128, scale: i32) -> Option<Self>

Returns the value that represents value * 10**-scale, rounding toward zero if necessary, or None if the rounded value is out of range for this type.

§Examples

assert_eq!(Fixed::<11, 1>::new(435, 0).unwrap().to_string(), "435");
assert_eq!(Fixed::<11, 1>::new(435, 1).unwrap().to_string(), "43.5");
assert_eq!(Fixed::<11, 1>::new(435, 2).unwrap().to_string(), "4.3");
assert_eq!(Fixed::<11, 1>::new(435, 3).unwrap().to_string(), "0.4");
Source

pub fn new_round_even(value: i128, scale: i32) -> Option<Self>

Returns the value that represents value * 10**-scale, rounding to nearest if necessary, with ties rounded to even, or None if the rounded value is out of range for this type.

§Examples

assert_eq!(Fixed::<11, 1>::new_round_even(435, 0).unwrap().to_string(), "435");
assert_eq!(Fixed::<11, 1>::new_round_even(435, 1).unwrap().to_string(), "43.5");
assert_eq!(Fixed::<11, 1>::new_round_even(435, 2).unwrap().to_string(), "4.4");
assert_eq!(Fixed::<11, 1>::new_round_even(435, 3).unwrap().to_string(), "0.4");
Source

pub fn internal_representation(self) -> i128

Returns the internal representation of this Fixed value This is an unstable API, use at your own risk!

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 fn checked_rem<const P0: usize, const S0: usize, const P1: usize, const S1: usize>( self, other: Fixed<P0, S0>, ) -> Option<Fixed<P1, S1>>

Remainder, as defined for remainder in General Decimal Arithmetic. Returns None 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 int_floor(&self) -> Fixed<P, 0>

Returns this value rounded down to the nearest integer, with type Fixed<P, 0>

Source

pub fn trunc(&self) -> Self

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

trunc() is equivalent to trunc_digits(0), but it might be more efficient due to constant folding.

Source

pub fn trunc_digits(&self, digits: i32) -> Self

Returns this value, truncated toward zero at digits after the decimal point. 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 int_ceil(&self) -> Fixed<P, 0>

Returns this value rounded up to the nearest integer, or None if rounding caused 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§

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.

Source§

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

Source

pub const UNSIGNED_MIN: u128 = 0

Value returned by Self::MIN.to_unsigned_encoding().

This is always 0.

Source

pub const UNSIGNED_ZERO: u128

Value returned by Self::ZERO.to_unsigned_encoding().

Source

pub const UNSIGNED_MAX: u128

Value returned by Self::MAX.to_unsigned_encoding().

Source

pub fn to_unsigned_encoding(self) -> u128

Returns this value converted to a u128 in the range Self::UNSIGNED_MIN to Self::UNSIGNED_MAX (inclusive). The values returned for any given Fixed<P,S> are suitable for equality and order comparison, that is, a.cmp(&b) has the same value as a.to_unsigned_encoding().cmp(&b.to_unsigned_encoding()).

§Usage

This might only be useful in practice for DBSP aggregates, which only only support unsigned integer values. We expose it in case it’s useful for some other purpose.

Source

pub fn from_unsigned_encoding(encoding: u128) -> Option<Self>

Inverts the transformation of to_unsigned_encoding, returning the original Fixed value (assuming P and S are the same as before). Returns None if encoding is invalid (which cannot happen if to_unsigned_encoding returned encoding).

§Usage

This might only be useful in practice for DBSP aggregates, which only only support unsigned integer values. We expose it in case it’s useful for some other purpose.

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, 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> 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> 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> 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> 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) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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

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() -> Self

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> Eq for Fixed<P, S>

Source§

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

Source§

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

Encodes value, for later deserialization into a new Fixed with possibly a different precision and scale.

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 = ParseDecimalError

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: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. 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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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<DynamicDecimal> for Fixed<P, S>

Source§

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

Deserializes DynamicDecimal into Fixed. If successful, returns the original value from before serialization. If S < value.exponent, then some trailing decimals are lost, by rounding toward zero. Returns an error` if the value is out of range for this type.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: Fixed<P, S>) -> Result<Self, Self::Error>

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

Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.

Source§

type Error = OutOfRange

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

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

Source§

fn try_from(value: f32) -> 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<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<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<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<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<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<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<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<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<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.

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> UnsafeUnpin 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V