0

I use Microsoft Visual Studio 2010 and Intel C++ Compiler XE 14.0. Project configuration is ‘x64’. I need to work with the long double data type. I added a compile option /Qlong_double and wrote a test example:

    long double ld = 2;
    long double res = std::sqrt(ld);
    printf("long double size: %i, value: %Lf", sizeof(res), res);
    printf("double value of res: %f", (double)res);

Output:

long double size: 16, value: 0,000000

double value of res: 1,414214

I found that the problem is that standard C libraries for Windows does not support long double. Tried to use MPFR:

    long double ld = 2;
    long double res = std::sqrt(ld);
    mpfr_t test;
    mpfr_init2(test, 100);
    mpfr_set_ld(test, res, GMP_RNDN);
    mpfr_printf("\nmpfr long double: %Rf\n", test); 

Output:

mpfr long double: 0

Is there no of the method (including low-level ways) to correctly print long double values on Microsoft Windows? Maybe i can retrieve and print separate significand and exponent?

UPD:

I wrote example to see whether calculations are performed with long double:

     int count = 0;
     long double e = static_cast<long double>(1.0);
     while (static_cast<long double>(1.0) + e / static_cast<long double>(2.0) > static_cast<long double>(1.0)){
         e /= static_cast<long double>(2.0);
         count++;
     }
     cout<< endl<< "COUNT LONG DOUBLE: " << count<<endl;

     double de = 1.0;
     count = 0;
     while (1.0 + de / 2.0 > 1.0){
         de /= 2.0;
         count++;
     }
     cout<< endl<< "COUNT DOUBLE: " << count<<endl;

Output:

COUNT LONG DOUBLE: 52

COUNT DOUBLE: 52

This means that work is done with double instead of long double (although /Qlong_double flag is set). What are some ideas?

Community
  • 1
  • 1
Konstantin Isupov
  • 199
  • 1
  • 2
  • 12
  • I think you'll need to study the Intel compiler's documentation, and possibly support groups. It sounds like it's using the Visual C++ compiler's standard library? Note that with Visual C++ a `long double` is just a 64-bit IEEE format float, same as `double`. – Cheers and hth. - Alf Mar 08 '15 at 15:13
  • 1
    I had to delete my answer because I had missed that point that long double is 128 bit with the Intel compiler. – Kit Fisto Mar 08 '15 at 15:30
  • 1
    @Cheersandhth.-Alf I found the following: "ICC uses under Windows Microsoft's CRT library, and Microsoft decided not to support long double. This topic was discussed here many times. I use long double extensively, but before C++'s "cout << ld_number" or "printf" and friends, you need to, sadly, cast it to double. I'm not happy with this situation as well :-(." (https://software.intel.com/en-us/forums/topic/372720) – Konstantin Isupov Mar 08 '15 at 20:37

0 Answers0