Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > "long double" and "printf"

Reply
Thread Tools

"long double" and "printf"

 
 
Zero
Guest
Posts: n/a
 
      06-06-2006
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!

 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      06-06-2006
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
 
Reply With Quote
 
 
 
 
Zero
Guest
Posts: n/a
 
      06-06-2006

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

??

 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      06-06-2006
"Zero" <(E-Mail Removed)> 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
 
Reply With Quote
 
Dik T. Winter
Guest
Posts: n/a
 
      06-06-2006
In article <(E-Mail Removed). com> "Zero" <(E-Mail Removed)> 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/
 
Reply With Quote
 
Zero
Guest
Posts: n/a
 
      06-06-2006

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?

 
Reply With Quote
 
Zero
Guest
Posts: n/a
 
      06-06-2006

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?

 
Reply With Quote
 
Zero
Guest
Posts: n/a
 
      06-06-2006

Richard Bos wrote:
> "Zero" <(E-Mail Removed)> 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?

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      06-06-2006
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
 
Reply With Quote
 
Tim Prince
Guest
Posts: n/a
 
      06-06-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments