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: f64Rounded component.
lo: f64Exact residual component.
Implementations§
Source§impl Df64
impl Df64
Sourcepub fn from_f64(value: f64) -> Self
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 });Sourcepub fn zero() -> Self
pub fn zero() -> Self
Additive identity.
§Examples
use tenferro_df64_proof::Df64;
assert_eq!(Df64::zero(), Df64 { hi: 0.0, lo: 0.0 });Sourcepub fn narrow_to_f64(self) -> f64
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);Sourcepub fn ratio(self, divisor: Self) -> Self
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);Sourcepub fn sqrt(self) -> Self
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());Trait Implementations§
Source§impl BinaryScalarOp<Df64> for Df64Add
impl BinaryScalarOp<Df64> for Df64Add
impl Copy for Df64
Source§impl Scalar for Df64
impl Scalar for Df64
Source§const DOMAIN: ScalarDomain = tenferro_tensor_core::ScalarDomain::Field
const DOMAIN: ScalarDomain = tenferro_tensor_core::ScalarDomain::Field
Source§impl ScalarArithmetic for Df64
impl ScalarArithmetic for Df64
Source§fn scalar_mul(self, rhs: Self) -> Self
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
fn scalar_zero() -> Self
Source§fn scalar_one() -> Self
fn scalar_one() -> Self
Source§fn scalar_add(self, rhs: Self) -> Self
fn scalar_add(self, rhs: Self) -> Self
Source§fn scalar_sub(self, rhs: Self) -> Self
fn scalar_sub(self, rhs: Self) -> Self
impl StructuralPartialEq for Df64
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§
impl<T> Boilerplate for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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