#decimal-number #decimal #big-float #bignum #increase

no-std num-bigfloat

Increased precision floating point numbers implemented purely in Rust

19 releases (stable)

1.7.1 Mar 9, 2024
1.7.0 Sep 10, 2023
1.6.3 Aug 15, 2023
1.6.2 Feb 3, 2023
0.1.6 Jun 19, 2022

#60 in Math

Download history 555/week @ 2024-08-21 657/week @ 2024-08-28 666/week @ 2024-09-04 680/week @ 2024-09-11 752/week @ 2024-09-18 926/week @ 2024-09-25 893/week @ 2024-10-02 808/week @ 2024-10-09 834/week @ 2024-10-16 734/week @ 2024-10-23 838/week @ 2024-10-30 549/week @ 2024-11-06 653/week @ 2024-11-13 531/week @ 2024-11-20 1279/week @ 2024-11-27 1164/week @ 2024-12-04

3,760 downloads per month
Used in 11 crates (10 directly)

MIT license

4MB
157K SLoC

Tests Minimum rustc version

Increased precision floating point numbers implemented purely in Rust.

Arbitrary precision numbers

A fork of the library is available that implements floating-point numbers of arbitrary precision: astro-float. The new library uses more elaborate algorithms, has higher accuracy and better test coverage.

Rationale

There are several notable implementations of numbers with increased precision for Rust. Among the libraries, one can recall num-bigint, rust_decimal.

While these libraries are great in many ways, they don't allow you to perform operations on numbers while still providing fairly high precision.

There are also wrapper libraries, like rug, that depend on MPFR for implementing arbitrary precision floating point numbers.

This library is written in pure Rust, provides more precision than f32, f64, and some other data types with increased precision.

Number characteristics

Number has fixed-size mantissa and exponent.

Name Value
Base 10
Decimal positions in mantissa 40
Exponent minimum value -128
Exponent maximum value 127

no_std

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

Performance

Benchmark for num-bigfloat, rug(MPFR), and astro-float can be found here: bigfloat-bench.

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.

Dependencies