Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Wide

Struct Wide 

Source
pub struct Wide(/* private fields */);
Expand description

A signed 64-bit value, built from native 32-bit multiplies and adds.

See the module documentation for the operations it offers and the ones it leaves out on purpose.

Implementations§

Source§

impl Wide

Source

pub const ZERO: Wide

Zero.

Source

pub const ONE: Wide

One.

Source

pub const MAX: Wide

The largest value, 2^63 - 1.

Source

pub const MIN: Wide

The smallest value, -2^63.

Source

pub const fn of(a: i32) -> Wide

A 32-bit value widened (sign-extending).

Source

pub const fn of_u(a: u32) -> Wide

A 32-bit unsigned value widened (zero-extending).

Source

pub const fn from_parts(hi: i32, lo: u32) -> Wide

The value with signed high word hi and low word lo, the pair a mult leaves in HI:LO.

Source

pub const fn mul(a: i32, b: i32) -> Wide

The full signed product of two words: one mult.

Source

pub const fn mul_add(self, a: i32, b: i32) -> Wide

self + a * b: one mult and a 64-bit add.

Source

pub const fn mul_sub(self, a: i32, b: i32) -> Wide

self - a * b: one mult and a 64-bit subtract.

Source

pub const fn add_w(self, o: Wide) -> Wide

self + o, usable in const fn.

Source

pub const fn sub_w(self, o: Wide) -> Wide

self - o, usable in const fn.

Source

pub const fn mul_w(self, o: Wide) -> Wide

self * o, the low 64 bits of the product (three multiplies).

Source

pub const fn times(self, k: i32) -> Wide

self * k, the low 64 bits of the product.

Source

pub const fn plus(self, k: i32) -> Wide

self + k for a 32-bit k.

Source

pub const fn negate(self) -> Wide

-self, wrapping at Wide::MIN.

Source

pub const fn abs(self) -> Wide

|self|, wrapping at Wide::MIN.

Source

pub const fn unsigned_abs(self) -> WideU

|self| as an unsigned value: exact for every input, Wide::MIN included (2^63).

Source

pub const fn cast_unsigned(self) -> WideU

The same 64 bits read as unsigned, like as u64: a negative value becomes 2^64 - |self|.

Source

pub const fn dot3(a: [i32; 3], b: [i32; 3]) -> Wide

The dot product of two 3-vectors, three mults and two 64-bit adds. With a == b it is the squared length.

Source

pub const fn shl_by(self, n: u32) -> Wide

Arithmetic shift left; the count is taken modulo 64.

Source

pub const fn sar(self, n: u32) -> Wide

Arithmetic shift right (the sign is kept); the count is taken modulo 64.

Source

pub const fn lshr(self, n: u32) -> Wide

Logical shift right of the 64-bit pattern (zeros come in at the top); the count is taken modulo 64.

Source

pub const fn low(self) -> i32

The low 32 bits as i32 (truncating, like as i32).

Source

pub const fn low_u32(self) -> u32

The low 32 bits as u32 (the LO register).

Source

pub const fn high(self) -> i32

The high 32 bits as i32 (the HI register).

Source

pub const fn shr_i32(self, n: u32) -> i32

self >> n (arithmetic, count modulo 64) truncated to its low 32 bits: the fixed-point “multiply, then drop the fraction” step.

Source

pub const fn saturate_i32(self) -> i32

The value clamped into i32.

Source

pub const fn to_i32(self) -> Option<i32>

The value as i32 if it fits.

Source

pub const fn saturate_u32(self) -> u32

The value clamped into u32 (a negative value gives 0).

Source

pub const fn to_u32(self) -> Option<u32>

The value as u32 if it fits.

Source

pub const fn is_negative(self) -> bool

Is the value below zero?

Source

pub const fn is_positive(self) -> bool

Is the value above zero?

Source

pub const fn is_zero(self) -> bool

Is the value zero?

Source

pub const fn cmp_i32(self, k: i32) -> Ordering

Compare with a 32-bit value.

Source

pub const fn isqrt(self) -> u32

floor(sqrt(self)), 0 for a negative value (crate::int32::isqrt_u64).

Source§

impl Wide

Source

pub const fn div_pow2(self, shift: u32) -> Wide

self / 2^shift, truncated toward zero, for shift < 63: the bias and arithmetic shift a compiler emits for i64 / (1 << shift).

Source

pub fn div_i32_wrap(self, d: i32, round: Rounding) -> i32

self / d rounded as asked, as the low 32 bits of the quotient: where the quotient does not fit i32 it wraps, exactly like (n / d) as i32.

Exact for every self and every nonzero d; panics if d is zero.

Source

pub fn div_i32_sat(self, d: i32, round: Rounding) -> i32

self / d rounded as asked and clamped to the i32 range. Panics if d is zero.

Source

pub fn div_wide_sat(self, d: Wide, round: Rounding) -> i32

self / d for a wide divisor, rounded as asked and clamped to the i32 range. Panics if d is zero.

Trait Implementations§

Source§

impl Add for Wide

Source§

type Output = Wide

The resulting type after applying the + operator.
Source§

fn add(self, o: Wide) -> Wide

Performs the + operation. Read more
Source§

impl Clone for Wide

Source§

fn clone(&self) -> Wide

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Wide

Prints the two words, Wide(HI:LO) in hex. (Decimal formatting of 64 bits would pull in a software divide.)

Source§

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

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

impl Default for Wide

Source§

fn default() -> Wide

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

impl Neg for Wide

Source§

type Output = Wide

The resulting type after applying the - operator.
Source§

fn neg(self) -> Wide

Performs the unary - operation. Read more
Source§

impl Ord for Wide

Source§

fn cmp(&self, other: &Wide) -> Ordering

This method returns an [Ordering] between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

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

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Wide

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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 Wide

Source§

fn partial_cmp(&self, other: &Wide) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

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§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

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 Shl<u32> for Wide

Shift left; the count is taken modulo 64.

Source§

type Output = Wide

The resulting type after applying the << operator.
Source§

fn shl(self, n: u32) -> Wide

Performs the << operation. Read more
Source§

impl Shr<u32> for Wide

Arithmetic shift right; the count is taken modulo 64.

Source§

type Output = Wide

The resulting type after applying the >> operator.
Source§

fn shr(self, n: u32) -> Wide

Performs the >> operation. Read more
Source§

impl Sub for Wide

Source§

type Output = Wide

The resulting type after applying the - operator.
Source§

fn sub(self, o: Wide) -> Wide

Performs the - operation. Read more
Source§

impl Copy for Wide

Source§

impl Eq for Wide

Source§

impl StructuralPartialEq for Wide

Auto Trait Implementations§

§

impl Freeze for Wide

§

impl RefUnwindSafe for Wide

§

impl Send for Wide

§

impl Sync for Wide

§

impl Unpin for Wide

§

impl UnsafeUnpin for Wide

§

impl UnwindSafe for Wide

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.