softfpu/lib.rs
1//! Software floating-point arithmetic on binary32, binary64 and x87 80-bit encodings.
2//! The library uses integer arithmetic and requires no allocator or global state.
3//!
4//! [`math`] provides binary32 and binary64 arithmetic with round-to-nearest,
5//! ties to even. Each operation returns its value and exception flags.
6//!
7//! ```
8//! use softfpu::{Double, Flags, math};
9//!
10//! let one = Double::from_i32(1);
11//! let ten = Double::from_i32(10);
12//! let quotient = math::divide(one, ten);
13//!
14//! assert_eq!(quotient.value, Double(0.1_f64.to_bits()));
15//! assert_eq!(quotient.flags, Flags::INEXACT);
16//! ```
17//!
18//! The core exposes [`Single`], [`Double`] and [`Extended`]. Operations take a
19//! [`nan::NanPolicy`] type parameter and report [`Flags`]. The [`x86`] facade
20//! selects the x86 NaN policy and detects tininess after rounding.
21//!
22//! [`Computed::Finished`] carries a value and its flags. [`Computed::Unfinished`]
23//! carries an intermediate that the caller rounds for the destination.
24//! Even an exact result can need a range response: half the smallest normal
25//! number is a denormal under masked rounding but triggers exponent adjustment
26//! for an unmasked x87 register underflow. [`Computed::settle`] calls the
27//! supplied rounding function only for an unfinished result.
28
29#![cfg_attr(not(test), no_std)]
30#![forbid(unsafe_code)]
31
32pub mod math;
33pub mod nan;
34pub mod x86;
35
36mod add;
37mod cold;
38mod compare;
39mod convert;
40mod divide;
41mod format;
42mod multiply;
43mod result;
44mod round;
45mod sqrt;
46
47#[cfg(test)]
48mod test_util;
49#[cfg(test)]
50mod tests;
51
52pub use compare::Relation;
53pub use convert::InvalidConversion;
54pub use format::{Category, Double, Extended, Single};
55pub use result::{Computed, Flags, Rounded};
56pub use round::{Precision, Rounding, Tininess, Unrounded};