#floating-point #mathematics #numerics #float #no-std

no-std ieee754

Low-level manipulations of IEEE754 floating-point numbers

9 releases

Uses old Rust 2015

0.3.0-alpha.2 Dec 20, 2020
0.2.6 Jan 13, 2019
0.2.2 May 17, 2017
0.2.1 Nov 19, 2015
0.1.1 May 12, 2015

#788 in Math

Download history 3148/week @ 2022-10-17 3363/week @ 2022-10-24 2865/week @ 2022-10-31 3273/week @ 2022-11-07 4308/week @ 2022-11-14 3285/week @ 2022-11-21 3885/week @ 2022-11-28 4478/week @ 2022-12-05 4369/week @ 2022-12-12 4021/week @ 2022-12-19 2387/week @ 2022-12-26 4388/week @ 2023-01-02 4485/week @ 2023-01-09 4142/week @ 2023-01-16 4695/week @ 2023-01-23 5307/week @ 2023-01-30

18,870 downloads per month
Used in 110 crates (16 directly)

MIT/Apache

75KB
1K SLoC

ieee754

Build Status codecov

Low-level manipulations of IEEE754 floating-point numbers.

This library includes:

  • no_std support by default,
  • ulp computation (units in the last place, representing the resolution of a float),
  • miscellaneous functions like nextafter (next and prev), copysign (copy_sign), abs, sign,
  • the IEEE-754 totalOrder predicate for doing Ord::cmp-like comparisons on floats,
  • an iterator over every floating point value in a range,
  • a parallel iterator over every floating point value in a range (optional: activate with the rayon feature),
  • relative error computation.

Documentation, crates.io.


lib.rs:

Low-level manipulations of IEEE754 floating-point numbers.

Installation

Add this to your Cargo.toml:

[dependencies]
ieee754 = "0.2"

To enable rayon parallel iteration, activate the optional rayon feature:

[dependencies]
ieee754 = { version = "0.2", features = ["rayon"] }

Examples

use ieee754::Ieee754;

// there are 840 single-precision floats between 1.0 and 1.0001
// (inclusive).
assert_eq!(1_f32.upto(1.0001).count(), 840);

If rayon is enabled, this can be performed in parallel:

extern crate ieee754;
# #[cfg(feature = "rayon")]
extern crate rayon;

# #[cfg(feature = "rayon")]
# fn main() {
use ieee754::Ieee754;
use rayon::prelude::*;

// there are 840 single-precision floats between 1.0 and 1.0001
// (inclusive).
assert_eq!(1_f32.upto(1.0001).into_par_iter().count(), 840);
# }
# #[cfg(not(feature = "rayon"))] fn main() {}

Dependencies