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

icx 2021.3.0 bug: isinf wrong result

DominikT
Beginner
978 Views

Hello everyone,

there seems to be a bug with infinity numbers.

See this minimal example

 

#include <iostream>
#include <limits>
#include <cmath>

int main()
{
    std::cout << std::isinf(std::numeric_limits<double>::infinity());
}

 

If -O1 or higher is enabled, this puts out 0 with is wrong.

I am using the Intel(R) oneAPI DPC++/C++ Compiler 2021.3.0 (2021.3.0.20210619)

Here is a link to the code on compiler explorer:

https://godbolt.org/z/rvvcd4dfY

 

0 Kudos
1 Solution
Khalik_K_Intel
Moderator
894 Views

Hello,

Thank you for contacting Intel support.


The behavior you have experienced is expected. Let me explain in more details:

When you execute the compiler with -O1 or higher, the default compiler options are passed to compiler driver.

There is an option fp-model (https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html), which controls the semantics of floating-point calculations.


OneAPI 2021.2.0 has changed the default value for this option to -fp-model=fast (please see this page this this and other changes: https://software.intel.com/content/www/us/en/develop/articles/intel-oneapi-dpc-c-compiler-release-notes.html), which means the compiler can make various out-of-box optimizations for floating-point math (float or double). This made the compiler to use more aggressive optimizations on floating-point calculations compared to previous release. That is why you may observe 1 being returned with Intel® oneAPI DPC++/C++ Compiler 2021.1.2 and 0 being returned with Intel® oneAPI DPC++/C++ Compiler 2021.2 and newer.


If you wish to get the desired result (1 in your case), then you can use "-fp-model=strict" or "-fno-finite-math-only" options as follows:

$ icpx -O1 test.cpp -o test

$ ./test

0

$ icpx -O1 -fp-model=strict test.cpp -o test

$ ./test

1

$ icpx -O1 -fno-finite-math-only test.cpp -o test

$ ./test

1

However, we now understand that users may face this issue and if so, then they would like to understand why they get incorrect results. Therefore, A new warning would be introduced for such cases in the upcoming Intel® oneAPI release.

Hope that this helps.


Regards,

Khalik.


View solution in original post

0 Kudos
3 Replies
VarshaS_Intel
Moderator
939 Views

Hi,


Thanks for reporting us.


We are able to reproduce your issue. We are working on this internally and will get back to you soon.


Thanks & Regards

Varsha


0 Kudos
Khalik_K_Intel
Moderator
895 Views

Hello,

Thank you for contacting Intel support.


The behavior you have experienced is expected. Let me explain in more details:

When you execute the compiler with -O1 or higher, the default compiler options are passed to compiler driver.

There is an option fp-model (https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html), which controls the semantics of floating-point calculations.


OneAPI 2021.2.0 has changed the default value for this option to -fp-model=fast (please see this page this this and other changes: https://software.intel.com/content/www/us/en/develop/articles/intel-oneapi-dpc-c-compiler-release-notes.html), which means the compiler can make various out-of-box optimizations for floating-point math (float or double). This made the compiler to use more aggressive optimizations on floating-point calculations compared to previous release. That is why you may observe 1 being returned with Intel® oneAPI DPC++/C++ Compiler 2021.1.2 and 0 being returned with Intel® oneAPI DPC++/C++ Compiler 2021.2 and newer.


If you wish to get the desired result (1 in your case), then you can use "-fp-model=strict" or "-fno-finite-math-only" options as follows:

$ icpx -O1 test.cpp -o test

$ ./test

0

$ icpx -O1 -fp-model=strict test.cpp -o test

$ ./test

1

$ icpx -O1 -fno-finite-math-only test.cpp -o test

$ ./test

1

However, we now understand that users may face this issue and if so, then they would like to understand why they get incorrect results. Therefore, A new warning would be introduced for such cases in the upcoming Intel® oneAPI release.

Hope that this helps.


Regards,

Khalik.


0 Kudos
Khalik_K_Intel
Moderator
763 Views

This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread.

Any further interaction in this thread will be considered community only.


0 Kudos
Reply