Prevent math errors by carefully bounds-checking before calling functions. In particular, the following domain errors should be prevented by prior bounds-checking:
Function Bounds-checking acos(x), asin(x) -1 <= x && x <= 1 atan2 x != 0 || y != 0 log, log10 x >= 0 pow(x, y) x != 0 || y >= 0 sqrt(x) x >= 0
The calling function should take alternative action if these bounds are violated.
Non-Compliant Example
Compliant Solution
References
- ISO/IEC 9899-1999 7.12 Mathematics <math.h>
- Plum 91 Topic: 2.10 conv - conversions and overflow