This chapter presents an implementation of the floating point arithmetic as described in the IEEE-754 standard. The following floating point routines for the S12Z device family are implemented. Refer the standard for detailed description of their functionality
- Basic floating point operations for single precision and double precision: addition, subtraction, multiplication, division
- Conversion to and from integer (16-bit, 32-bit and 64-bit) and floating point format (32-bit and 64-bit).
- Conversion between 32-bit and 64-bit floating point
- Comparison functions
- ANSI functions: frexp/f, ldexp/f, modf/f for single and double precision
- Functions for manipulating exception flags: saveAllFlags, restoreFlags, testFlags, testSavedFlags, lowerFlags, and raiseFlags.
Floating point functions are provided in the form of libraries and source code, both C and assembly. The implementation is ready for use with the CodeWarrior compiler.
The implementation demonstrates a good balance between functionality and performance and for this reason does not strictly follow the floating point standard. In particular, the implementation provides several library variants, each of them differing in compliance level to the standard.
Table 1. ansif and ansid Library Features | Features |
ansif |
ansifc |
ansid |
ansidc |
| 64-bit double |
No |
No |
Yes |
Yes |
| Rounding |
None |
Round to the nearest even |
None |
Round to the nearest even |
| Non-numerical values |
Yes |
Yes |
Yes |
Yes |
| Sub-normal values |
Yes |
Yes |
Yes |
Yes |
| Exceptions |
No |
Yes |
No |
Yes |
| ANSI functions |
Yes |
Yes |
Yes |
Yes |
- ansif.lib: This library is the smallest and generally the fastest. The double type is mapped to 32-bit. Apart from basic functionality (arithmetic operations, conversions), this version can handle denormalized numbers, as well as non-numerical values.
- ansidr.lib / ansidm.lib*: This library provides the best compromise between functionality and performance. It is a bare bone implementation of the standard with double precision capabilities. Denormalized numbers and non-numerical values are supported.
- ansidr.lib / ansidm.lib: This library offers a good level of IEEE-754 standard compliance, without sacrificing much on performance. This version supports rounding, namely the "round to nearest even number" rounding mode. Additionally, it offers support for exception flags (overflow, underflow, inexact, invalid, divide by zero). Comparisons with NaNs (unordered comparisons) behave according to the standard.
Note: "r"-suffixed and "m"-suffixed libraries differ in terms of calling convention for 64-bit data types. Depending on the -bit64_code_gen option supplied to the compiler, the appropriate library must be linked: ansidr(c) for a register-based calling convention and ansidm(c) for a stack-based calling convention.
Note: A detailed discussion regarding use of the different floating point features imposed by the IEEE-754 standard is beyond the scope of this chapter and shall not be provided. However, users are reminded that this subject is non-trivial. It is recommended that users familiarize themselves with the appropriate literature in order to use such features correctly.