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:
| Type | Maximum 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>
impl<const P: usize, const S: usize> Fixed<P, S>
Sourcepub const MIN: Self
pub const MIN: Self
Smallest value for this type, e.g. -999.99 for Fixed<5,2>.
MIN is always -MAX.
Sourcepub const ONE: Self
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.
Sourcepub fn mantissa(&self) -> i128
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.
Sourcepub fn new(value: i128, scale: i32) -> Option<Self>
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");Sourcepub fn new_round_even(value: i128, scale: i32) -> Option<Self>
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");Sourcepub fn internal_representation(self) -> i128
pub fn internal_representation(self) -> i128
Returns the internal representation of this Fixed value This is an unstable API, use at your own risk!
Sourcepub const fn checked_div_integer(self, other: Self) -> Option<i128>
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.
Sourcepub const fn strict_div_integer(self, other: Self) -> i128
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.
Sourcepub fn checked_rem<const P0: usize, const S0: usize, const P1: usize, const S1: usize>(
self,
other: Fixed<P0, S0>,
) -> Option<Fixed<P1, S1>>
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.
Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Returns the absolute value. This is an exact calculation that cannot overflow.
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if this value is negative, false if it is zero or positive.
Sourcepub fn checked_sqrt(self) -> Option<Self>
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.
Sourcepub fn sqrt(self) -> Self
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.
Sourcepub fn checked_round(&self, n: i32) -> Option<Self>
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.
Sourcepub fn round(&self, n: i32) -> Self
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.
Sourcepub fn checked_round_ties_even(&self, n: i32) -> Option<Self>
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.
Sourcepub fn round_ties_even(&self, n: i32) -> Self
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.
Sourcepub fn checked_floor(&self) -> Option<Self>
pub fn checked_floor(&self) -> Option<Self>
Returns this value rounded down to the nearest integer, or None if
rounding caused overflow.
Sourcepub fn int_floor(&self) -> Fixed<P, 0>
pub fn int_floor(&self) -> Fixed<P, 0>
Returns this value rounded down to the nearest integer, with type Fixed<P, 0>
Sourcepub fn trunc(&self) -> Self
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.
Sourcepub fn trunc_digits(&self, digits: i32) -> Self
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.
Sourcepub fn checked_ceil(&self) -> Option<Self>
pub fn checked_ceil(&self) -> Option<Self>
Returns this value rounded up to the nearest integer, or None if
rounding caused overflow.
Sourcepub fn int_ceil(&self) -> Fixed<P, 0>
pub fn int_ceil(&self) -> Fixed<P, 0>
Returns this value rounded up to the nearest integer, or None if
rounding caused overflow.
Sourcepub fn sign(&self) -> Fixed<1, 0>
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>.
Sourcepub fn checked_recip(&self) -> Option<Self>
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.
Sourcepub fn recip(&self) -> Self
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.
Sourcepub fn checked_powi(&self, exp: i32) -> Option<Self>
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.
Sourcepub fn powi(&self, exp: i32) -> Self
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§impl<const P0: usize, const S0: usize> Fixed<P0, S0>
impl<const P0: usize, const S0: usize> Fixed<P0, S0>
Sourcepub fn convert<const P1: usize, const S1: usize>(&self) -> Option<Fixed<P1, S1>>
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.
Sourcepub fn convert_round_even<const P1: usize, const S1: usize>(
&self,
) -> Option<Fixed<P1, S1>>
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.
Sourcepub fn checked_sign_generic<const P1: usize, const S1: usize>(
&self,
) -> Option<Fixed<P1, S1>>
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).
Sourcepub 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>>
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.
Sourcepub 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>>
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.
Sourcepub 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>>
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.
Sourcepub 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>>
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.
Sourcepub fn strict_add_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>(
self,
other: Fixed<P1, S1>,
) -> Fixed<P2, S2>
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.
Sourcepub fn strict_sub_generic<const P1: usize, const S1: usize, const P2: usize, const S2: usize>(
self,
other: Fixed<P1, S1>,
) -> Fixed<P2, S2>
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§impl<const P: usize, const S: usize> Fixed<P, S>
impl<const P: usize, const S: usize> Fixed<P, S>
Sourcepub const fn max_u128() -> u128
pub const fn max_u128() -> u128
Returns the maximum u128 that can be converted to this type.
The minimum is 0.
Sourcepub const fn max_isize() -> isize
pub const fn max_isize() -> isize
Returns the maximum isize that can be converted to this type.
Sourcepub const fn min_isize() -> isize
pub const fn min_isize() -> isize
Returns the minimum isize that can be converted to this type.
Sourcepub const fn max_usize() -> usize
pub const fn max_usize() -> usize
Returns the maximum usize that can be converted to this type.
The minimum is 0.
Sourcepub const fn max_u64() -> u64
pub const fn max_u64() -> u64
Returns the maximum u64 that can be converted to this type.
The minimum is 0.
Sourcepub const fn max_u32() -> u32
pub const fn max_u32() -> u32
Returns the maximum u32 that can be converted to this type.
The minimum is 0.
Source§impl<const P: usize, const S: usize> Fixed<P, S>
impl<const P: usize, const S: usize> Fixed<P, S>
Sourcepub const UNSIGNED_MIN: u128 = 0
pub const UNSIGNED_MIN: u128 = 0
Value returned by Self::MIN.to_unsigned_encoding().
This is always 0.
Sourcepub const UNSIGNED_ZERO: u128
pub const UNSIGNED_ZERO: u128
Value returned by Self::ZERO.to_unsigned_encoding().
Sourcepub const UNSIGNED_MAX: u128
pub const UNSIGNED_MAX: u128
Value returned by Self::MAX.to_unsigned_encoding().
Sourcepub fn to_unsigned_encoding(self) -> u128
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.
Sourcepub fn from_unsigned_encoding(encoding: u128) -> Option<Self>
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> AddAssign for Fixed<P, S>
impl<const P: usize, const S: usize> AddAssign for Fixed<P, S>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Source§impl<const P: usize, const S: usize> AddAssign<&Fixed<P, S>> for Fixed<P, S>
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>)
fn add_assign(&mut self, other: &Fixed<P, S>)
Source§impl<const P: usize, const S: usize> CheckedAdd for Fixed<P, S>
impl<const P: usize, const S: usize> CheckedAdd for Fixed<P, S>
Source§fn checked_add(&self, other: &Self) -> Option<Self>
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>
impl<const P: usize, const S: usize> CheckedDiv for Fixed<P, S>
Source§fn checked_div(&self, other: &Self) -> Option<Self>
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>
impl<const P: usize, const S: usize> CheckedMul for Fixed<P, S>
Source§fn checked_mul(&self, other: &Self) -> Option<Self>
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>
impl<const P: usize, const S: usize> CheckedSub for Fixed<P, S>
Source§fn checked_sub(&self, other: &Self) -> Option<Self>
fn checked_sub(&self, other: &Self) -> Option<Self>
Returns the difference, which is exact, or None if the result is out
of range.
impl<const P: usize, const S: usize> Copy for Fixed<P, S>
Source§impl<const P: usize, const S: usize> DivAssign for Fixed<P, S>
impl<const P: usize, const S: usize> DivAssign for Fixed<P, S>
Source§fn div_assign(&mut self, other: Self)
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.
impl<const P: usize, const S: usize> Eq for Fixed<P, S>
Source§impl<const P: usize, const S: usize> FromStr for Fixed<P, S>
impl<const P: usize, const S: usize> FromStr for Fixed<P, S>
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
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
type Err = ParseDecimalError
Source§impl<const P: usize, const S: usize> MulAssign for Fixed<P, S>
impl<const P: usize, const S: usize> MulAssign for Fixed<P, S>
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Source§impl<const P: usize, const S: usize> Ord for Fixed<P, S>
impl<const P: usize, const S: usize> Ord for Fixed<P, S>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const P0: usize, const S0: usize, const P1: usize, const S1: usize> PartialEq<Fixed<P1, S1>> for Fixed<P0, S0>
impl<const P0: usize, const S0: usize, const P1: usize, const S1: usize> PartialEq<Fixed<P1, S1>> for Fixed<P0, S0>
Source§impl<const P0: usize, const S0: usize, const P1: usize, const S1: usize> PartialOrd<Fixed<P1, S1>> for Fixed<P0, S0>
impl<const P0: usize, const S0: usize, const P1: usize, const S1: usize> PartialOrd<Fixed<P1, S1>> for Fixed<P0, S0>
Source§impl<const P: usize, const S: usize> SubAssign for Fixed<P, S>
impl<const P: usize, const S: usize> SubAssign for Fixed<P, S>
Source§fn sub_assign(&mut self, other: Self)
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>
impl<const P: usize, const S: usize> TryFrom<DynamicDecimal> for Fixed<P, S>
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
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
type Error = OutOfRange
Source§impl<const P: usize, const S: usize> TryFrom<Fixed<P, S>> for u128
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>
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
type Error = OutOfRange
Source§impl<const P: usize, const S: usize> TryFrom<Fixed<P, S>> for u64
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>
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
type Error = OutOfRange
Source§impl<const P: usize, const S: usize> TryFrom<Fixed<P, S>> for u32
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>
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
type Error = OutOfRange
Source§impl<const P: usize, const S: usize> TryFrom<Fixed<P, S>> for u16
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>
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
type Error = OutOfRange
Source§impl<const P: usize, const S: usize> TryFrom<Fixed<P, S>> for u8
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>
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
type Error = OutOfRange
Source§impl<const P: usize, const S: usize> TryFrom<Fixed<P, S>> for usize
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>
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.