AutosarC++17_03-M0.4.2¶
Use of floating-point arithmetic shall be documented
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | non-automated |
Rationale
The safe use of floating-point arithmetic requires a high level of numerical analysis skills and in-depth knowledge of the compiler and target hardware.
If floating-point is to be used, then the following issues need to be covered as part of the deviation process:
- A justification explaining why floating-point is the appropriate or only solution.
- Demonstrate that appropriate skills are available.
- Demonstrate that an appropriate process is being applied.
- Document the floating-point implementation.
The paper “What Every Computer Scientist Should Know about Floating-Point Arithmetic” explains the issues that need to be considered when using floating-point.
Example
When solving a quadratic equation, the value of b2–4.a.c is calculated. Assume that a=1.22, b=3.34, c=2.28 and that three significant digits are used during calculation. The exact value of b2–4.a.c is 0.0292. However, b2 rounds to 11.2 and 4.a.c rounds to 11.1, giving a final answer of 0.1. This example demonstrates catastrophic cancellation. The subtraction does not cause an error, but it does expose errors introduced in the multiplications that are used when generating its operands.
Note
For legal reasons, this rule’s description is not part of the public documentation.