Skip to main content

Computable

Struct Computable 

Source
pub struct Computable { /* private fields */ }
Expand description

Computable approximation of a Real number.

Implementations§

Source§

impl Computable

Source

pub fn one() -> Computable

Exactly one.

Source

pub fn pi() -> Computable

Approximate π, the ratio of a circle’s circumference to its diameter.

Source

pub fn rational(r: Rational) -> Computable

Any Rational.

Source§

impl Computable

Source

pub fn exp(self) -> Computable

Natural Exponential function, raise Euler’s Number to this number.

Source

pub fn cos(self) -> Computable

Cosine of this number.

Source

pub fn sin(self) -> Computable

Sine of this number.

Source

pub fn tan(self) -> Computable

Tangent of this number.

Source

pub fn ln(self) -> Computable

Natural logarithm of this number.

Source

pub fn sqrt(self) -> Computable

Square root of this number.

Source

pub fn negate(self) -> Computable

Negate this number.

Source

pub fn inverse(self) -> Computable

Multiplicative inverse of this number.

Source

pub fn square(self) -> Self

Square of this number.

Source

pub fn multiply(self, other: Computable) -> Computable

Multiply this number by some other number.

Source

pub fn add(self, other: Computable) -> Computable

Add some other number to this number.

Source

pub fn abort(&mut self, s: Arc<AtomicBool>)

Source

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

pub fn approx_signal(&self, signal: &Option<Arc<AtomicBool>>, p: i32) -> BigInt

Like approx but specifying an atomic abort/ stop signal.

Source

pub fn sign(&self) -> Sign

Source

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

Do not call this function if self and other may be the same.

Source

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

Source§

fn clone(&self) -> Computable

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 Computable

Source§

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

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

impl Display for Computable

Source§

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

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

impl LowerExp for Computable

Source§

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

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

impl UpperExp for Computable

Source§

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

Formats the value using the given formatter. 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.