pub struct Fixed16(/* private fields */);Expand description
A signed fixed-point value with $frac_bits bits.
Implementations§
Source§impl Fixed16
A signed fixed-point type.
impl Fixed16
A signed fixed-point type.
Sourcepub const INTEGER_BITS: u8 = 16u8
pub const INTEGER_BITS: u8 = 16u8
The number of integer bits.
Sourcepub const FRACTIONAL_BITS: u8 = 16u8
pub const FRACTIONAL_BITS: u8 = 16u8
The number of fractional bits.
Sourcepub const fn from_bits(n: i32) -> Self
pub const fn from_bits(n: i32) -> Self
Returns the fixed-point value with the same bit-representation as the given value.
pub const fn get(self) -> i32
Sourcepub fn from_f32(n: f32) -> Self
pub fn from_f32(n: f32) -> Self
Converts an f32 floating-point value to fixed point.
This conversion may be lossy, with behavior like standard Rust float-to-int casting.
Extra precision will be truncated, and the result will be saturated if it doesn’t
fit in the underlying type’s range. NaN returns 0.0.
Sourcepub fn from_f64(n: f64) -> Self
pub fn from_f64(n: f64) -> Self
Converts an f64 floating-point value to fixed-point.
This conversion may be lossy, with behavior like standard Rust float-to-int casting.
Extra precision will be truncated, and the result will be saturated if it doesn’t
fit in the underlying type’s range. NaN returns 0.0.
Sourcepub fn to_f32(self) -> f32
pub fn to_f32(self) -> f32
Converts this fixed-point value to f32 floating-point.
This conversion may be lossy if f32 does not have enough precision
to represent the fixed-point value.
Use From to ensure that the conversion is lossless at compile-time.
Sourcepub fn to_f64(self) -> f64
pub fn to_f64(self) -> f64
Converts this fixed-point value to f64 floating-point.
This conversion may be lossy if f64 does not have enough precision
to represent the fixed-point value.
Use From to ensure that the conversion is lossless at compile-time.
Sourcepub fn mul_int(self, other: i32) -> i32
pub fn mul_int(self, other: i32) -> i32
Multiplies this fixed-point by an integer, returning the integer result. The result uses full range of the integer. The fractional bits will be truncated.
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. -Self::MIN is the only case where wrapping occurs.
Sourcepub const fn wrapping_add(self, other: Self) -> Self
pub const fn wrapping_add(self, other: Self) -> Self
Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.
Sourcepub const fn wrapping_sub(self, other: Self) -> Self
pub const fn wrapping_sub(self, other: Self) -> Self
Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.
Sourcepub const fn wrapping_mul(self, other: Self) -> Self
pub const fn wrapping_mul(self, other: Self) -> Self
Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.
Sourcepub const fn wrapping_div(self, other: Self) -> Self
pub const fn wrapping_div(self, other: Self) -> Self
Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.
Sourcepub const fn wrapping_mul_int(self, other: i32) -> i32
pub const fn wrapping_mul_int(self, other: i32) -> i32
Wrapping (modular) multiplication. Multiplies this fixed-point by an integer, returning the integer result. The result will use the full size of the integer. The fractional bits will be truncated.
Trait Implementations§
Source§impl AddAssign for Fixed16
impl AddAssign for Fixed16
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl DivAssign<i32> for Fixed16
impl DivAssign<i32> for Fixed16
Source§fn div_assign(&mut self, other: i32)
fn div_assign(&mut self, other: i32)
/= operation. Read moreSource§impl DivAssign for Fixed16
impl DivAssign for Fixed16
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
/= operation. Read moreSource§impl MulAssign<i32> for Fixed16
impl MulAssign<i32> for Fixed16
Source§fn mul_assign(&mut self, other: i32)
fn mul_assign(&mut self, other: i32)
*= operation. Read moreSource§impl MulAssign for Fixed16
impl MulAssign for Fixed16
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
*= operation. Read moreSource§impl Ord for Fixed16
impl Ord for Fixed16
Source§impl PartialOrd for Fixed16
impl PartialOrd for Fixed16
Source§impl SubAssign for Fixed16
impl SubAssign for Fixed16
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read more