[go: up one dir, main page]

Struct Fp32

Source
pub struct Fp32<F = _16> { /* private fields */ }
Expand description

A 32 fixed point number. The size of the fractional is defined by the type parameter F.

Implementations§

Source§

impl<F: FractionalBits> Fp32<F>

Source

pub fn raw(self) -> i32

Returns the internal representation.

This internal represenataion can be used for computations to avoid bit-shifting between each operation. The number of divisions should be equal to the number of multiplications performed in order to balance out the bit shifts that were skipped.

Source

pub fn from_raw(bits: i32) -> Self

Source

pub fn zero() -> Self

Source

pub fn is_zero(self) -> bool

Source

pub fn epsilon() -> Self

Smallest increment that can be reresented with this type.

Source

pub fn from_f32(val: f32) -> Self

Converts from a 32 bits floating point value.

Source

pub fn to_f32(self) -> f32

Converts to a 32 bits floating point value.

Source

pub fn from_f64(val: f64) -> Self

Converts from a 64 bits floating point value.

Source

pub fn to_f64(self) -> f64

Converts to a 64 bits floating point value.

Source

pub fn sign(self) -> i32

Returns 1 if the number of positive, -1 if it is negative.

Source

pub fn rem(self, other: Self) -> Self

Returns the result of self % other.

Source

pub fn min(self, other: Self) -> Self

Returns the lowest of the two values.

Source

pub fn max(self, other: Self) -> Self

Returns the highest of the two values.

Source

pub fn min_max(self, other: Self) -> (Self, Self)

Returns the lowest and highest of the two values in order.

Source

pub fn abs(self) -> Self

Returns the absolute value of this number.

Source

pub fn to_fixed<NewF: FractionalBits>(self) -> Fp32<NewF>

Returns the same number with a different fractional precision.

Source§

impl<F: FractionalBits> Fp32<F>

Source

pub fn one() -> Self

Source

pub fn from_i32(val: i32) -> Self

Source

pub fn truncate_to_i32(self) -> i32

Convert to an i32, truncating the fractional part

Source

pub fn mul_div(self, m: Self, d: Self) -> Self

Computes the self * m / d in one go, avoid the precision loss from shifting bits back and forth.

Source

pub fn min_val() -> Self

Source

pub fn max_val() -> Self

Source

pub fn to_fp64<NewF: FractionalBits>(self) -> Fp64<NewF>

Casts into a 64 bits fixed point number.

Trait Implementations§

Source§

impl<F: FractionalBits> Add for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F: FractionalBits> AddAssign for Fp32<F>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<F> Clone for Fp32<F>

Source§

fn clone(&self) -> Self

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<F: FractionalBits> Debug for Fp32<F>

Source§

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

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

impl<F: FractionalBits> Display for Fp32<F>

Source§

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

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

impl<F: FractionalBits> Div<i32> for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<F: FractionalBits> Div for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<F: FractionalBits> From<f32> for Fp32<F>

Source§

fn from(val: f32) -> Self

Converts to this type from the input type.
Source§

impl<F: FractionalBits> From<f64> for Fp32<F>

Source§

fn from(val: f64) -> Self

Converts to this type from the input type.
Source§

impl<F> Hash for Fp32<F>

Source§

fn hash<H: Hasher>(&self, h: &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<F: FractionalBits> Into<f32> for Fp32<F>

Source§

fn into(self) -> f32

Converts this type into the (usually inferred) input type.
Source§

impl<F: FractionalBits> Into<f64> for Fp32<F>

Source§

fn into(self) -> f64

Converts this type into the (usually inferred) input type.
Source§

impl<F: FractionalBits> Mul<i32> for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F: FractionalBits> Mul for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F: FractionalBits> Neg for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<F: FractionalBits> Ord for Fp32<F>

Source§

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

Source§

fn eq(&self, other: &Self) -> 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<F: FractionalBits> PartialOrd for Fp32<F>

Source§

fn partial_cmp(&self, other: &Self) -> 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<F: FractionalBits> Sub for Fp32<F>

Source§

type Output = Fp32<F>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<F: FractionalBits> SubAssign for Fp32<F>

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl<F> Copy for Fp32<F>

Source§

impl<F> Eq for Fp32<F>

Auto Trait Implementations§

§

impl<F> Freeze for Fp32<F>

§

impl<F> RefUnwindSafe for Fp32<F>
where F: RefUnwindSafe,

§

impl<F> Send for Fp32<F>
where F: Send,

§

impl<F> Sync for Fp32<F>
where F: Sync,

§

impl<F> Unpin for Fp32<F>
where F: Unpin,

§

impl<F> UnwindSafe for Fp32<F>
where F: UnwindSafe,

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.