Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7939 Discussions

A potential divide by 0 is ignored by Intel C++ compiler ( no warning or remark displayed )

SergeyKostrov
Valued Contributor II
512 Views

Please investigate a potential divide by 0 is ignored by Intel C++ compiler ( v13.x / W5 level of warnings / no warning or remark displayed ). I've done a verification with Microsoft C++ compiler and it reports:

...
double dX = 1.0L;
double dResult = (-dX + dX )/(-dX + dX );
...

..\Common\PrtTests.cpp(21076) : warning C4723: potential divide by 0

...

Thanks in advance.

0 Kudos
5 Replies
TimP
Honored Contributor III
512 Views

If this compiles correctly, the result should be NaN, possibly set at compile time.

0 Kudos
SergeyKostrov
Valued Contributor II
512 Views
>>...If this compiles correctly, the result should be NaN, possibly set at compile time... Thanks, Tim. It compiles. I know that a result of the expression has to be equal to NaN and I'll do a verification if it sets at compile time. However, I really expected a warning or a remark from Intel C++ compiler especially when option /W5 is used. I'll also do a verification with option /Wcheck.
0 Kudos
Bernard
Valued Contributor I
512 Views

>>>double dResult = (-dX + dX )/(-dX + dX );>>>

If it compiles it should return a NAN.I used such a code to emulate a NaN returning to the caller.

0 Kudos
jimdempseyatthecove
Honored Contributor III
512 Views

In the event that the compiler (version you have) is faulty and returns 0.0 as opposed to NaN, then try using "volatile double dX = 1.0L;"

IOW force the compiler to generate code to perform the calculation (as opposed to having the optimization pre-compute the result).

Jim Dempsey

0 Kudos
SergeyKostrov
Valued Contributor II
512 Views
>>>>A potential divide by 0 is ignored by Intel C++ compiler... >> >>In the event that the compiler (version you have) is faulty and returns 0.0 as opposed to NaN... It doesn't return 0.0 and I didn't want to look or to take into account all the rest possible problems. Now, I confirm the problem and here are more details: Note: Verified with versions 12.x and 13.x of Intel C++ compiler on 32-bit and 64-bit Windows platforms. [ Test-Case 1 - /W5 /Wcheck options used ] ... double dX = 0.0L; dX = ( -1.0L + 1.0L )/( -1.0L + 1.0L ); dX = dX; ... [ COMPILATION Output 1 ] ... ..\DivTestApp.cpp(24): warning #39: division by zero dX = ( -1.0L + 1.0L )/( -1.0L + 1.0L ); ... [ Test-Case 2 - /W5 /Wcheck options used ] ... double dX = 1.0L; double dResult = ( -dX + dX )/( -dX + dX ); ... [ COMPILATION Output 2 ] No Warning
0 Kudos
Reply