softfpu 0.3.0

32-, 64- and 80-bit floating-point arithmetic in safe Rust, including Intel x87 transcendental functions
Documentation
# Arithmetic design

The core operates on binary32, binary64 and x87 80-bit encodings. Each format
decodes a finite nonzero operand into a sign, an unbiased exponent and a 64-bit
normalized significand. If the exponent is `e` and the significand is `m`, the
magnitude is `m × 2^(e − 63)`. Shifting a denormal up to bit 63 and reducing its
exponent by the same number of places preserves its value.

## Results before rounding

An operation can finish immediately when the caller's precision, rounding mode
and range response cannot change the value. NaN propagation and division by zero
are examples. A finished result carries the flags raised by the operation.

For a finite nonzero result that needs a rounding decision, the kernel returns a
sign, an exponent and two fractional words. Bit 63 of the high word holds the
leading one. The low word holds the next bits and may include a sticky bit. The
caller can use the same intermediate for different range responses. Half the
smallest normal number, for example, is exactly representable as a denormal.
Masked rounding can deliver that denormal, while an unmasked x87 register
underflow adjusts the exponent.

## Precision of an intermediate

Let `p` be the destination format's maximum significand precision. Truncate the
exact normalized significand to `p + 2` bits and set the last retained bit if
any discarded bit was nonzero. This is rounding to odd. The kernel must produce
the same exponent and sign and a fraction that agrees with the exact fraction
after both are rounded to odd at `p + 2` bits.

A kernel can therefore return an exact fraction, or keep leading bits and
combine the rest into a sticky bit. This guarantee suffices for rounding at any
supported precision up to `p`, including onto the denormal grid. It does not
give the caller enough information for further arithmetic on the intermediate.
[Rounding proof](rounding.md#retained-and-discarded-bits)

## Inline and cold paths

Addition and multiplication handle normal pairs inline. Extended addition also
tests for a difference of magnitudes with equal or adjacent exponents. Those
differences can cancel by many bits and go to the cold path. Division and square
root normalize finite denormals before calling the same magnitude kernels used
for normal inputs.

A cold path packs its result into two words, retaining enough bits for final
rounding. Targets that return both words in registers avoid a store. On
`wasm32`, the result passes through memory.

### Inlining

Every function or method that a caller in another crate can invoke, with no type
or const parameters of its own or of its `impl`, carries `#[inline]`, so its
body reaches the caller whatever the caller's build.

### Operand order in addition

Binary64 addition uses `select_unpredictable` to choose the operand with the
larger exponent. LLVM emitted conditional moves, and addition was faster on
random pairs and slower when the larger operand always came first.

## NaNs and x86

The format recognizes a NaN from its encoding. The policy type supplies the
default NaN, signalling test, quieting and operand selection. Conversion uses a
common payload with the fraction aligned at the high end of a word. Each format
implements one export and one import, so each pair of formats can exchange a NaN
without a separate conversion rule.

The x86 facade selects the policy and implements the x87 and SSE unmasked range
responses. The instruction caller owns the masks, denormal-operand detection,
destination writes and flush to zero. This lets it choose the response after it
knows which exceptions occurred.