Skip to main content

Q15

Struct Q15 

Source
#[repr(transparent)]
pub struct Q15(pub i16);
Expand description

Strongly-typed Q1.15 fixed-point number stored in an i16.

Range is [-1.0, 0.999969482421875]. Provides operator overloading (+, -, *, /) with saturating fixed-point arithmetic.

Tuple Fields§

§0: i16

Implementations§

Source§

impl Q15

Source

pub const ZERO: Self

Zero representation (0.0).

Source

pub const ONE: Self

Maximum positive value (0.999969482... = 32767).

Source

pub const MIN: Self

Minimum representable value (-1.0 = -32768).

Source

pub const MAX: Self

Maximum representable value (0.999969482... = 32767).

Source

pub const DELTA: Self

Smallest positive step (1 / 32768).

Source

pub const fn from_bits(bits: i16) -> Self

Create from raw integer bits.

Source

pub const fn to_bits(self) -> i16

Retrieve raw integer bits.

Source

pub fn from_f32(v: f32) -> Self

Convert from f32 with rounding and saturation to [-1.0, 0.999969].

Source

pub fn to_f32(self) -> f32

Convert to f32.

Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating addition.

Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating subtraction.

Source

pub fn saturating_mul(self, rhs: Self) -> Self

Saturating Q15 multiplication.

Source

pub fn saturating_div(self, rhs: Self) -> Self

Saturating Q15 division with division-by-zero protection.

Source

pub const fn abs(self) -> Self

Absolute value (saturating at Self::MAX for -1.0).

Source

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

Clamp to [min, max].

Trait Implementations§

Source§

impl Add for Q15

Source§

type Output = Q15

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Q15

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Q15

Source§

fn clone(&self) -> Q15

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 Copy for Q15

Source§

impl Debug for Q15

Source§

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

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

impl Default for Q15

Source§

fn default() -> Q15

Returns the “default value” for a type. Read more
Source§

impl Div for Q15

Source§

type Output = Q15

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign for Q15

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl DspSample for Q15

Source§

const ZERO: Self = Self::ZERO

Additive identity (0.0).
Source§

const ONE: Self = Self::ONE

Multiplicative identity or normalized unity (1.0).
Source§

fn sat_add(self, rhs: Self) -> Self

Saturating addition.
Source§

fn sat_sub(self, rhs: Self) -> Self

Saturating subtraction.
Source§

fn sat_mul(self, rhs: Self) -> Self

Saturating multiplication.
Source§

fn sat_div(self, rhs: Self) -> Self

Saturating division.
Source§

fn abs_val(self) -> Self

Absolute value.
Source§

fn to_f32(self) -> f32

Convert to floating-point f32.
Source§

fn from_f32(val: f32) -> Self

Convert from floating-point f32.
Source§

impl Eq for Q15

Source§

impl From<Q15> for i16

Source§

fn from(v: Q15) -> Self

Converts to this type from the input type.
Source§

impl From<Q15> for f32

Source§

fn from(v: Q15) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Q15

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Q15

Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl Hash for Q15

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 for Q15

Source§

type Output = Q15

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign for Q15

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Neg for Q15

Source§

type Output = Q15

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for Q15

Source§

fn cmp(&self, other: &Q15) -> 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§

impl PartialEq for Q15

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Q15

Source§

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

Source§

impl Sub for Q15

Source§

type Output = Q15

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Q15

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl Freeze for Q15

§

impl RefUnwindSafe for Q15

§

impl Send for Q15

§

impl Sync for Q15

§

impl Unpin for Q15

§

impl UnsafeUnpin for Q15

§

impl UnwindSafe for Q15

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