Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7700 Discussions

icx 2021.3.0 bug: isinf wrong result

DominikT
Beginner
667 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
583 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-gui...), 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-no...), 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

3 Replies
VarshaS_Intel
Moderator
628 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


Khalik_K_Intel
Moderator
584 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-gui...), 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-no...), 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.


Khalik_K_Intel
Moderator
452 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.


Reply