"long double" and "printf"

Discussion in 'C Programming' started by Zero, Jun 6, 2006.

  1. Zero

    Zero Guest

    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!
    Zero, Jun 6, 2006
    #1
    1. Advertising

  2. Zero

    pete Guest

    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
    pete, Jun 6, 2006
    #2
    1. Advertising

  3. Zero

    Zero Guest

    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

    ??
    Zero, Jun 6, 2006
    #3
  4. Zero

    Richard Bos Guest

    "Zero" <> 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
    Richard Bos, Jun 6, 2006
    #4
  5. In article <> "Zero" <> 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/
    Dik T. Winter, Jun 6, 2006
    #5
  6. Zero

    Zero Guest

    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?
    Zero, Jun 6, 2006
    #6
  7. Zero

    Zero Guest

    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?
    Zero, Jun 6, 2006
    #7
  8. Zero

    Zero Guest

    Richard Bos wrote:
    > "Zero" <> 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?
    Zero, Jun 6, 2006
    #8
  9. Zero

    Flash Gordon Guest

    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
    Flash Gordon, Jun 6, 2006
    #9
  10. Zero

    Tim Prince Guest

    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.
    Tim Prince, Jun 6, 2006
    #10
  11. Zero

    Dann Corbit Guest

    "Dik T. Winter" <> wrote in message
    news:...
    > In article <> "Zero"
    > <> 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/
    Dann Corbit, Jun 6, 2006
    #11
  12. Zero

    jacob navia Guest

    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
    jacob navia, Jun 6, 2006
    #12
  13. Zero

    Richard Bos Guest

    "Zero" <> wrote:

    > Richard Bos wrote:
    > > "Zero" <> 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
    Richard Bos, Jun 8, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Piotr B.
    Replies:
    6
    Views:
    8,945
    Martin Ambuhl
    Oct 19, 2004
  2. saper

    printf and 'long double'

    saper, Feb 24, 2005, in forum: C++
    Replies:
    4
    Views:
    11,403
    Ioannis Vranos
    Feb 25, 2005
  3. Piotr B.
    Replies:
    6
    Views:
    608
    Martin Ambuhl
    Oct 19, 2004
  4. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,179
    Peter Shaggy Haywood
    Sep 20, 2005
  5. fieldfallow

    printf() error with long double and null pointer.

    fieldfallow, Feb 24, 2006, in forum: C Programming
    Replies:
    69
    Views:
    1,717
    Jordan Abel
    Feb 28, 2006
Loading...

Share This Page