Skip to main content

Dyadic

Struct Dyadic 

Source
pub struct Dyadic { /* private fields */ }
Expand description

An exact dyadic rational, numerator · 2^-scale.

Implementations§

Source§

impl Dyadic

Source

pub fn zero() -> Dyadic

The value zero.

Source

pub fn one() -> Dyadic

The value one.

Source

pub fn new(n: Int, k: i64) -> Dyadic

Builds n · 2^-k, canonicalizing to an odd numerator (so a positive k scales the value down, matching the n·2⁻ᵏ convention).

Source

pub fn from_int(n: Int) -> Dyadic

Builds the dyadic value of an integer.

Source

pub fn numerator(&self) -> &Int

Returns the (odd, or zero) numerator.

Source

pub fn scale(&self) -> i64

Returns the scale k, so that the value equals numerator · 2^-k. A positive scale is the count of fractional binary digits.

Source

pub fn is_zero(&self) -> bool

Returns true if this value is zero.

Source

pub fn is_integer(&self) -> bool

Returns true if this value is an integer (scale <= 0).

Source

pub fn sign(&self) -> Sign

Returns the sign of this value.

Source

pub fn neg(&self) -> Dyadic

Returns -self.

Source

pub fn abs(&self) -> Dyadic

Returns |self|.

Source

pub fn mul_2k(&self, k: i64) -> Dyadic

Returns self · 2^k (exact; k may be negative).

Source

pub fn add(&self, rhs: &Dyadic) -> Dyadic

Returns self + rhs (exact).

Source

pub fn sub(&self, rhs: &Dyadic) -> Dyadic

Returns self - rhs (exact).

Source

pub fn mul(&self, rhs: &Dyadic) -> Dyadic

Returns self · rhs (exact).

Source

pub fn pow(&self, exp: u32) -> Dyadic

Returns self raised to exp (exact).

Source

pub fn floor(&self) -> Int

Returns the greatest integer <= self.

Source

pub fn trunc(&self) -> Int

Returns self truncated toward zero as an integer.

Source§

impl Dyadic

Source

pub fn to_rational(&self) -> Rational

Returns the exact value as a Rational.

Source

pub fn try_from_rational(r: &Rational) -> Option<Dyadic>

Converts a Rational to a Dyadic, or None if its denominator is not a power of two.

Source§

impl Dyadic

Source

pub fn to_float(&self, precision: u64, mode: RoundingMode) -> Float

Rounds this value to a Float at precision bits.

Source

pub fn from_float(f: &Float) -> Option<Dyadic>

Converts a finite Float to an exact Dyadic, or None for NaN / ±∞ (finite floats are always exactly dyadic).

Trait Implementations§

Source§

impl Add for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<&Dyadic> for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dyadic) -> Dyadic

Performs the + operation. Read more
Source§

impl AddAssign for Dyadic

Source§

fn add_assign(&mut self, rhs: Dyadic)

Performs the += operation. Read more
Source§

impl Clone for Dyadic

Source§

fn clone(&self) -> Dyadic

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

Source§

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

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

impl Default for Dyadic

Source§

fn default() -> Dyadic

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

impl Display for Dyadic

Source§

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

Prints the exact (terminating) decimal expansion.

Source§

impl Eq for Dyadic

Source§

impl From<Int> for Dyadic

Source§

fn from(n: Int) -> Dyadic

Converts to this type from the input type.
Source§

impl From<i64> for Dyadic

Source§

fn from(v: i64) -> Dyadic

Converts to this type from the input type.
Source§

impl FromStr for Dyadic

Source§

fn from_str(s: &str) -> Result<Dyadic>

Parses a decimal ("3", "-1.5", "0.25"); returns Error::Parse if the value is not dyadic (its reduced denominator is not a power of two).

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

impl Hash for Dyadic

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 Dyadic

Source§

type Output = Dyadic

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<&Dyadic> for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dyadic) -> Dyadic

Performs the * operation. Read more
Source§

impl MulAssign for Dyadic

Source§

fn mul_assign(&mut self, rhs: Dyadic)

Performs the *= operation. Read more
Source§

impl Neg for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

fn neg(self) -> Dyadic

Performs the unary - operation. Read more
Source§

impl Ord for Dyadic

Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Dyadic

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 (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 Ring for Dyadic

Available on crate feature dyadic only.
Source§

fn zero(&self) -> Self

The additive identity of the same ring as self (same modulus/field).
Source§

fn one(&self) -> Self

The multiplicative identity of the same ring as self.
Source§

fn is_zero(&self) -> bool

Whether self is the additive identity.
Source§

const REASSOCIATIVE: bool = false

Whether this ring’s +//× are exact and associative, so that a re-associating fast matrix multiply (Strassen–Winograd, which forms products of sums of blocks and recombines them in a different order) is bit-identical to the naive triple loop. Read more
Source§

const EXACT: bool = false

Whether this ring’s arithmetic is exact (no rounding), so that an algebraic algorithm whose mathematical result is unique — fast polynomial division (Newton) and the Half-GCD — is bit-identical to the schoolbook/Euclid reference it replaces. Read more
Source§

fn poly_mul(_a: &[Self], _b: &[Self]) -> Option<Vec<Self>>

Optional fast dense-polynomial multiply hook, keyed on the coefficient type, letting Poly::mul route to a specialized algorithm that Rust’s coherence rules forbid expressing as a Poly<T> override. The inputs are the two operands’ coefficient slices (low-to-high, each trimmed with a nonzero leading term); the return value is the product coefficient vector (low-to-high). Returning None — the default — falls back to the generic Karatsuba/schoolbook path. Read more
Source§

fn multiply_cost_hint(&self) -> u64

A cheap proxy for the cost of multiplying two ring elements of roughly self’s magnitude — for the arbitrary-precision integers/rationals, the operand’s bit length. Read more
Source§

impl StructuralPartialEq for Dyadic

Source§

impl Sub for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<&Dyadic> for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dyadic) -> Dyadic

Performs the - operation. Read more
Source§

impl SubAssign for Dyadic

Source§

fn sub_assign(&mut self, rhs: Dyadic)

Performs the -= operation. Read more

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.