Expand description

Multiple precision floating point numbers implemented purely in Rust. Number has fixed-size mantissa and exponent, but increased precision compared to f32 or f64 values.

Number characteristics:

NameValue
Decimal positions in mantissa40
Exponent minimum value-128
Exponent maximum value127

Examples

use num_bigfloat::BigFloat;
use num_bigfloat::ONE;
use num_bigfloat::PI;
 
// compute pi: pi = 6*arctan(1/sqrt(3))
let six: BigFloat = 6.0.into(); // note: conversion from f64,f32 are not loss-less.
let three: BigFloat = BigFloat::parse("3.0").unwrap();
let pi = six * (ONE / three.sqrt()).atan();
let epsilon = 1.0e-38.into();
 
assert!((pi - PI).abs() < epsilon);
 
println!("{}", pi);
// output: 3.141592653589793238462643383279502884196e-39

no_std example:

use num_bigfloat::BigFloat;
use num_bigfloat::ONE;
use num_bigfloat::PI;
 
// compute pi: pi = 6*arctan(1/sqrt(3))
let six: BigFloat = BigFloat::from_u8(6);
let three: BigFloat = BigFloat::from_u8(3);
let pi = six.mul(&ONE.div(&three.sqrt()).atan());
let epsilon = BigFloat::from_f64(1.0e-38);
 
assert!(pi.sub(&PI).abs().cmp(&epsilon).unwrap() < 0);

Precision

The use of additional digits of the manitissa in calculations allows minimizing the error and rounding the results correctly (i.e. as if the result was a rounded infinitely precise number). The precision of the results may be lost under certain conditions, such as when the argument is a subnormal number, or when the function is periodic, such as sine or cosine, when the argument is much larger than pi.

no_std

Library can be used without the standard Rust library. This can be achieved by turning off std feature.

Structs

Number representation.

Enums

Possible errors.

Constants

Euler’s number.

PI/2

Negative infinity.

Positive infinity.

Maximum value possible.

Maximum possible exponent.

Minumum value possible.

Minumum possible exponent.

Smalles positive number.

NaN representation.

Value of one.

PI number.

Radix of BigFloat

Value of two.

Value of zero.