Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Piotr B.
Guest
 
Posts: n/a
#1: Jul 22 '05
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
*/
}

Ioannis Vranos
Guest
 
Posts: n/a
#2: Jul 22 '05

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


Piotr B. wrote:[color=blue]
>
> 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
> */
> }[/color]


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.



--
Ioannis Vranos

http://www23.brinkster.com/noicys
Piotr B.
Guest
 
Posts: n/a
#3: Jul 22 '05

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


Ioannis Vranos wrote:[color=blue]
> MINGW is broken regarding long double.[/color]

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.J. Plauger
Guest
 
Posts: n/a
#4: Jul 22 '05

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


"Ioannis Vranos" <ivr@guesswh.at.grad.com> wrote in message
news:1098183261.455403@athnrd02...
[color=blue]
> 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.[/color]

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.
[color=blue]
> 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.[/color]

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


jacob navia
Guest
 
Posts: n/a
#5: Jul 22 '05

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


P.J. Plauger wrote:[color=blue]
> "Ioannis Vranos" <ivr@guesswh.at.grad.com> wrote in message
> news:1098183261.455403@athnrd02...
>
>[color=green]
>>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.[/color]
>
>
> 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.
>[/color]

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.
Martin Ambuhl
Guest
 
Posts: n/a
#6: Jul 22 '05

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


Piotr B. wrote:[color=blue]
> 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++ ?[/color]


#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
Closed Thread