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:
Name | Value |
---|---|
Base | 10 |
Decimal positions in mantissa | 40 |
Exponent minimum value | -128 |
Exponent maximum value | 127 |
§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§
- Number representation.
Enums§
- Possible errors.
- Rounding modes.
Constants§
- Euler’s number.
- The difference between 1 and the smallest floating point number greater than 1.
- 1 / PI
- 1 / SQRT(2)
- 2 / PI
- 2 / SQRT(PI)
- PI / 3
- PI / 4
- PI / 6
- PI / 8
- PI / 2.
- Negative infinity.
- Positive infinity.
- ln(2)
- ln(10)
- log2(E)
- log10(E)
- Maximum value possible.
- Maximum possible exponent.
- Minumum value possible.
- Minumum possible exponent.
- The smallest positive number.
- The smallest positive normal number.
- NaN representation.
- Value of one.
- PI number.
- Radix of BigFloat.
- SQRT(2)
- Value of two.
- Value of zero.