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§
- serde
- Serialization and deserialization using different formats and data types.
Structs§
- BigFloat
- Number representation.
Enums§
- Error
- Possible errors.
- Rounding
Mode - Rounding modes.
Constants§
- E
- Euler’s number.
- EPSILON
- The difference between 1 and the smallest floating point number greater than 1.
- FRAC_
1_ PI - 1 / PI
- FRAC_
1_ SQRT_ 2 - 1 / SQRT(2)
- FRAC_
2_ PI - 2 / PI
- FRAC_
2_ SQRT_ PI - 2 / SQRT(PI)
- FRAC_
PI_ 3 - PI / 3
- FRAC_
PI_ 4 - PI / 4
- FRAC_
PI_ 6 - PI / 6
- FRAC_
PI_ 8 - PI / 8
- HALF_PI
- PI / 2.
- INF_NEG
- Negative infinity.
- INF_POS
- Positive infinity.
- LN_2
- ln(2)
- LN_10
- ln(10)
- LOG2_E
- log2(E)
- LOG10_E
- log10(E)
- MAX
- Maximum value possible.
- MAX_EXP
- Maximum possible exponent.
- MIN
- Minumum value possible.
- MIN_EXP
- Minumum possible exponent.
- MIN_
POSITIVE - The smallest positive number.
- MIN_
POSITIVE_ NORMAL - The smallest positive normal number.
- NAN
- NaN representation.
- ONE
- Value of one.
- PI
- PI number.
- RADIX
- Radix of BigFloat.
- SQRT_2
- SQRT(2)
- TWO
- Value of two.
- ZERO
- Value of zero.