Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Bakhvalov__Pavel
Beginner
51 Views

Division by zero inside if(0) clause

Hello!

I encounter the strange behavior of the Intel C++ Compiler. 

The following program generates "Floating point exception" if optimization (at least -O1) is enabled:

#include <fenv.h>
#include <stdio.h>
int j = 0;
int main(int argc, char *argv[]){
    feenableexcept( FE_DIVBYZERO );
    double r = 0.0;
    for(int k=0; k<2; k++) {
        double A[3] = {0.,0.,0.};
        if(j) A[0] -= 1.0/r;
        printf("A = %e %e %e\n", A[0], A[1], A[2]);
    }    
}

Linux, 64bit. Compiler version: icc (ICC) 16.0.1 20151021.

If the optimization is disabled, no exception is generated. gcc also generates no exception.

Is everything correct?

0 Kudos
2 Replies
Viet_H_Intel
Moderator
51 Views

Hi,

I'll look into it further. In the mean time, can you use -fp-model strict?

Thanks,

Viet

Bakhvalov__Pavel
Beginner
51 Views

When compiled with option -fp-model strict, the result is as it should be:
A = 0.000000e+00 0.000000e+00 0.000000e+00
A = 0.000000e+00 0.000000e+00 0.000000e+00

Reply