Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and GDB*
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
443 Discussions

std::isfinite(INFINITY) returns true on Linux

AJIOB
Novice
806 Views

Hello

 

I'm using Intel oneAPI 2022.1.3 from APT on Ubuntu 20.04 LTS x64 English (Linux-based).

 

I got example code of std::isfinite() from cppreference, compile them with DPC++ 2022.0.0.20211123 and it works incorrectly on Linux: not as C++ standard wants.

 

Linux build & execution log was attached.

 

Linux output:

 

isfinite(NaN) = true
isfinite(Inf) = true
isfinite(0.0) = true
isfinite(exp(800)) = true
isfinite(DBL_MIN/2.0) = true

 

Windows version of DPC++ generates correct output:

 

isfinite(NaN) = false
isfinite(Inf) = false
isfinite(0.0) = true
isfinite(exp(800)) = false
isfinite(DBL_MIN/2.0) = true

 

Example code was attached as a test.cpp file in test.zip too.

 

Code was compiled with command dpcpp test.cpp -o test

 

How can I fix that behavior?

 

With regards,
Alex

Labels (1)
0 Kudos
6 Replies
NoorjahanSk_Intel
Moderator
699 Views

Hi,

 

Thanks for reaching out to us.

 

>>How can I fix that behavior?

 

Could you please try with below command as it worked (as expected) from our end.

 

dpcpp test.cpp -fp-model=precise -o test

 

Please find the below screenshot for more details.

NoorjahanSk_Intel_0-1648459214066.png

 

"-fp-model=precise" disables the optimization for floating-point calculations, so that the result won't be changed.

 

Please refer to below link for more details.

https://www.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

 

 

 

Thanks & regards,

Noorjahan.

 

AJIOB
Novice
679 Views

Hi Noorjahan,

 

Yes, you are right, that flag was helpful for fixing behavior on Linux.

 

But I need to have maximum speed for Linux & Windows with equal & correct behaviour.

 

What about fixing an optimized version?

 

With regards,
Alex

VinInn
Beginner
571 Views

I advice to test this version [1] as the original has the risk that everything is computed at compile time (try in godbolt for instance)

with Ofast (aka finite-math) one DOES expect isfinite(NAN) to be true

 

with latest gcc I get

c++ -O3 isfinite.cpp; ./a.out
isfinite(NaN) = false
isfinite(Inf) = false
isfinite(0.0) = true
isfinite(exp(800)) = false
isfinite(DBL_MIN/2.0) = true
x = 0
isfinite(0.f/x) = false
isfinite(1.f/x) = false
isfinite(x) = true
isfinite(exp(x)) = true
isfinite(DBL_MIN/x) = false

 

c++ -Ofast isfinite.cpp
 ./a.out

isfinite(NaN) = false
isfinite(Inf) = false
isfinite(0.0) = true
isfinite(exp(800)) = true
isfinite(DBL_MIN/2.0) = true
x = 0
isfinite(0.f/x) = true
isfinite(1.f/x) = true
isfinite(x) = true
isfinite(exp(x)) = true
isfinite(DBL_MIN/x) = true

 

[1]

#include <iostream>
#include <cmath>
#include <cfloat>

int main(int argc, char**)
{


float x = 1.f -float(argc);


std::cout << std::boolalpha
<< "isfinite(NaN) = " << std::isfinite(NAN) << '\n'
<< "isfinite(Inf) = " << std::isfinite(INFINITY) << '\n'
<< "isfinite(0.0) = " << std::isfinite(0.0) << '\n'
<< "isfinite(exp(800)) = " << std::isfinite(std::exp(800)) << '\n'
<< "isfinite(DBL_MIN/2.0) = " << std::isfinite(DBL_MIN/2.0) << '\n';


std::cout << std::boolalpha
<< "x = " << x << '\n'
<< "isfinite(0.f/x) = " << std::isfinite(0.f/x) << '\n'
<< "isfinite(1.f/x) = " << std::isfinite(1.f/x) << '\n'
<< "isfinite(x) = " << std::isfinite(0.0) << '\n'
<< "isfinite(exp(x)) = " << std::isfinite(std::exp(x)) << '\n'
<< "isfinite(DBL_MIN/x) = " << std::isfinite(DBL_MIN/x) << '\n';

 

NoorjahanSk_Intel
Moderator
620 Views

Hi,


We are working on your issue. We will get back to you soon.


Thanks & Regards,

Noorjahan


DMITRY_T_Intel
Employee
611 Views

Hi Alex,

I escalated this issue to development. I will update it as soon as I get any information.

Thanks!


DMITRY_T_Intel
Employee
555 Views

Hi Alex,

I got reply from developers:

"Use of dpcpp or icpx uses Intel defaults, which includes -fp-model=fast. This behavior is expected."

Thanks!


Reply