473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
*/
}
Jul 22 '05 #1
5 22846
Piotr B. wrote:

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.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #2
Ioannis Vranos wrote:
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
*/
}
Jul 22 '05 #3
"Ioannis Vranos" <iv*@guesswh.at.grad.com> wrote in message
news:1098183261.455403@athnrd02...
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
Jul 22 '05 #4
P.J. Plauger wrote:
"Ioannis Vranos" <iv*@guesswh.at.grad.com> wrote in message
news:1098183261.455403@athnrd02...

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.


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.
Jul 22 '05 #5
Piotr B. wrote:
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
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Adam Ierymenko | last post by:
I have a question that might have been asked before, but I have not been able to find anything via groups.google.com or any web search that is definative. I am writing an evolutionary AI...
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
6
by: Piotr B. | last post by:
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...
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
3
by: ext | last post by:
"A "long" in C is an "int" in C#." Does this mean that whenever passing a parameter to a C function which expects a long type, the variable on C# side should be declared as int type? What if...
7
by: Jo Deni | last post by:
Folks, I'm a newbie here (and with C++). While executing a C++ program I'm getting the following message error: integer constant is too large for "long" type and here is the offending line...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.