Crate num_bigfloat

source ·
Expand description

Increased 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
Base10
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();
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

The same example using functions:

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);  // note: conversion from f64,f32 are not loss-less for `no_std`.

assert!(pi.sub(&PI).abs().cmp(&epsilon).unwrap() < 0);

§no_std

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

§Other features

The library depends on rand which is used by BigFloat::random_normal. This dependecy can be excluded by turning off the rand feature. rand feature requires std feature.

The library depends on serde which is also optional and can be eliminated by turning off the serde feature.

In addition, the library implements num-traits. Dependency on num-traits can be excluded by turning off num-traits feature.

Modules§

  • Serialization and deserialization using different formats and data types.

Structs§

Enums§

Constants§