pub struct Computable { /* private fields */ }Expand description
Computable approximation of a Real number.
Implementations§
Source§impl Computable
impl Computable
Sourcepub fn one() -> Computable
pub fn one() -> Computable
Exactly one.
Sourcepub fn pi() -> Computable
pub fn pi() -> Computable
Approximate π, the ratio of a circle’s circumference to its diameter.
Sourcepub fn rational(r: Rational) -> Computable
pub fn rational(r: Rational) -> Computable
Any Rational.
Source§impl Computable
impl Computable
Sourcepub fn exp(self) -> Computable
pub fn exp(self) -> Computable
Natural Exponential function, raise Euler’s Number to this number.
Sourcepub fn cos(self) -> Computable
pub fn cos(self) -> Computable
Cosine of this number.
Sourcepub fn sin(self) -> Computable
pub fn sin(self) -> Computable
Sine of this number.
Sourcepub fn tan(self) -> Computable
pub fn tan(self) -> Computable
Tangent of this number.
Sourcepub fn ln(self) -> Computable
pub fn ln(self) -> Computable
Natural logarithm of this number.
Sourcepub fn sqrt(self) -> Computable
pub fn sqrt(self) -> Computable
Square root of this number.
Sourcepub fn negate(self) -> Computable
pub fn negate(self) -> Computable
Negate this number.
Sourcepub fn inverse(self) -> Computable
pub fn inverse(self) -> Computable
Multiplicative inverse of this number.
Sourcepub fn multiply(self, other: Computable) -> Computable
pub fn multiply(self, other: Computable) -> Computable
Multiply this number by some other number.
Sourcepub fn add(self, other: Computable) -> Computable
pub fn add(self, other: Computable) -> Computable
Add some other number to this number.
pub fn abort(&mut self, s: Arc<AtomicBool>)
Sourcepub fn approx(&self, p: i32) -> BigInt
pub fn approx(&self, p: i32) -> BigInt
An approximation of this Computable scaled to a specific precision
The approximation is scaled (thus, a larger value for more negative p) and should be accurate to within +/- 1 at the scale provided.
Example: 0.875 is between 0 and 1 with zero bits of extra precision
use realistic::{Rational,Computable};
use num::{Zero,One};
use num::bigint::{BigInt,ToBigInt};
let n = Rational::fraction(7, 8).unwrap();
let comp = Computable::rational(n);
assert!((BigInt::zero() ..= BigInt::one()).contains(&comp.approx(0)));Example: π * 2³ is a bit more than 25 but less than 26
use realistic::{Rational,Computable};
use num::{Zero,One};
use num::bigint::{BigInt,ToBigInt};
let pi = Computable::pi();
let between_25_26 = (ToBigInt::to_bigint(&25).unwrap() ..= ToBigInt::to_bigint(&26).unwrap());
assert!(between_25_26.contains(&pi.approx(-3)));Sourcepub fn approx_signal(&self, signal: &Option<Arc<AtomicBool>>, p: i32) -> BigInt
pub fn approx_signal(&self, signal: &Option<Arc<AtomicBool>>, p: i32) -> BigInt
Like approx but specifying an atomic abort/ stop signal.
pub fn sign(&self) -> Sign
Sourcepub fn compare_to(&self, other: &Self) -> Ordering
pub fn compare_to(&self, other: &Self) -> Ordering
Do not call this function if self and other may be the same.
Sourcepub fn compare_absolute(&self, other: &Self, tolerance: i32) -> Ordering
pub fn compare_absolute(&self, other: &Self, tolerance: i32) -> Ordering
Compare two values to a specified tolerance (more negative numbers are more precise).
Trait Implementations§
Source§impl Clone for Computable
impl Clone for Computable
Source§fn clone(&self) -> Computable
fn clone(&self) -> Computable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more