pub struct DoubleDouble {
pub hi: f64,
pub lo: f64,
}Expand description
Double-double precision floating-point number.
Represents the unevaluated sum hi + lo where |lo| ≤ 0.5 ulp(hi).
Provides approximately 31 decimal digits of precision using two f64 values.
§Constants
use scirs2_core::arithmetic::DoubleDouble;
let zero = DoubleDouble::ZERO;
let one = DoubleDouble::ONE;
let pi = DoubleDouble::PI;
let e = DoubleDouble::E;Fields§
§hi: f64High-order word (most significant bits).
lo: f64Low-order word (error term; |lo| ≤ 0.5 ulp(hi)).
Implementations§
Source§impl DoubleDouble
impl DoubleDouble
Sourcepub const E: Self
pub const E: Self
e = exp(1) to double-double precision. Value: 2.71828182845904523536028747135266249…
Sourcepub fn from_f64(hi: f64, lo: f64) -> Self
pub fn from_f64(hi: f64, lo: f64) -> Self
Construct from explicit (hi, lo) parts with renormalization.
Sourcepub fn to_f128_approx(self) -> f64
pub fn to_f128_approx(self) -> f64
Convert to f64 with compensated rounding (returns hi + lo).
Loses precision in the conversion but is numerically more accurate than to_f64.
Sourcepub fn add(self, rhs: Self) -> Self
pub fn add(self, rhs: Self) -> Self
Add self + rhs using double-double arithmetic.
Uses the precise algorithm (Shewchuk 1997).
Sourcepub fn div(self, rhs: Self) -> CoreResult<Self>
pub fn div(self, rhs: Self) -> CoreResult<Self>
Divide self / rhs.
Returns Err if rhs is zero.
Sourcepub fn mul_f64(self, rhs: f64) -> Self
pub fn mul_f64(self, rhs: f64) -> Self
Multiply self × rhs where rhs is a plain f64.
Slightly cheaper than the full double-double multiplication.
Sourcepub fn sqrt(self) -> CoreResult<Self>
pub fn sqrt(self) -> CoreResult<Self>
Square root via Newton-Raphson iteration in double-double precision.
Returns Err for negative inputs.
Sourcepub fn exp(self) -> CoreResult<Self>
pub fn exp(self) -> CoreResult<Self>
Compute e^self using range reduction and Taylor series in DD arithmetic.
Range reduction: x = k*ln(2) + r, then exp(x) = 2^k * exp(r).
Sourcepub fn ln(self) -> CoreResult<Self>
pub fn ln(self) -> CoreResult<Self>
Compute ln(self) for positive inputs.
Uses a Newton refinement of the f64 result.
Sourcepub fn sin(self) -> CoreResult<Self>
pub fn sin(self) -> CoreResult<Self>
Compute sin(self) in double-double precision.
Returns only the sine component. For simultaneous sin/cos, prefer sincos.
Sourcepub fn cos(self) -> CoreResult<Self>
pub fn cos(self) -> CoreResult<Self>
Compute cos(self) in double-double precision.
Returns only the cosine component. For simultaneous sin/cos, prefer sincos.
Sourcepub fn sincos(self) -> CoreResult<(Self, Self)>
pub fn sincos(self) -> CoreResult<(Self, Self)>
Compute (sin(self), cos(self)) simultaneously.
Uses argument reduction to [-π/4, π/4] followed by Taylor series.
Sourcepub fn powi(self, n: i32) -> CoreResult<Self>
pub fn powi(self, n: i32) -> CoreResult<Self>
Integer power via repeated squaring.
Handles negative exponents by inversion.
Trait Implementations§
Source§impl Add for DoubleDouble
impl Add for DoubleDouble
Source§type Output = DoubleDouble
type Output = DoubleDouble
+ operator.Source§fn add(self, rhs: DoubleDouble) -> DoubleDouble
fn add(self, rhs: DoubleDouble) -> DoubleDouble
+ operation. Read moreSource§impl Clone for DoubleDouble
impl Clone for DoubleDouble
Source§fn clone(&self) -> DoubleDouble
fn clone(&self) -> DoubleDouble
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DoubleDouble
impl Debug for DoubleDouble
Source§impl Default for DoubleDouble
impl Default for DoubleDouble
Source§fn default() -> DoubleDouble
fn default() -> DoubleDouble
Source§impl Display for DoubleDouble
impl Display for DoubleDouble
Source§impl Div for DoubleDouble
Division via div; returns DoubleDouble { hi: NaN, lo: NaN } if rhs is zero.
Prefer DoubleDouble::div for error handling.
impl Div for DoubleDouble
Division via div; returns DoubleDouble { hi: NaN, lo: NaN } if rhs is zero.
Prefer DoubleDouble::div for error handling.
Source§type Output = DoubleDouble
type Output = DoubleDouble
/ operator.Source§fn div(self, rhs: DoubleDouble) -> DoubleDouble
fn div(self, rhs: DoubleDouble) -> DoubleDouble
/ operation. Read moreSource§impl From<f64> for DoubleDouble
impl From<f64> for DoubleDouble
Source§fn from(x: f64) -> DoubleDouble
fn from(x: f64) -> DoubleDouble
Source§impl From<i32> for DoubleDouble
impl From<i32> for DoubleDouble
Source§fn from(x: i32) -> DoubleDouble
fn from(x: i32) -> DoubleDouble
Source§impl From<i64> for DoubleDouble
impl From<i64> for DoubleDouble
Source§fn from(x: i64) -> DoubleDouble
fn from(x: i64) -> DoubleDouble
Source§impl Mul for DoubleDouble
impl Mul for DoubleDouble
Source§type Output = DoubleDouble
type Output = DoubleDouble
* operator.Source§fn mul(self, rhs: DoubleDouble) -> DoubleDouble
fn mul(self, rhs: DoubleDouble) -> DoubleDouble
* operation. Read moreSource§impl Neg for DoubleDouble
impl Neg for DoubleDouble
Source§type Output = DoubleDouble
type Output = DoubleDouble
- operator.Source§fn neg(self) -> DoubleDouble
fn neg(self) -> DoubleDouble
- operation. Read moreSource§impl PartialEq for DoubleDouble
impl PartialEq for DoubleDouble
Source§impl PartialOrd for DoubleDouble
impl PartialOrd for DoubleDouble
Source§impl Sub for DoubleDouble
impl Sub for DoubleDouble
Source§type Output = DoubleDouble
type Output = DoubleDouble
- operator.Source§fn sub(self, rhs: DoubleDouble) -> DoubleDouble
fn sub(self, rhs: DoubleDouble) -> DoubleDouble
- operation. Read moreimpl Copy for DoubleDouble
Auto Trait Implementations§
impl Freeze for DoubleDouble
impl RefUnwindSafe for DoubleDouble
impl Send for DoubleDouble
impl Sync for DoubleDouble
impl Unpin for DoubleDouble
impl UnsafeUnpin for DoubleDouble
impl UnwindSafe for DoubleDouble
Blanket Implementations§
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.