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

WideU

Struct WideU 

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

An unsigned 64-bit value: a u32 * u32 product needs all 64 bits.

Same rules as Wide: native operations only; division is in crate::wide_div.

Implementations§

Source§

impl WideU

Source

pub const ZERO: WideU

Zero.

Source

pub const MAX: WideU

The largest value, 2^64 - 1.

Source

pub const fn of(a: u32) -> WideU

A 32-bit value widened.

Source

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

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

Source

pub const fn mul(a: u32, b: u32) -> WideU

The full unsigned product of two words: one multu.

Source

pub const fn mul_add(self, a: u32, b: u32) -> WideU

self + a * b: one multu and a 64-bit add (wrapping).

Source

pub const fn add(self, o: WideU) -> WideU

self + o, wrapping.

Source

pub const fn sub(self, o: WideU) -> WideU

self - o, wrapping.

Source

pub const fn saturating_add(self, o: WideU) -> WideU

self + o, stopping at WideU::MAX.

Source

pub const fn times(self, k: u32) -> WideU

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

Source

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

Shift left; the count is taken modulo 64.

Source

pub const fn shr_by(self, n: u32) -> WideU

Shift right (zeros come in at the top); the count is taken modulo 64.

Source

pub const fn low(self) -> u32

The low 32 bits (the LO register).

Source

pub const fn high(self) -> u32

The high 32 bits (the HI register).

Source

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

self >> n (count modulo 64) truncated to its low 32 bits.

Source

pub const fn saturate_u32(self) -> u32

The value clamped into u32.

Source

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

The value as u32 if it fits.

Source

pub const fn cast_signed(self) -> Wide

The same 64 bits read as signed, like as i64: a value from 2^63 up becomes negative.

Source

pub const fn is_zero(self) -> bool

Is the value zero?

Source

pub const fn isqrt(self) -> u32

floor(sqrt(self)) (crate::int32::isqrt_u64).

Source§

impl WideU

Source

pub fn div_rem_u32(self, d: u32) -> (WideU, u32)

(self / d, self % d): the exact 64-bit quotient and the remainder.

A numerator below 2^32 is one divu. Panics if d is zero.

Source

pub fn quotient(self, d: WideU) -> u32

floor(self / d), clamped to u32::MAX when the true quotient is larger. Exact: no estimate survives to the result. Panics if d is zero.

A divisor wider than 32 bits makes the quotient fit u32 by itself; the clamp only matters for a divisor that fits 32 bits.

Source

pub fn mul_full(self, o: WideU) -> (WideU, WideU)

The exact 128-bit product of two values, as (bits 64..128, bits 0..64).

Source

pub fn cmp_ratio(a: WideU, b: WideU, c: WideU, d: WideU) -> Ordering

Orders a / b against c / d without dividing: a * d against c * b, each an exact 128-bit product. b and d must be nonzero.

Source

pub fn scale_by_ratio(self, a: u32, den: WideU) -> u32

floor(a * self / den) for self <= den (a fraction of at most one), so the result is at most a. Exact. Panics if den is zero or self > den.

Trait Implementations§

Source§

impl Add for WideU

Source§

type Output = WideU

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for WideU

Source§

fn clone(&self) -> WideU

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 WideU

Prints the two words, WideU(HI:LO) in hex.

Source§

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

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

impl Default for WideU

Source§

fn default() -> WideU

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

impl Ord for WideU

Source§

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

Source§

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

Source§

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

Shift left; the count is taken modulo 64.

Source§

type Output = WideU

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

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

Performs the << operation. Read more
Source§

impl Shr<u32> for WideU

Shift right (logical); the count is taken modulo 64.

Source§

type Output = WideU

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

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

Performs the >> operation. Read more
Source§

impl Sub for WideU

Source§

type Output = WideU

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for WideU

Source§

impl Eq for WideU

Source§

impl StructuralPartialEq for WideU

Auto Trait Implementations§

§

impl Freeze for WideU

§

impl RefUnwindSafe for WideU

§

impl Send for WideU

§

impl Sync for WideU

§

impl Unpin for WideU

§

impl UnsafeUnpin for WideU

§

impl UnwindSafe for WideU

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.