Skip to main content

Df64

Struct Df64 

Source
pub struct Df64 {
    pub hi: f64,
    pub lo: f64,
}
Expand description

A real scalar carrying a high and a low f64 component.

hi holds the rounded value and lo the exact residual, so hi + lo is the represented real number.

§Examples

use tenferro_df64_proof::Df64;

let carried = Df64 { hi: 1.0, lo: 2f64.powi(-80) };
assert_eq!(carried.narrow_to_f64(), 1.0);
assert_ne!(carried, Df64::from_f64(1.0));

Fields§

§hi: f64

Rounded component.

§lo: f64

Exact residual component.

Implementations§

Source§

impl Df64

Source

pub fn from_f64(value: f64) -> Self

Build a scalar with no low component.

§Examples
use tenferro_df64_proof::Df64;

assert_eq!(Df64::from_f64(1.5), Df64 { hi: 1.5, lo: 0.0 });
Source

pub fn zero() -> Self

Additive identity.

§Examples
use tenferro_df64_proof::Df64;

assert_eq!(Df64::zero(), Df64 { hi: 0.0, lo: 0.0 });
Source

pub fn narrow_to_f64(self) -> f64

Explicitly narrow to f64, discarding the low component.

This is a numerical conversion, not a reinterpretation: it allocates nothing and reads only the rounded component.

§Examples
use tenferro_df64_proof::Df64;

// The low component is deliberately dropped, and is not recovered.
assert_eq!(Df64 { hi: 1.0, lo: 2f64.powi(-80) }.narrow_to_f64(), 1.0);
Source

pub fn ratio(self, divisor: Self) -> Self

Quotient, refined to the full two-component precision.

The first component of the result is the ordinary f64 quotient and the remaining error is recovered by two Newton corrections evaluated in the two-component arithmetic, so the quotient carries both components.

§Examples
use tenferro_df64_proof::Df64;

// One divided by three is not a binary fraction, and the low component holds
// the part an `f64` quotient cannot.
let third = Df64::from_f64(1.0).ratio(Df64::from_f64(3.0));
assert_eq!(third.hi, 1.0 / 3.0);
assert_ne!(third.lo, 0.0);
assert!((third * Df64::from_f64(3.0) - Df64::from_f64(1.0)).abs_hi() < 1e-31);
Source

pub fn sqrt(self) -> Self

Square root, refined to the full two-component precision.

A negative operand follows IEEE: the result is NaN with a zero low component.

§Examples
use tenferro_df64_proof::Df64;

let root = Df64::from_f64(2.0).sqrt();
assert_eq!(root.hi, 2.0_f64.sqrt());
// Squaring recovers two to a precision an `f64` root cannot reach.
assert!((root * root - Df64::from_f64(2.0)).abs_hi() < 1e-31);
assert!(Df64::from_f64(-1.0).sqrt().hi.is_nan());
Source

pub fn abs_hi(self) -> f64

Absolute value of the rounded component.

This is the scale a convergence test uses; it does not widen the represented value.

§Examples
use tenferro_df64_proof::Df64;

assert_eq!(Df64 { hi: -2.0, lo: 1.0 }.abs_hi(), 2.0);

Trait Implementations§

Source§

impl Add for Df64

Source§

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

Exact addition of two expansions.

Source§

type Output = Df64

The resulting type after applying the + operator.
Source§

impl BinaryScalarOp<Df64> for Df64Add

Source§

fn apply(lhs: Df64, rhs: Df64) -> Df64

Apply the operation. Read more
Source§

impl Clone for Df64

Source§

fn clone(&self) -> Df64

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 Df64

Source§

impl Debug for Df64

Source§

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

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

impl Default for Df64

Source§

fn default() -> Df64

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

impl Div for Df64

Source§

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

Two-component quotient, refined to both components.

Source§

type Output = Df64

The resulting type after applying the / operator.
Source§

impl Mul for Df64

Source§

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

Two-component product: the exact leading product plus the first-order corrections, which is what the contract’s arithmetic promises.

Source§

type Output = Df64

The resulting type after applying the * operator.
Source§

impl Neg for Df64

Source§

type Output = Df64

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Df64

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Scalar for Df64

Source§

const DOMAIN: ScalarDomain = tenferro_tensor_core::ScalarDomain::Field

Algebra of this scalar’s ordinary arithmetic.
Source§

impl ScalarArithmetic for Df64

Source§

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

First-order expansion product: the exact leading product plus the first-order correction terms.

Source§

fn scalar_zero() -> Self

Additive identity. Read more
Source§

fn scalar_one() -> Self

Multiplicative identity. Read more
Source§

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

Sum under this scalar’s own semantics. Read more
Source§

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

Difference under this scalar’s own semantics. Read more
Source§

impl StructuralPartialEq for Df64

Source§

impl Sub for Df64

Source§

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

Exact subtraction.

Source§

type Output = Df64

The resulting type after applying the - operator.

Auto Trait Implementations§

§

impl Freeze for Df64

§

impl RefUnwindSafe for Df64

§

impl Send for Df64

§

impl Sync for Df64

§

impl Unpin for Df64

§

impl UnsafeUnpin for Df64

§

impl UnwindSafe for Df64

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
§

impl<T> Boilerplate for T
where T: Copy + Send + Sync + Debug + PartialEq + 'static,

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

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.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = 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.