smallest positive double number

Discussion in 'C Programming' started by gouqizi.lvcha@gmail.com, Jun 22, 2005.

  1. Guest

    Hi, All:

    I wonder what is the smallest positive double numbers in C in 32 bit
    CPU?

    Rick
    , Jun 22, 2005
    #1
    1. Advertising

  2. CBFalconer Guest

    CBFalconer, Jun 22, 2005
    #2
    1. Advertising

  3. Richard Bos Guest

    "" <> wrote:

    > I wonder what is the smallest positive double numbers in C in 32 bit
    > CPU?


    That question cannot really be answered. OTOH, there is probably a very
    definite and useful answer.
    It cannot be answered because having a "32 bit CPU", whichever that
    means, does not necessarily mean anything for your integers; means
    nearly nothing for the size of your doubles; and means even less for the
    representation of those doubles within that size. How a double is
    represented is decided by your implementation, not by the CPU. The
    implementation probably does take certain aspects of the hardware into
    account, but the relevant ones are most likely to be the layout of the
    registers of the floating point unit, not the size of the data bus,
    fastest or largest integer registers, or whatever aspect of the CPU is
    called "32 bit".
    It can be answered quite authoritatively for the implementation you are
    compiling on at the moment, though: DBL_MIN, from <float.h>, is the
    smallest positive normalised double value.

    Richard
    Richard Bos, Jun 22, 2005
    #3
  4. Grumble Guest

    wrote:

    > I wonder what is the smallest positive double numbers in C
    > in 32 bit CPU?


    DBL_MIN yields the smallest normalized, finite representable value
    of type double. DBL_EPSILON yields the smallest X of type double
    such that 1.0 + X != 1.0.

    (Source www.dinkumware.com)
    Grumble, Jun 22, 2005
    #4
  5. On 22/06/2005 09:29, Richard Bos wrote:

    > "" <> wrote:
    >
    >> I wonder what is the smallest positive double numbers in C in 32 bit
    >> CPU?

    >


    I wonder... Actually a CPU could have no FPU at all, which happened on 8086,
    80286 and 80386 at least, and probably on 68000. Second, it's perfectly
    possible that a C compiler don't use the FPU, if there is one, and sometimes
    it depends on how you run the compiler. So there are two different
    questions: how does your C compiler handle double numbers, and how does your
    CPU, if that makes sense. The first was already answered, the second is in
    your CPU's manual. If you have not that manual, it's probably on the web:
    there are PDF files for Pentium, PowerPC, 68000, Alpha and Sparc, at least.

    You question is also tricky for another reason: usually a C compiler handles
    float and double numbers, but the Pentium processor can work with extended
    precision (that can be set by an asm instruction, maybe no accessible from
    C, and certainly not in C standard). If you work with usual 64 bits IEEE754
    doubles on a pentium, you may have different results in your computations
    depending on which precision is used internally. There is the same kind of
    problem on machines with fused-multiply-add (fma). So be aware that you
    question is not only related to your compiler, it's also related to your
    CPU. Both are off-topic anyway.
    Jean-Claude Arbaut, Jun 22, 2005
    #5
  6. Tim Prince Guest

    Grumble wrote:
    > wrote:
    >
    >> I wonder what is the smallest positive double numbers in C
    >> in 32 bit CPU?

    >
    >
    > DBL_MIN yields the smallest normalized, finite representable value
    > of type double. DBL_EPSILON yields the smallest X of type double
    > such that 1.0 + X != 1.0.
    >
    > (Source www.dinkumware.com)

    If you have IEEE gradual underflow enabled on your system, subnormal
    values DBL_MIN * DBL_EPSILON <= X < DBL_EPSILON are available. This has
    nothing to do with "32 bit CPU," nor does "32 bit CPU" have anything to
    do with C, except as reflected in <float.h> and <limits.h>.
    Tim Prince, Jun 22, 2005
    #6
  7. AC Guest

    "Grumble" <> wrote in message
    news:d9ba31$c74$...
    > wrote:
    >
    >> I wonder what is the smallest positive double numbers in C
    >> in 32 bit CPU?

    >
    > DBL_MIN yields the smallest normalized, finite representable value
    > of type double. DBL_EPSILON yields the smallest X of type double
    > such that 1.0 + X != 1.0.
    >
    > (Source www.dinkumware.com)


    The smallest floating point value might not be normal.

    What about something like (pseudo code)

    x=1;
    while(x/FLT_RADIX)
    {
    x = x/FLT_RADIX;
    }
    AC, Jun 22, 2005
    #7
  8. wrote:

    > I wonder what is the smallest positive double number is
    > in C in 32 bit CPU?


    > cat main.c

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

    int main(int argc, char* argv[]) {
    const
    double x = DBL_MIN*DBL_EPSILON;
    const unsigned
    long int* p = (const unsigned long int*)(&x);
    fprintf(stdout, "x = %g\n", x);
    fprintf(stdout, "p[1] = %lu\tp[0] = %lu\n", p[1], p[0]);
    return 0;
    }

    > gcc -Wall -std=c99 -pedantic -o main main.c
    > ./main

    x = 4.94066e-324
    p[1] = 0 p[0] = 1
    E. Robert Tisdale, Jun 22, 2005
    #8
  9. Grumble Guest

    Jean-Claude Arbaut wrote:

    > You question is also tricky for another reason: usually a C compiler handles
    > float and double numbers, but the Pentium processor can work with extended
    > precision (that can be set by an asm instruction, maybe no accessible from
    > C, and certainly not in C standard).


    long double?
    Grumble, Jun 23, 2005
    #9
  10. On 23/06/2005 10:35, Grumble wrote:

    > Jean-Claude Arbaut wrote:
    >
    >> You question is also tricky for another reason: usually a C compiler handles
    >> float and double numbers, but the Pentium processor can work with extended
    >> precision (that can be set by an asm instruction, maybe no accessible from
    >> C, and certainly not in C standard).

    >
    > long double?


    If the compiler knows of this type, yes.
    Jean-Claude Arbaut, Jun 23, 2005
    #10
  11. pete Guest

    Jean-Claude Arbaut wrote:
    >
    > On 23/06/2005 10:35, Grumble wrote:


    > > long double?

    >
    > If the compiler knows of this type, yes.


    long double has been standard, ever since there was a standard.

    We usually assume standard C here, unless otherwise stated.
    If you're stating something that's only intended to be true
    for one of C89 or C99 or K&R, then it's best to specify which.

    --
    pete
    pete, Jun 23, 2005
    #11
  12. On 23/06/2005 12:34, pete wrote:

    > Jean-Claude Arbaut wrote:
    >>
    >> On 23/06/2005 10:35, Grumble wrote:

    >
    >>> long double?

    >>
    >> If the compiler knows of this type, yes.

    >
    > long double has been standard, ever since there was a standard.
    >
    > We usually assume standard C here, unless otherwise stated.
    > If you're stating something that's only intended to be true
    > for one of C89 or C99 or K&R, then it's best to specify which.


    Ok, the compiler always knows. But that wasn't the problem. The OP asked for
    the smallest positive double, and depending on what he is doing with it,
    compiler optimizations can be nasty: there may be numbers smaller than that
    at runtime, simply because it's computing in extended precision, and it
    doesn't store/reload values between computation. The same kind of problem
    happens on PPC with fma instructions (but there, reloading values does not
    help). When doing fp computation, one must be careful with fpu flags, for
    instance precision control flags. Even of PPC, you can have long double, if
    they are implemented as two doubles, XLC has them for example.
    Jean-Claude Arbaut, Jun 23, 2005
    #12
    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. Sydex
    Replies:
    12
    Views:
    6,452
    Victor Bazarov
    Feb 17, 2005
  2. Replies:
    2
    Views:
    361
    P.J. Plauger
    Jun 22, 2005
  3. EK
    Replies:
    0
    Views:
    309
  4. MRAB
    Replies:
    2
    Views:
    292
    John Machin
    Jan 31, 2009
  5. Hicham Mouline
    Replies:
    2
    Views:
    750
    Keith Thompson
    Apr 23, 2010
Loading...

Share This Page