Floating point (FP) is implemented for MIDRANGE, ENHANCED mid-range and HIGHPERF (PIC18).
Using FP in non-constant expressions with other processors will produce compilation errors.
FP may be used in a constant expression evaluation for any processor, only the FP code generation is not implemented for BASELINE devices.
PMP's FP uses routines based on a port of the excellent FP package called PicFloat from Mike Gore, which may be found on the net. It has been completely rewritten to be adapted to PMP's internal logic.
PMP supports two FP formats: REAL (proprietary) and SINGLE (IEEE 754 compatible). The standard IEEE 64-bit DOUBLE format is not supported.
The proprietary REAL format is an optimized 48-bit (6 bytes) format, giving a pretty 32-bit plus sign mantissa, the full format is:
<SIGN><EXP><MANTISSA> ::= [7..0] [7..0] [31..0]
►This format gives 9.4 (9 to 10) digits of accuracy with an exponent up to ± 2127 (± 1.7E38).
In the MSB only one bit is used for <SIGN>, 7 bits are reserved for future implementations.
compare with the 23 bits plus sign of the SINGLE 32-bit (4 bytes) IEEE 754 format:
<SIGN><EXP><MANTISSA> ::= [31] [30..23] [22..0]
►This format gives 7.1 (7 to 8) digits accuracy with an exponent up to ± 2127 (± 1.7E38).
Assigning a 32-bit integer to a SINGLE implies a loss of precision (SINGLE has only a 23-bit + sign mantissa). |
During compilation, PMP uses internally a 64-bit DOUBLE format that is converted to the appropriate format according to generated statements.
The user code may use variables in 32-bit SINGLE format but it is systematically converted to the REAL format when a call to a FP routine is needed (simple + - * / operators or a call to any FP function).
Assignment of a SINGLE variable with a SINGLE constant does not generate a conversion.
PMP does not have an internal representation for NaN (Not a Number) or infinity.
Overflow may be trapped as an error and the maximum FP value is returned instead of infinity.
If an error occurs, the ERROR procedure is called if any has been assigned.