fp64lib is a library for implementing 64-bit floating point arithmetic on the AVR MegaAVR architecure microprocessors, like the popular Arduino series. Data format is fully compatible with IEEE 754 binary64 standard (see Wikipedia):
- Sign bit: 1 bit
- Exponent: 11 bits
- Significand precision: 53 bits (52 explicitly stored)
All functions of fp64lib support
- signed 0 (zero)
- +Inf and -Inf
- subnormal numbers
To limit code size, not all features of IEEE 754 are implemented. The major differences are:
- There are no signaling NaNs, only quite NaNs.
- No exceptions are raised.
- Out of the five rounding modes, only Round to nearest, ties to even is implemented.
- Therefore, rounding modes cannot be controlled.
The library comes with a math.h compatible head file named “fp64-math.h”. All fp64lib routines start with “fp64_”, e.g. fp64_sin or fp64_add. Library is fully compatible to usual “math.h” routines, e.g.
- Basic arithmetic functions: fp64_add(), fp64_sub(), fp64_mul(), fp64_div(), fp64_fmod(), fp64_fma()
- Check and compare functions: fp64_isinf(), fp64_isnan(), fp64_isfinite(), fp64_compare(), fp64_signbit(), fp64_fmin(), fp64_fmax(), fp64_fdim()
- Basic functions: fp64_neg(), fp64_abs(), fp64_inverse(), fp64_sqrt(), fp64_square(), fp64_trunc(), fp64_ceil(), fp64_floor(), fp64_round(), fp64_lround(), fp64_lrint()
- Trigonometric functions and their inverse: fp64_sin(), fp64_cos(), fp64_tan(), fp64_asin(), fp64_acos(), fp64_atan(), fp64_hypot(),
- Conversion functions from and to float/double: fp64_sd(), fp64_ds()
- Conversion functions from and to integer: fp64_to_int64(), fp64_to_uint64, fp64_long_to_float64(), fp64_to_int32( ), fp64_to_uint32( ), fp64_to_int16( ), fp64_to_uint16(), fp64_to_int8() , fp64_to_uint8()
- Conversion functions from and to string: fp64_to_decimalExp(), fp64_strtod(), fp64_to_string()
- Logarithmic and hyperbel function: fp64_log(), fp64_exp(), fp64_log10(), fp64_sinh(), fp64_cosh(), fp64_tanh(), fp64_ldexp(), fp64_frexp(), fp64_pow(), fp64_cbrt()
Furthermore, the library is mostly compatible with the avr_f64.c library. To make conversion from your previous avr_f64.c project easy, a avr_fp64.h header file is supplied that converts calls to avr_f64 routine to calls to fp64lib routines. Beware however, that due to the extended support of IEE 754, that the behaviour of your program might differ slightly. But usally, you will only notice that your code runs 80% faster.
Source code of the library is available on GitHub, it can be downloaded here as an plug & play Arduino library. Library reference can be found in the documentation section.