softfpu
A safe Rust library implementing 32-, 64- and 80-bit software floating-point arithmetic, including Intel x87 transcendental functions.
At a Glance
softfpu Rust library released under the MIT license; free to use, copy, modify, merge, publish, distribute, sublicense and sell.
Engagement
Available On
Alternatives
Listed Dec 2026
About softfpu
softfpu is an MIT-licensed Rust crate by Roberto Thais that implements binary32, binary64 and x87 80-bit floating-point arithmetic in software. It uses integer arithmetic only, relies on core, and needs no allocator or global state. Its addition, subtraction, multiplication, division and square root are correctly rounded and report exception flags.
What It Is
softfpu is a software floating-point library for authors of emulators, compilers and verification tools who need bit-exact x87 and SSE behavior. The Single, Double and Extended types store raw bit patterns rather than host f32 or f64 values. They preserve NaN payloads, signed zeros and noncanonical 80-bit encodings such as unnormals, pseudo-NaNs, pseudo-infinities and pseudo-denormals.
The math module handles binary32 and binary64 arithmetic with round-to-nearest, ties to even. Each operation returns its value together with exception flags. The lower-level API lets callers choose the rounding mode, tininess rule and NaN policy.
How computation and rounding are separated
A core operation returns either a finished value with flags or an unfinished intermediate that the caller rounds. This lets the same intermediate be rounded for both masked and unmasked x87 exceptions, including the exponent adjustment used for unmasked overflow and underflow. Rounded results also report whether rounding increased the magnitude, which the x87 status word needs for C1, and whether the result was tiny.
NaN handling is pluggable through a nan::NanPolicy type parameter. The x86 layer supplies the x86 selection rules for SSE and x87, integer-indefinite results for failed conversions, and x87 precision control at 24, 53 and 64 bits.
x87 transcendentals and x86 extras
The x86 layer covers the eight x87 transcendental instructions (fsin, fcos, fsincos, fptan, fpatan, f2xm1, fyl2x, fyl2xp1). It also covers fscale, fxtract, fprem, fprem1, packed BCD instructions, the x87 constants and the SSE rcpss and rsqrtss approximations. The README states the x87 algorithms were reconstructed from the Intel SDM, Intel's paper on trigonometric range reduction, die-photo reading of the Pentium constant ROM and hardware measurements, and that several steps remain assumptions. The README reports that results matched Intel hardware on every operand tested.
Verification and performance
The project's tests include doc tests, an integer rounding model, NaN-policy tests, and a replay of 45,610 x87 transcendental results recorded on Intel hardware. An optional test run checks generated cases against Berkeley TestFloat. The README also reports benchmark comparisons against Berkeley SoftFloat 3e, natively and under wasm32.
Setup path
Add the crate with cargo add softfpu. API documentation is hosted on docs.rs, and the repository includes design notes on rounding, addition, multiplication, division, square root, conversions and transcendentals.
Collections
Collections with tools like softfpu
- Frameworks
Collection by @joemseifi · has Effect
Add softfpu to one of your collections.
Community Discussions
Be the first to start a conversation about softfpu
Share your experience with softfpu, ask questions, or help others learn from your insights.
Pricing
Open Source (MIT)
softfpu Rust library released under the MIT license; free to use, copy, modify, merge, publish, distribute, sublicense and sell.
- 32-, 64- and 80-bit floating-point arithmetic in safe Rust
- Bit-exact Intel x87 transcendental functions
- x86 NaN policies, rounding and tininess control
- No allocation or global state; uses only core
- MIT License
Capabilities
Key Features
- 32-, 64- and 80-bit software floating-point arithmetic in safe Rust
- Correctly rounded add, subtract, multiply, divide and square root with exception flags
- Raw bit-pattern Single, Double and Extended types preserving NaN payloads and noncanonical x87 encodings
- All eight x87 transcendental instructions
- Separation of computation from rounding for masked and unmasked x87 exceptions
- Rounding metadata including rounded-up and tiny indicators
- Pluggable NaN policies with x86 SSE and x87 selection rules
- x87 precision control at 24, 53 and 64 bits
- fscale, fxtract, fprem, fprem1 and packed BCD instruction support
- SSE rcpss and rsqrtss approximations
- No allocator or global state required, uses only core
- Tests against Berkeley TestFloat and recorded Intel hardware results
