473,796 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 23105
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@athnrd0 2...
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@athnrd0 2...

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
3950
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 application in C++. I want to use 32-bit integers, and I want the application to be able to save it's state in a portable fashion. The obvious choice would be to use the "long" type, as it is deined to be at least 32 bits in size. However, the...
22
3726
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 wintel compilers support a 16-byte "long double" (with 33 decimal digits of accuracy) including proper printf() support. I found some compilers that did support "long double", but theirs was an 8-byte or 10-byte or 12-byte type with accuracy the...
6
594
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 worked... The same source compiled with Borland C++Builder 5.0 works for %Lf format. How to get the same results with MinGW g++ ?
12
43472
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: printf("\n%20s\t%7u\t%13i\t%13i","signed int",sizeof(signed int),INT_MIN,INT_MAX);
3
7303
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 in the following case, should the parameter "level" be type of int as well? public interface XoInterface {
7
7538
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 in my code double X = 10000000000;
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.