Versions Compared

Key

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

...

Code Block
float x, result;

if( x <= -1 || x >= 1){
     /* handle domain error */
}

result = acos(x);

atan2(y, x)

Non-Compliant Solution

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

...

Code Block
float x, y, result;

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

result = atan2(y, x);

log(x), log10(x)

Non-Compliant Example

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

Code Block

float result, x;

result = log(x);

Compliant Example

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

Code Block

float result, x;

if(x <=0){
     /* handle domain and range errors */
}

result = log(x);

pow(x,y)

Non-Compliant Example

...

Code Block
float x, y, result;

if(x == 0 && y <=0){
     /* handle domain error condition */
}

result = pow(x, y);

Sqrt(x)

Non-Compliant Solution

The following code may produce a domain error if x is negative.

Code Block

float x, result;

result = sqrt(x);

Compliant Solution

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

Code Block

float x, result;

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

result = sqrt(x);

References