Struct Real

Source
pub struct Real {
    pub prim: Box<Primitive>,
    pub approx: Option<Approx>,
}
Expand description

The core idea here is that we represent a real number as a function f(n: i32) -> BigInt, where n is the desired precision (typically negative).

The function is constructed such that |f(n)*2^n - x| < 2^n. By using an increasingly negative n, we can approximate x to arbitrary precision.

Fields§

§prim: Box<Primitive>§approx: Option<Approx>

Implementations§

Source§

impl Real

Source

pub fn new(prim: Primitive) -> Self

Source

pub fn known_msd(&self) -> Option<i32>

Returns the most significant digit based on the current approximation. If msd is n, then 2^(n-1) < |x| < 2^(n+1). Returns None if no approximation has been made.

Source

pub fn msd(&mut self, precision: i32) -> Option<i32>

Evaluates to the desired precision and returns the msd. Returns None if the correct msd < precision

Source

pub fn iter_msd_n(&mut self, min_precision: i32) -> Option<i32>

Iteratively lowers the precision until the msd is found, or the provided precision is reached.

Source

pub fn iter_msd(&mut self) -> Option<i32>

Iteratively lowers the precision until the msd is found. This will create an infinite loop if the value is zero.

Source

pub fn appr(&mut self, precision: i32) -> Approx

Generates an approximation of the real number. If we have already approximated the number with a sufficient precision, we simply scale the approximation. Otherwise we call the underlying approximate method.

Source

pub fn render_base(&self, n: u32, base: u32) -> String

Source

pub fn render(&self, n: u32) -> String

Source

pub fn cmp_ra( &mut self, other: &mut Real, rel_tol: i32, abs_tol: i32, ) -> Ordering

Source

pub fn cmp_a(&mut self, other: &mut Real, abs_tol: i32) -> Ordering

Source

pub fn cmp_until(&self, other: &Real, min_precision: i32) -> Ordering

Source

pub fn signum_a(&self, a: i32) -> i32

Source§

impl Real

Source

pub fn int(value: BigInt) -> Self

Source

pub fn squared(self) -> Self

Source

pub fn atan(value: BigInt) -> Self

Source

pub fn exp(self) -> Self

Source

pub fn cos(self) -> Self

Source

pub fn sin(self) -> Self

Source

pub fn asin(self) -> Self

Source

pub fn acos(self) -> Self

Source

pub fn ln2(self) -> Self

Source

pub fn ln(self) -> Self

Source

pub fn sqrt(self) -> Self

Source

pub fn shifted(self, bits: i32) -> Self

Source

pub fn pi() -> Self

John Machin’s formula from 1706: pi/4 = 4 * atan(1/5) - atan(1/239)

Source

pub fn inv(self) -> Self

Trait Implementations§

Source§

impl Add for Real

Source§

type Output = Real

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Real

Source§

fn clone(&self) -> Real

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Real

Source§

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

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

impl Div for Real

Source§

type Output = Real

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl From<BigInt> for Real

Source§

fn from(value: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<Ratio<BigInt>> for Real

Source§

fn from(value: BigRational) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Real

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Real

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Real

Source§

type Err = ParseBigIntError

The associated error which can be returned from parsing.
Source§

fn from_str(str: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Into<BigInt> for Real

Source§

fn into(self) -> BigInt

Converts this type into the (usually inferred) input type.
Source§

impl Into<f64> for Real

Source§

fn into(self) -> f64

Converts this type into the (usually inferred) input type.
Source§

impl Mul for Real

Source§

type Output = Real

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Real

Source§

type Output = Real

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Num for Real

Source§

type FromStrRadixErr = ParseBigIntError

Source§

fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
Source§

impl One for Real

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl Ord for Real

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Real

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Real

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 · 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 · 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 · 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 · 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 Rem for Real

Source§

type Output = Real

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl Signed for Real

Source§

fn abs(&self) -> Self

Computes the absolute value. Read more
Source§

fn abs_sub(&self, other: &Self) -> Self

The positive difference of two numbers. Read more
Source§

fn signum(&self) -> Self

Returns the sign of the number. Read more
Source§

fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative.
Source§

fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.
Source§

impl Sub for Real

Source§

type Output = Real

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Zero for Real

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl Eq for Real

Auto Trait Implementations§

§

impl Freeze for Real

§

impl RefUnwindSafe for Real

§

impl Send for Real

§

impl Sync for Real

§

impl Unpin for Real

§

impl UnwindSafe for Real

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.
Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,