range of long double variables

Discussion in 'C++' started by Leslaw Bieniasz, Feb 21, 2011.

  1. Hi,

    I have Borland C++Builder 6.0 compiler, and I would be happy
    to understand the implementation of long double variables in this
    compiler. According to the help files and manuals, long double variables
    are implemented using 10 bytes, they are supposed to have 18 significant
    digits, and range from (about) 10^(-4932) to 10^(4932).
    From my calculations, I see that the accuracy is indeed at this level.
    However, I have been unable to perform any operations on numbers greater
    than about 10^308, which is the maximum limit for double variables, not
    long double. For example, an attempt to substitute:

    long double x = 1.e309L;

    produces exceptions during program execution.
    Does anybody know what is the reason for this behaviour?
    Am I possibly doing something wrong? Should I link any special
    libraries, choose any special compiler options, or whatever?

    Leslaw
     
    Leslaw Bieniasz, Feb 21, 2011
    #1
    1. Advertising

  2. Leslaw Bieniasz

    jacob navia Guest

    Le 21/02/11 12:00, Leslaw Bieniasz a écrit :
    >
    >
    > Hi,
    >
    > I have Borland C++Builder 6.0 compiler, and I would be happy
    > to understand the implementation of long double variables in this
    > compiler. According to the help files and manuals, long double variables
    > are implemented using 10 bytes, they are supposed to have 18 significant
    > digits, and range from (about) 10^(-4932) to 10^(4932).
    > From my calculations, I see that the accuracy is indeed at this level.
    > However, I have been unable to perform any operations on numbers greater
    > than about 10^308, which is the maximum limit for double variables, not
    > long double. For example, an attempt to substitute:
    >
    > long double x = 1.e309L;
    >
    > produces exceptions during program execution.
    > Does anybody know what is the reason for this behaviour?
    > Am I possibly doing something wrong? Should I link any special
    > libraries, choose any special compiler options, or whatever?
    >
    > Leslaw


    1) Look at the generated assembler code. Does it use long double
    operations?

    2) Look at the CPU state: Is in full precision or in double precision only?

    If unsure send me the assembler listing and I will tell you.
     
    jacob navia, Feb 21, 2011
    #2
    1. Advertising

  3. jacob navia <> wrote:
    > 2) Look at the CPU state: Is in full precision or in double precision only?


    I didn't know Intel CPUs need to be in a special state in order to support
    extended precision floating point numbers. Are you talking about some
    different CPU?
     
    Juha Nieminen, Feb 21, 2011
    #3
  4. Leslaw Bieniasz

    jacob navia Guest

    Le 21/02/11 15:33, Juha Nieminen a écrit :
    > jacob navia<> wrote:
    >> 2) Look at the CPU state: Is in full precision or in double precision only?

    >
    > I didn't know Intel CPUs need to be in a special state in order to support
    > extended precision floating point numbers. Are you talking about some
    > different CPU?

    The CPU can perform operations in double precision or in native long
    double precision.

    Microsoft compilers set the precision to double precision at startup,
    since they do not support long double, in their implementation
    long double is equal to double.

    Other compilers like lcc-win or gcc use long double precision and the
    startup code (at least in my compiler system lcc-win) sets the CPU
    to full precision. This means that sometimes programs may fail that
    would work in double precision...

    When using double precision only, the CPU discards extra precision.

    Normally, gcc startup code sets the CPU in full precision, as in
    lcc-win since they support long double.

    Now, Borland is difficult to say...

    Do they support true long double?

    Or do they just accept long double but they convert it to double?

    Or they support long double only when some compilation directive
    is issued?

    If you look at the generated asm code you know what is being used:
    double or long double precision...
     
    jacob navia, Feb 21, 2011
    #4
  5. Leslaw Bieniasz

    Geoff Guest

    On Mon, 21 Feb 2011 12:00:29 +0100, Leslaw Bieniasz
    <> wrote:

    >
    >
    >Hi,
    >
    >I have Borland C++Builder 6.0 compiler, and I would be happy
    >to understand the implementation of long double variables in this
    >compiler. According to the help files and manuals, long double variables
    >are implemented using 10 bytes, they are supposed to have 18 significant
    >digits, and range from (about) 10^(-4932) to 10^(4932).
    >From my calculations, I see that the accuracy is indeed at this level.
    >However, I have been unable to perform any operations on numbers greater
    >than about 10^308, which is the maximum limit for double variables, not
    >long double. For example, an attempt to substitute:
    >
    >long double x = 1.e309L;
    >
    >produces exceptions during program execution.
    >Does anybody know what is the reason for this behaviour?
    >Am I possibly doing something wrong? Should I link any special
    >libraries, choose any special compiler options, or whatever?
    >
    >Leslaw


    What is the value of
    LDBL_MAX_10_EXP
    LDBL_MIN_10_EXP
    LDBL_MAX
    LDBL_MIN
    for your implementation?

    Post some sample code showing the behavior you describe?
     
    Geoff, Feb 21, 2011
    #5
    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. ferran
    Replies:
    9
    Views:
    3,121
    Kevin Goodsell
    Apr 12, 2004
  2. JKop
    Replies:
    4
    Views:
    16,574
  3. Sydex
    Replies:
    12
    Views:
    6,656
    Victor Bazarov
    Feb 17, 2005
  4. Michael Mair

    Typecast long double->double seems to go wrong

    Michael Mair, May 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    697
    Michael Mair
    May 24, 2004
  5. Daniel Rudy

    unsigned long long int to long double

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

Share This Page