Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
This code may produce a domain error if the argument is not in the range \[-1, \+1\].

Code Block
bgColor#FFcccc
float x, result;

result = acos(x);

...

This code uses bounds checking to ensure there is not a domain error.

Code Block
bgColor#ccccff
float x, result;

if( islessequal(x,-1) || isgreaterequal(x, 1) ){
     /* handle domain error */
}

result = acos(x);

...

This code may produce a domain error if both x and y are zero.

Code Block
bgColor#FFcccc
float x, y, result;

result = atan2(y, x);

...

This code tests the arguments to ensure that there is not a domain error.

Code Block
bgColor#ccccff
float x, y, result;

if( fpclassify(x) == FP_ZERO && fpclassify(y) == FP_ZERO){
     /* handle domain error */
}

result = atan2(y, x);

...

This code may produce a domain error if x is negative and a range error if x is zero.

Code Block
bgColorFFcccc
float result, x;

result = log(x);

...

This code tests the suspect arguments to ensure no domain or range errors are raised.

Code Block
bgColor#ccccff
float result, x;

if(islessequal(x, 0)){
     /* handle domain and range errors */
}

result = log(x);

...

This code may produce a domain error if x is zero and y less than or equal to zero. A range error may also occur if x is zero and y is negative.

Code Block
bgColor#FFcccc
float x, y, result;

result = pow(x,y);

...

This code tests x and y to ensure that there will be no range or domain errors.

Code Block
bgColor#ccccff
float x, y, result;

if(fpclassify(x) == FP_ZERO && islessequal(y, 0)){
     /* handle domain error condition */
}

result = pow(x, y);

...

This code may produce a domain error if x is negative.

Code Block
bgColor#FFcccc
float x, result;

result = sqrt(x);

...

This code tests the suspect argument to ensure no domain error is raised.

Code Block
bgColor#ccccff
float x, result;

if(isless(x, 0)){
     /* handle domain error */
}

result = sqrt(x);

...