Connecting Tech Pros Worldwide Help | Site Map

"long double" and "printf"

 
LinkBack Thread Tools Search this Thread
  #1  
Old June 6th, 2006, 01:25 PM
Zero
Guest
 
Posts: n/a
Default "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!


  #2  
Old June 6th, 2006, 01:45 PM
pete
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

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

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
  #3  
Old June 6th, 2006, 02:05 PM
Zero
Guest
 
Posts: n/a
Default Re: "long double" and "printf"


pete wrote:[color=blue]
> Zero wrote:[color=green]
> >
> > 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.[/color]
>
> 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[/color]

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

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

??

  #4  
Old June 6th, 2006, 02:05 PM
Richard Bos
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

"Zero" <chefmuetze@web.de> wrote:
[color=blue]
> 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.[/color]

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
  #5  
Old June 6th, 2006, 02:25 PM
Dik T. Winter
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

In article <1149602363.679848.32320@h76g2000cwa.googlegroups. com> "Zero" <chefmuetze@web.de> writes:
....[color=blue]
> Thanks for your help. But i still get this message:
>
> long double
> 12
> 0.000000e+000
> -1.#QNAN0e+000[/color]

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/
  #6  
Old June 6th, 2006, 02:25 PM
Zero
Guest
 
Posts: n/a
Default Re: "long double" and "printf"


Zero wrote:[color=blue]
> 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![/color]

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?

  #7  
Old June 6th, 2006, 02:25 PM
Zero
Guest
 
Posts: n/a
Default Re: "long double" and "printf"


Zero wrote:[color=blue]
> 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![/color]

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?

  #8  
Old June 6th, 2006, 02:25 PM
Zero
Guest
 
Posts: n/a
Default Re: "long double" and "printf"


Richard Bos wrote:[color=blue]
> "Zero" <chefmuetze@web.de> wrote:
>[color=green]
> > 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.[/color]
>
> 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[/color]

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

  #9  
Old June 6th, 2006, 04:15 PM
Flash Gordon
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

Zero wrote:

<snip>
[color=blue][color=green]
>> 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![/color]
>
> 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?[/color]

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
  #10  
Old June 6th, 2006, 04:25 PM
Tim Prince
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

Flash Gordon wrote:[color=blue]
> Zero wrote:
>
> <snip>
>[color=green][color=darkred]
>>> 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![/color]
>>
>> 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?[/color]
>
> Both. The C standard does not mandate exact sizes only minimums.[/color]
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.
  #11  
Old June 6th, 2006, 05:45 PM
Dann Corbit
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

"Dik T. Winter" <Dik.Winter@cwi.nl> wrote in message
news:J0FzDt.9zw@cwi.nl...[color=blue]
> In article <1149602363.679848.32320@h76g2000cwa.googlegroups. com> "Zero"
> <chefmuetze@web.de> writes:
> ...[color=green]
> > Thanks for your help. But i still get this message:
> >
> > long double
> > 12
> > 0.000000e+000
> > -1.#QNAN0e+000[/color]
>
> Some older compilers did use 'll' in stead of 'L' for long double.[/color]

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).
[color=blue]
> --
> dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland,
> +31205924131
> home: bovenover 215, 1025 jn amsterdam, nederland;
> http://www.cwi.nl/~dik/[/color]


  #12  
Old June 6th, 2006, 08:25 PM
jacob navia
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

pete a écrit :[color=blue]
>
> 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 */
>
>[/color]


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

with lcc-win32
  #13  
Old June 8th, 2006, 01:35 PM
Richard Bos
Guest
 
Posts: n/a
Default Re: "long double" and "printf"

"Zero" <chefmuetze@web.de> wrote:
[color=blue]
> Richard Bos wrote:[color=green]
> > "Zero" <chefmuetze@web.de> wrote:[/color][/color]
[color=blue][color=green][color=darkred]
> > > 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[/color][/color][/color]
[color=blue][color=green]
> > 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.[/color]
>
> How do you know that this is a bug?[/color]

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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.