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

Intel C++ for Windows bug in long double

Davies__Robert
Beginner
434 Views

Can someone pass this bug report to whoever handles bugs in the compiler since I have failed to find any way of reporting bugs.

Both cout << x and log(x) give wrong answers when x is declared long double. But various other functions including log10 are fine.

Here is the test program

int main()
{

   {
      cout << "Declaring two as double" << endl;
      double two = 2;
      double sqrt2 = (double)sqrt(two);
      double log2 = (double)log(two);
      double log10_2 = (double)log10(two);
      double exp2 = (double)exp(two);
      cout << "two        " << two << endl;
      cout << "sqrt(two)  " << sqrt2 << endl;
      cout << "log(two)   " << log2 << endl;
      cout << "log10(two) " << log10_2 << endl;
      cout << "exp(two)   " << exp2 << endl;
      cout << endl;
   }
   {
      cout << "Declaring two as long double" << endl;
      long double two = 2;
      double sqrt2 = (double)sqrt(two);
      double log2 = (double)log(two);
      double log10_2 = (double)log10(two);
      double exp2 = (double)exp(two);
      cout << "two        " << two << endl;
      cout << "sqrt(two)  " << sqrt2 << endl;
      cout << "log(two)   " << log2 << endl;
      cout << "log10(two) " << log10_2 << endl;
      cout << "exp(two)   " << exp2 << endl;
      cout << endl;
   }

   return 0;

and here is the output

Declaring two as double
two        2
sqrt(two)  1.41421
log(two)   0.693147
log10(two) 0.30103
exp(two)   7.38906

Declaring two as long double
two        1.38893e-312
sqrt(two)  1.41421
log(two)   -nan(ind)
log10(two) 0.30103
exp(two)   7.38906

This happens with both the 2018 and 2019 versions of the compiler. This is the line in the make file calling the compiler

icl -Qstd=c++17 -c -EHsc -GR -Ge -GS -Qprec -Qprec_div -nologo -Qlong_double -fp:precise $*.cpp -D__builtin_huge_val()=HUGE_VAL -D__builtin_huge_valf()=HUGE_VALF -D__builtin_nan=nan -D__builtin_nanf=nanf -D__builtin_nans=nan -D__builtin_nansf=nanf

It looks like a compiler bug rather than my error but it would be nice if anyone can assist.

Robert

 

0 Kudos
3 Replies
Viet_H_Intel
Moderator
434 Views

It's somehow related to -Qlong-double option. Can you remove /Qlong-double flag as a workaround?

Thanks,

Viet

 

C:\Temp\vah\testcase>icl -Qstd=c++17  -EHsc -GR -Ge -GS -Qprec -Qprec_div -nologo -Qlong_double -fp:precise test.cpp -D__builtin_huge_val()=HUGE_VAL -D__builtin_huge_valf()=HUGE_VALF -D__builtin_nan=nan -D__builtin_nanf=nanf -D__builtin_nans=nan -D__builtin_nansf=nanf
test.cpp

C:\Temp\vah\testcase>test.exe
Declaring two as double
two        2
sqrt(two)  1.41421
log(two)   0.693147
log10(two) 0.30103
exp(two)   7.38906

Declaring two as long double
two        1.29046e-312
sqrt(two)  1.41421
log(two)   -nan(ind)
log10(two) 0.30103
exp(two)   7.38906


C:\Temp\vah\testcase>icl -Qstd=c++17  -EHsc -GR -Ge -GS -Qprec -Qprec_div -nologo  -fp:precise test.cpp -D__builtin_huge_val()=HUGE_VAL -D__builtin_huge_valf()=HUGE_VALF -D__builtin_nan=nan -D__builtin_nanf=nanf -D__builtin_nans=nan -D__builtin_nansf=nanf
test.cpp

C:\Temp\vah\testcase>test.exe
Declaring two as double
two        2
sqrt(two)  1.41421
log(two)   0.693147
log10(two) 0.30103
exp(two)   7.38906

Declaring two as long double
two        2
sqrt(two)  1.41421
log(two)   0.693147
log10(two) 0.30103
exp(two)   7.38906

0 Kudos
TimP
Honored Contributor III
434 Views

ICL depends on the Microsoft run-time library, which doesn't support long double except as an alias for double. -Qlong_double is documented as not supported to this extent. sqrt(), when optimized with inline instructions, should be OK even if you don't provide your own long double implementation, although there are questionable aspects.  As you don't supply the required standard headers, you can't hope for the required down-casting from long double to double to happen implicitly for the run-time library functions.  Examples like this may work fine in linux but not with Windows.  

0 Kudos
Davies__Robert
Beginner
434 Views

Sorry - I didn't show the headers - these were the headers

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

One often wants to use long double in a numerical calculation involving sums of products to try to reduce round-off error. It was easy enough for me to change the code to convert back to double before taking the log, but it makes the code more complicated. Possibly I need a different version for the Windows Intel compiler and the other compilers.

But really, unless I have messed up somewhere this is a bug in the Intel compiler for Windows that needs fixing.

Robert

 

0 Kudos
Reply