Skip to main content

ArbitraryFloat

Struct ArbitraryFloat 

Source
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

Source

pub fn zero(precision: Precision) -> Self

Create a zero value with the given precision.

Source

pub fn one(precision: Precision) -> Self

Create a one value with the given precision.

Source

pub fn pos_infinity(precision: Precision) -> Self

Create positive infinity.

Source

pub fn neg_infinity(precision: Precision) -> Self

Create negative infinity.

Source

pub fn nan(precision: Precision) -> Self

Create NaN (Not a Number).

Source

pub fn is_zero(&self) -> bool

Check if this value is zero.

Source

pub fn is_pos_infinity(&self) -> bool

Check if this value is positive infinity.

Source

pub fn is_neg_infinity(&self) -> bool

Check if this value is negative infinity.

Source

pub fn is_infinity(&self) -> bool

Check if this value is any infinity.

Source

pub fn is_nan(&self) -> bool

Check if this value is NaN.

Source

pub fn is_finite(&self) -> bool

Check if this value is finite (not infinity or NaN).

Source

pub fn is_negative(&self) -> bool

Check if this value is negative.

Source

pub fn is_positive(&self) -> bool

Check if this value is positive.

Source

pub fn precision(&self) -> Precision

Get the precision of this value.

Source

pub fn from_f64(value: f64, precision: Precision) -> Self

Create from an f64 value.

§Arguments
  • value - The f64 value to convert
  • precision - Target precision
§Example
use oxiz_math::mpfr::{ArbitraryFloat, Precision};
let f = ArbitraryFloat::from_f64(3.14159, Precision::new(128));
Source

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);
Source

pub fn add(&self, other: &Self, rounding: RoundingMode) -> Self

Add two arbitrary precision floats.

§Arguments
  • other - The other value to add
  • rounding - Rounding mode for the result
§Returns

The sum with the higher precision of the two operands.

Source

pub fn sub(&self, other: &Self, rounding: RoundingMode) -> Self

Subtract two arbitrary precision floats.

Source

pub fn mul(&self, other: &Self, rounding: RoundingMode) -> Self

Multiply two arbitrary precision floats.

Source

pub fn div(&self, other: &Self, rounding: RoundingMode) -> Self

Divide two arbitrary precision floats.

Source

pub fn sqrt(&self, rounding: RoundingMode) -> Self

Compute the square root.

Uses Newton-Raphson iteration for arbitrary precision square root.

Source

pub fn neg(&self) -> Self

Negate the value.

Source

pub fn abs(&self) -> Self

Absolute value.

Source

pub fn partial_compare(&self, other: &Self) -> Option<Ordering>

Compare two arbitrary precision floats.

Returns None if either value is NaN.

Source

pub fn from_str(s: &str, precision: Precision) -> Option<Self>

Create from a string representation.

Supports decimal notation (e.g., “3.14159”) and scientific notation (e.g., “3.14e-10”).

Trait Implementations§

Source§

impl Add for ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for &ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for ArbitraryFloat

Source§

fn clone(&self) -> ArbitraryFloat

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 ArbitraryFloat

Source§

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

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

impl Display for ArbitraryFloat

Source§

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

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

impl Div for ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for &ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Mul for ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for &ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Neg for &ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for ArbitraryFloat

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for ArbitraryFloat

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 Sub for ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for &ArbitraryFloat

Source§

type Output = ArbitraryFloat

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

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.