Fixed16

Struct Fixed16 

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

Source

pub const INTEGER_BITS: u8 = 16u8

The number of integer bits.

Source

pub const FRACTIONAL_BITS: u8 = 16u8

The number of fractional bits.

Source

pub const ZERO: Self

The fixed-point value representing 0.0.

Source

pub const ONE: Self

The fixed-point value representing 1.0.

Source

pub const MIN: Self

The minimum representable value of this type.

Source

pub const MAX: Self

The maximum representable value of this type.

Source

pub const fn from_bits(n: i32) -> Self

Returns the fixed-point value with the same bit-representation as the given value.

Source

pub const fn get(self) -> i32

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn is_zero(self) -> bool

Returns true if this is equal to 0.0.

Source

pub const fn is_one(self) -> bool

Returns true if this is equal to 1.0.

Source

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.

Source

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.

Source

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

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

Source

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

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

Source

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

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

Source

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

Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.

Source

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 Add for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Fixed16

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Fixed16

Source§

fn clone(&self) -> Fixed16

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 Debug for Fixed16

Source§

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

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

impl Default for Fixed16

Source§

fn default() -> Self

Returns the default value of 0.0.

Source§

impl Display for Fixed16

Source§

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

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

impl Div<i32> for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign<i32> for Fixed16

Source§

fn div_assign(&mut self, other: i32)

Performs the /= operation. Read more
Source§

impl DivAssign for Fixed16

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl From<Fixed16> for f64

Source§

fn from(n: Fixed16) -> f64

Converts to this type from the input type.
Source§

impl From<i16> for Fixed16

Source§

fn from(n: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Fixed16

Source§

fn from(n: i8) -> Self

Converts to this type from the input type.
Source§

impl Hash for Fixed16

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 Mul<Fixed16> for i32

Source§

type Output = Fixed16

The resulting type after applying the * operator.
Source§

fn mul(self, other: Fixed16) -> Fixed16

Performs the * operation. Read more
Source§

impl Mul<i32> for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<i32> for Fixed16

Source§

fn mul_assign(&mut self, other: i32)

Performs the *= operation. Read more
Source§

impl MulAssign for Fixed16

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl Neg for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for Fixed16

Source§

fn cmp(&self, other: &Fixed16) -> 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 PartialEq for Fixed16

Source§

fn eq(&self, other: &Fixed16) -> 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 PartialOrd for Fixed16

Source§

fn partial_cmp(&self, other: &Fixed16) -> 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 Sub for Fixed16

Source§

type Output = Fixed16

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Fixed16

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl Copy for Fixed16

Source§

impl Eq for Fixed16

Source§

impl StructuralPartialEq for Fixed16

Auto Trait Implementations§

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.