Skip to main content

Crate softfpu

Crate softfpu 

Source
Expand description

Software floating-point arithmetic on binary32, binary64 and x87 80-bit encodings. The library uses integer arithmetic and requires no allocator or global state.

math provides binary32 and binary64 arithmetic with round-to-nearest, ties to even. Each operation returns its value and exception flags.

use softfpu::{Double, Flags, math};

let one = Double::from_i32(1);
let ten = Double::from_i32(10);
let quotient = math::divide(one, ten);

assert_eq!(quotient.value, Double(0.1_f64.to_bits()));
assert_eq!(quotient.exceptions, Flags::INEXACT);

The core exposes Single, Double and Extended. Operations take a nan::NanPolicy type parameter and report Flags. The x86 facade selects the x86 NaN policy, detects tininess after rounding and reports architectural exception bits.

Computed::Finished carries a value and its flags. Computed::Unfinished carries an intermediate that the caller rounds for the destination. Even an exact result can need a range response: half the smallest normal number is a denormal under masked rounding but triggers exponent adjustment for an unmasked x87 register underflow. Computed::settle calls the supplied rounding function only for an unfinished result.

Modules§

math
Binary32 and binary64 arithmetic with round-to-nearest, ties to even.
nan
NaN propagation and conversion policy.
x86
x86 floating-point arithmetic and exception reporting.

Structs§

Double
An IEEE binary64 bit pattern. The sign occupies bit 63, the biased exponent bits 52–62 (bias 1023), and the fraction bits 0–51. Finite normal values have 53 significant bits. Equality compares encodings.
Extended
An x87 extended bit pattern with an explicit integer bit. Equality compares all 80 bits. The byte conversions preserve every encoding. Arithmetic takes canonical operands. A zero exponent with the integer bit set is a pseudo-denormal. Normalize it to exponent field one before arithmetic. An all-ones exponent with the integer bit set denotes infinity (zero fraction) or NaN. Handle unsupported encodings in the instruction caller.
Flags
Architecture-independent floating-point exception flags.
Rounded
A delivered value, its exception flags and rounding indicators.
Single
An IEEE binary32 bit pattern. The sign occupies bit 31, the biased exponent bits 23–30 (bias 127), and the fraction bits 0–22. Finite normal values have 24 significant bits. Equality compares encodings.
Unrounded
A finite nonzero intermediate for destination F. For the arithmetic operations and conversions, its normalized fraction agrees with the exact result after rounding both to odd at p + 2 bits, where p is the format’s precision. For an x87 transcendental function, it holds the value the kernel’s schedule computes, which approximates the mathematical function. Round this value for each range response.

Enums§

Computed
An operation result before the caller chooses a range response.
InvalidConversion
Failure of a rounded conversion to a signed integer.
Precision
x87 significand precision. All settings retain the extended exponent range.
Relation
Numeric ordering, including unordered comparisons with NaNs.
Rounding
Direction for rounding an inexact result.
Tininess
Selects the magnitude used to detect tininess for masked rounding.