473,224 Members | 1,382 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,224 software developers and data experts.

"long double" and "printf"

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);

But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.

Thanks for your help!

Jun 6 '06 #1
12 43339
Zero wrote:

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);

But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.


For something like that,
you should try to post a complete program.

/* BEGIN new.c */

#include <stdio.h>
#include <float.h>

int main(void)
{
printf("%s\n%u\n%Le\n%Le\n",
"long double",
(unsigned)sizeof(long double),
LDBL_MIN,
LDBL_MAX);
return 0;
}

/* END new.c */
--
pete
Jun 6 '06 #2

pete wrote:
Zero wrote:

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);

But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.


For something like that,
you should try to post a complete program.

/* BEGIN new.c */

#include <stdio.h>
#include <float.h>

int main(void)
{
printf("%s\n%u\n%Le\n%Le\n",
"long double",
(unsigned)sizeof(long double),
LDBL_MIN,
LDBL_MAX);
return 0;
}

/* END new.c */
--
pete


Thanks for your help. But i still get this message:

long double
12
0.000000e+000
-1.#QNAN0e+000

??

Jun 6 '06 #3
"Zero" <ch********@web.de> wrote:
But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.


AFAICT this is a bug in Dev-C++. Their library and their headers don't
match on this detail. One (IIRC the header) thinks long doubles are
larger than doubles, the other (IIRC the printf() code) thinks they're
as large as doubles.

Richard
Jun 6 '06 #4
In article <11*********************@h76g2000cwa.googlegroups. com> "Zero" <ch********@web.de> writes:
....
Thanks for your help. But i still get this message:

long double
12
0.000000e+000
-1.#QNAN0e+000


Some older compilers did use 'll' in stead of 'L' for long double.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Jun 6 '06 #5

Zero wrote:
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);

But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.

Thanks for your help!


I just tried the code with Visual C++ and there it seems
that there is no difference between double and long double?

Bloodshed says long double consists of 12 Bytes, Visual C++ says 12.
What is right now?

Jun 6 '06 #6

Zero wrote:
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);

But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.

Thanks for your help!


I just tried the code with Visual C++ and there it seems
that there is no difference between double and long double?

Bloodshed says long double consists of 12 Bytes, Visual C++ says 8.
What is right now?

Jun 6 '06 #7

Richard Bos wrote:
"Zero" <ch********@web.de> wrote:
But what do I have to do when I want to print out the numbers of data
type "long double".

I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.


AFAICT this is a bug in Dev-C++. Their library and their headers don't
match on this detail. One (IIRC the header) thinks long doubles are
larger than doubles, the other (IIRC the printf() code) thinks they're
as large as doubles.

Richard


How do you know that this is a bug? Is there a side, where this
information can be fetched?

Jun 6 '06 #8
Zero wrote:

<snip>
I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.

Thanks for your help!


I just tried the code with Visual C++ and there it seems
that there is no difference between double and long double?

Bloodshed says long double consists of 12 Bytes, Visual C++ says 8.
What is right now?


Both. The C standard does not mandate exact sizes only minimums.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Jun 6 '06 #9
Flash Gordon wrote:
Zero wrote:

<snip>
I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0

Does anybody has a solution.

I tried this with Bloodshed using the gnu-compiler.

Thanks for your help!


I just tried the code with Visual C++ and there it seems
that there is no difference between double and long double?

Bloodshed says long double consists of 12 Bytes, Visual C++ says 8.
What is right now?


Both. The C standard does not mandate exact sizes only minimums.

Besides, the amount of unused storage doesn't directly answer your
problem. Few of us would know whether specifying Bloodshed implies a
specific version of gcc and run-time library. Run-time libraries
associated with Windows versions of gcc which I have used didn't
implement 10-byte long double in printf(), even though it might be
supported in terms of basic operators. If it uses Visual C++ printf(),
evidently there will be no support for more than 8-byte data type.
Jun 6 '06 #10
"Dik T. Winter" <Di********@cwi.nl> wrote in message
news:J0********@cwi.nl...
In article <11*********************@h76g2000cwa.googlegroups. com> "Zero"
<ch********@web.de> writes:
...
Thanks for your help. But i still get this message:

long double
12
0.000000e+000
-1.#QNAN0e+000
Some older compilers did use 'll' in stead of 'L' for long double.


I guess that he is using the GCC MINGW compiler which creates 80 bit
hardware long doubles, but which the Microsoft runtime libraries do not
match (for MS VC++ double and long double are the same type).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland,
+31205924131
home: bovenover 215, 1025 jn amsterdam, nederland;
http://www.cwi.nl/~dik/

Jun 6 '06 #11
pete a écrit :

For something like that,
you should try to post a complete program.

/* BEGIN new.c */

#include <stdio.h>
#include <float.h>

int main(void)
{
printf("%s\n%u\n%Le\n%Le\n",
"long double",
(unsigned)sizeof(long double),
LDBL_MIN,
LDBL_MAX);
return 0;
}

/* END new.c */

This produces:
long double
12
3.362103e-4932
1.189731e+4932

with lcc-win32
Jun 6 '06 #12
"Zero" <ch********@web.de> wrote:
Richard Bos wrote:
"Zero" <ch********@web.de> wrote:
I tried
printf("\n%20s\t%7u\t%13Lf\t%13Lf","long double",sizeof(long
double),LDBL_MIN,LDBL_MAX);
but this results in

long double 12 0.000000 -1.#QNAN0
AFAICT this is a bug in Dev-C++. Their library and their headers don't
match on this detail. One (IIRC the header) thinks long doubles are
larger than doubles, the other (IIRC the printf() code) thinks they're
as large as doubles.


How do you know that this is a bug?


For starters, because the behaviour you observe is not correct. There
was a c.l.c thread on this very problem some time ago; if you search for
it I'm sure you can find it. In that thread, some people (including me)
did some experiments and concluded that it had to be a mismatch
somewhere in Dev-C++.

Richard
Jun 8 '06 #13

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

Similar topics

5
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...
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...
2
by: Jude | last post by:
here is the source code: #include<stdio.h> int main() { float f; scanf("%d%f",&f); printf("The float is %10.5f\n",f); return 0; } when I input 12345.11111,the output is 12345.11133.
6
by: bananaguyc | last post by:
Okay, I'm running the following code in GCC 4.1.2: <stdio.h> int main(void) { long double test = 4.67e-4; printf("float: %f e-notation: %e\n", test, test); return 0; }
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split 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.