Printing "long double" type via printf() on MinGW g++ 3.2.3

P

Piotr B.

Hello,

I use MingGW g++ 3.2.3 on Windows 2000/AMD Athlon XP.
I tried to output a "long double" variable using stdio printf().
I've tried various %formats (%llf, %Lf etc.), but none of them worked...

The same source compiled with Borland C++Builder 5.0
works for %Lf format.

How to get the same results with MinGW g++ ?



#include <stdio.h>
int main()
{
long double x = 1.5;
printf("%llf %llf %llf %llf\n", x, x, x, x);
printf("%Lf %Lf %Lf %Lf\n", x, x, x, x);
printf ("%Le %LE %Lf %LF %Lg %LG\n", x, x, x, x, x, x);
return 0;

/*
MinGW g++ 3.2.3 output (all wrong):
-2.000000 0.000000 0.000000 -2.000000
-2.000000 0.000000 0.000000 -2.000000
-2.000000e+000 8.094277E-320 0.000000 -2 8.09428E-320

Borland C++Builder 5.0 output (%Lf works):
-2.000000 0.000000 0.000000 -2.000000
1.500000 1.500000 1.500000 1.500000
1.500000e+00 1.500000E+00 1.500000 %LF %Lg %LG
*/
}
 
I

Ioannis Vranos

Piotr said:
Hello,

I use MingGW g++ 3.2.3 on Windows 2000/AMD Athlon XP.
I tried to output a "long double" variable using stdio printf().
I've tried various %formats (%llf, %Lf etc.), but none of them worked...

The same source compiled with Borland C++Builder 5.0
works for %Lf format.

How to get the same results with MinGW g++ ?



#include <stdio.h>
int main()
{
long double x = 1.5;
printf("%llf %llf %llf %llf\n", x, x, x, x);
printf("%Lf %Lf %Lf %Lf\n", x, x, x, x);
printf ("%Le %LE %Lf %LF %Lg %LG\n", x, x, x, x, x, x);
return 0;

/*
MinGW g++ 3.2.3 output (all wrong):
-2.000000 0.000000 0.000000 -2.000000
-2.000000 0.000000 0.000000 -2.000000
-2.000000e+000 8.094277E-320 0.000000 -2 8.09428E-320

Borland C++Builder 5.0 output (%Lf works):
-2.000000 0.000000 0.000000 -2.000000
1.500000 1.500000 1.500000 1.500000
1.500000e+00 1.500000E+00 1.500000 %LF %Lg %LG
*/
}


MINGW is broken regarding long double. I had reported this myself some
time ago, and in summary here is what is going on:

In Windows world double and long double is the same. However in MINGW
long double is larger than double, however (I do not know more
specifics) it can print only the long double of MS Windows, that is the
double.

They are using an MS library or something.


You have two options. Either stick to double which is the same in
Windows world, or use DJGPP which is another GCC port (but creates
32-bit DOS executables).

Or use some other compiler.
 
P

Piotr B.

Ioannis said:
MINGW is broken regarding long double.

Thank you...
"long long" seem to be broken, too:



#include <stdio.h>
int main()
{
long long x = 123;
printf("%lld %lld %lld %lld\n", x, x, x, x);
printf("%Ld %Ld %Ld %Ld\n", x, x, x, x);

/*
MinGW g++ 3.2.3 output (all wrong):
123 0 123 0
123 0 123 0
*/
}
 
P

P.J. Plauger

MINGW is broken regarding long double. I had reported this myself some
time ago, and in summary here is what is going on:

In Windows world double and long double is the same. However in MINGW long
double is larger than double, however (I do not know more specifics) it
can print only the long double of MS Windows, that is the double.

They are using an MS library or something.

No, they are using their own C library, which has many faults.
Aside from any formatting omissions, they fail to set the state
of the FPP reliably. Hence, long double results flap in the
breeze.
You have two options. Either stick to double which is the same in Windows
world, or use DJGPP which is another GCC port (but creates 32-bit DOS
executables).

Or use some other compiler.

Or use some other library. Mingw works fine with our library --
we use it all the time in our development and testing.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
J

jacob navia

P.J. Plauger said:
No, they are using their own C library, which has many faults.
Aside from any formatting omissions, they fail to set the state
of the FPP reliably. Hence, long double results flap in the
breeze.

As far as I know they use crtdll.dll, the C library provided
by the windows OS.
This library is at the stand of C89.
 
R

Ron Natalie

Piotr said:
Hello,

I use MingGW g++ 3.2.3 on Windows 2000/AMD Athlon XP.
I tried to output a "long double" variable using stdio printf().
I've tried various %formats (%llf, %Lf etc.), but none of them worked...
There is no such type as long long in C++.
 
M

Martin Ambuhl

Piotr said:
Hello,

I use MingGW g++ 3.2.3 on Windows 2000/AMD Athlon XP.
I tried to output a "long double" variable using stdio printf().
I've tried various %formats (%llf, %Lf etc.), but none of them worked...

The same source compiled with Borland C++Builder 5.0
works for %Lf format.

How to get the same results with MinGW g++ ?


#include <stdio.h>
int main()
{
long double x = 1.5;
#if 0
/* mha: the 'll' modifier is for integral types */
printf("%llf %llf %llf %llf\n", x, x, x, x);
#endif
printf("%Lf %Lf %Lf %Lf\n", x, x, x, x);
/* mha: removed silly %LF specifier */
printf("%Le %LE %Lf %Lg %LG\n", x, x, x, x, x);
return 0;
}

[output]
1.500000 1.500000 1.500000 1.500000
1.500000e+00 1.500000E+00 1.500000 1.5 1.5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top