qFP16 is a compact fixed-point number library intended for use in embedded systems. It includes a variety of transcendental functions and essential operators, carefully chosen for optimal performance.
The format is a signed Q16.16, which is good enough for most purposes.
Datatype limits
The maximum representable value is 32767.999985. The minimum value is -32768.0
The minimum value is also used to represent fp16.overflow for overflow detection, so for some operations it cannot be determined whether it overflowed or the result was the smallest possible value. In practice, this does not matter much.
The smallest unit (machine precision) of the datatype is 1/65536=0.000015259.
Fixed-point functions
All the provided functions operate on 32-bit numbers, qFP16_t, which have 16-bit integer part and 16-bit fractional part.
Conversion functions
Conversion from integers and floating-point values. These conversions retain the numeric value and perform rounding where necessary.
qFP16_Sqrt() Square root. Performs rounding and is accurate to qFP16 limits.
qFP16_Exp() Exponential function using power series approximation. Accuracy depends on range, worst case +-40 absolute for negative inputs and +-0.003% for positive inputs. Average error is +-1 for neg and +-0.0003% for pos.
qFP16_Log() Natural logarithm using Newton approximation and qFP16_Exp(). Worst case error +-3 absolute, average error less than 1 unit.