...
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.
...
Code Block |
---|
float x, result;
if( x <= -1 || x >= 1){
/* handle domain error */
}
result = acos(x);
|
atan2
Non-Compliant Solution
The following code may produce a domain error if both x and y are zero.
Code Block |
---|
float x, y, result;
result = atan2(y, x);
|
Compliant Solution
The following code tests the arguments to ensure that there is not a domain error.
Code Block |
---|
float x, y, result; if( x == 0 && y == 0){ /* handle domain error */ } result = atan2(y, x); |
pow(x,y)
Non-Compliant Example
...
Code Block |
---|
float x, y, result; result = pow(x,y); |
Compliant Solution
The following code tests x and y to ensure that there will be no range or domain errors.
...