⚠️ This repository has moved to: https://gitlab.com/mbitsnbites/leanfloat
The latest release: LeanFloat Standard for Binary Floating-Point Arithmetic - v1.1
The current working draft: LeanFloat Standard for Binary Floating-Point Arithmetic - Draft
LeanFloat is a simplified version of the IEEE Standard for Floating-Point Arithmetic (IEEE 754).
For most intents and purposes it is compatible with the IEEE 754 standard, but with the following simplifications:
- Support for subnormal numbers is optional.
- Only a single rounding mode is supported: Round to nearest, ties to even (a.k.a. RTNE).
- Signaling NaNs (sNaN) are not supported. All NaNs are treated as quiet NaNs (qNaN).
- Floating-point exceptions are not supported. The default return value for an operation that would signal an exception is returned (e.g. sqrt(-1) returns qNaN).
- Decimal floating-point formats (e.g. decimal64) are not supported.
There are a number of driving motivations behind LeanFloat:
- Many existing systems, in particular SIMD/vector systems, do not fully support IEEE 754, but instead a subset that is equal to or very similar to LeanFloat. Yet, no proper common definition of this subset exists.
- Floating-point functionality is becoming increasingly popular in domains where full IEEE 754 compliance is neither necessary nor suitable (or even possible) due to hardware constraints. The LeanFloat specification aims to provide a least common denominator that can be targeted by such systems.
- For areas such as education and hobby and open source development where time and/or hardware constraints can be a limiting factor (e.g. if the target hardware is an FPGA with limited logic resources), LeanFloat can make floating-point functionality possible if a fully compliant IEEE 754 implementation would not be feasible.
- It is common for software programs to configure the FPU in a mode that is very similar to LeanFloat (e.g. disable subnormal numbers and floating-point exceptions), for the purpose of improved performance and/or compatibility with systems where full IEEE 754 functionality is not available.
Floating-point values produced by an IEEE 754 system can safely be used in a LeanFloat system, and vice versa.
Floating-point operations will behave identically on a LeanFloat system compared to an IEEE 754 system, as long as:
- The IEEE 754 system uses the default rounding mode.
- Floating-point exceptions are not used (see Caveats).
...and if subnormal numbers are not supported:
- No subnormal numbers are part of the floating-point operations (see Caveats).
A LeanFloat system is not 100% compatible with a fully compliant IEEE 754 system. In other words, software written against the IEEE 754 standard may not produce the same result when running on a LeanFloat system (and vice versa).
For example:
- Software that needs to trap on floating-point exceptions (e.g. to catch division by zero or overflow) may not function properly.
Additionally, the following caveats apply when subnormal numbers are not supported:
- If a LeanFloat system treats subnormal numbers as zeros, it has a slightly reduced numeric range. This can result in different computational results compared to an IEEE 754 system.
- Furthermore, the optional lack of support for subnormal numbers voids some of the guarantees provided by an IEEE 754 system. For instance, the relationship A != B => A - B != 0 does not hold for small numbers in a LeanFloat system without subnormals.