pub struct ArbitraryFloat { /* private fields */ }Expand description
Arbitrary precision floating-point number.
Represents a floating-point number with configurable precision. The internal representation uses a sign, mantissa (BigInt), and exponent.
Value = (-1)^sign * mantissa * 2^exponent
A normalized value (as produced by Self::normalize, Self::from_f64,
Self::add, Self::mul, Self::div, …) has mantissa.bits() == precision.bits(), i.e. the mantissa itself already occupies exactly
precision bits (no separate - precision + 1 offset folded into the
exponent).
Implementations§
Source§impl ArbitraryFloat
impl ArbitraryFloat
Sourcepub fn pos_infinity(precision: Precision) -> Self
pub fn pos_infinity(precision: Precision) -> Self
Create positive infinity.
Sourcepub fn neg_infinity(precision: Precision) -> Self
pub fn neg_infinity(precision: Precision) -> Self
Create negative infinity.
Sourcepub fn is_pos_infinity(&self) -> bool
pub fn is_pos_infinity(&self) -> bool
Check if this value is positive infinity.
Sourcepub fn is_neg_infinity(&self) -> bool
pub fn is_neg_infinity(&self) -> bool
Check if this value is negative infinity.
Sourcepub fn is_infinity(&self) -> bool
pub fn is_infinity(&self) -> bool
Check if this value is any infinity.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if this value is negative.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Check if this value is positive.
Sourcepub fn to_f64(&self, _rounding: RoundingMode) -> f64
pub fn to_f64(&self, _rounding: RoundingMode) -> f64
Convert to f64.
May lose precision if the ArbitraryFloat has higher precision than f64.
§Arguments
rounding- Rounding mode for the conversion
§Example
use oxiz_math::mpfr::{ArbitraryFloat, Precision, RoundingMode};
let f = ArbitraryFloat::from_f64(3.14159, Precision::new(128));
let back = f.to_f64(RoundingMode::RoundNearest);Sourcepub fn add(&self, other: &Self, rounding: RoundingMode) -> Self
pub fn add(&self, other: &Self, rounding: RoundingMode) -> Self
Sourcepub fn sub(&self, other: &Self, rounding: RoundingMode) -> Self
pub fn sub(&self, other: &Self, rounding: RoundingMode) -> Self
Subtract two arbitrary precision floats.
Sourcepub fn mul(&self, other: &Self, rounding: RoundingMode) -> Self
pub fn mul(&self, other: &Self, rounding: RoundingMode) -> Self
Multiply two arbitrary precision floats.
Sourcepub fn div(&self, other: &Self, rounding: RoundingMode) -> Self
pub fn div(&self, other: &Self, rounding: RoundingMode) -> Self
Divide two arbitrary precision floats.
Sourcepub fn sqrt(&self, rounding: RoundingMode) -> Self
pub fn sqrt(&self, rounding: RoundingMode) -> Self
Compute the square root.
Uses Newton-Raphson iteration for arbitrary precision square root.
Sourcepub fn partial_compare(&self, other: &Self) -> Option<Ordering>
pub fn partial_compare(&self, other: &Self) -> Option<Ordering>
Compare two arbitrary precision floats.
Returns None if either value is NaN.
Trait Implementations§
Source§impl Add for ArbitraryFloat
impl Add for ArbitraryFloat
Source§impl Add for &ArbitraryFloat
impl Add for &ArbitraryFloat
Source§impl Clone for ArbitraryFloat
impl Clone for ArbitraryFloat
Source§fn clone(&self) -> ArbitraryFloat
fn clone(&self) -> ArbitraryFloat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more