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
impl Real
pub fn new(prim: Primitive) -> Self
Sourcepub fn known_msd(&self) -> Option<i32>
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.
Sourcepub fn msd(&mut self, precision: i32) -> Option<i32>
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
Sourcepub fn iter_msd_n(&mut self, min_precision: i32) -> Option<i32>
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.
Sourcepub fn iter_msd(&mut self) -> Option<i32>
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.
Sourcepub fn appr(&mut self, precision: i32) -> Approx
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.
pub fn render_base(&self, n: u32, base: u32) -> String
pub fn render(&self, n: u32) -> String
pub fn cmp_ra( &mut self, other: &mut Real, rel_tol: i32, abs_tol: i32, ) -> Ordering
pub fn cmp_a(&mut self, other: &mut Real, abs_tol: i32) -> Ordering
pub fn cmp_until(&self, other: &Real, min_precision: i32) -> Ordering
pub fn signum_a(&self, a: i32) -> i32
Source§impl Real
impl Real
pub fn int(value: BigInt) -> Self
pub fn squared(self) -> Self
pub fn atan(value: BigInt) -> Self
pub fn exp(self) -> Self
pub fn cos(self) -> Self
pub fn sin(self) -> Self
pub fn asin(self) -> Self
pub fn acos(self) -> Self
pub fn ln2(self) -> Self
pub fn ln(self) -> Self
pub fn sqrt(self) -> Self
pub fn shifted(self, bits: i32) -> Self
pub fn inv(self) -> Self
Trait Implementations§
Source§impl From<Ratio<BigInt>> for Real
impl From<Ratio<BigInt>> for Real
Source§fn from(value: BigRational) -> Self
fn from(value: BigRational) -> Self
Source§impl Num for Real
impl Num for Real
type FromStrRadixErr = ParseBigIntError
Source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36). Read more