...
Code Block |
---|
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
Code Block |
---|
float x, y, result;
result = pow(x,y);
|
Compliant Solution
Code Block |
---|
float x, y, result;
if(x == 0 && y <=0){
/* handle domain error condition */
}
result = pow(x, y);
|
References
- ISO/IEC 9899-1999 7.12 Mathematics <math.h>
- Plum 91 Topic: 2.10 conv - conversions and overflow