Why is DBL_MIN != nextafter(0.0,1.0) ??

Discussion in 'C++' started by janzon@gmail.com, Feb 1, 2007.

  1. Guest

    The output of the following program
    ----------------------------------------------------------
    #include <iostream>
    #include <iomanip>
    #include <float.h>
    #include <fpu_control.h>
    #include <math.h>

    using namespace std;

    int main()
    {
    cout << setprecision(20);

    cout << nextafter(0.0, 1.0) << endl;
    cout << DBL_MIN << endl;
    cout << LDBL_MIN << endl;
    }
    ------------------------------------------------------------
    is this:

    4.9406564584124654418e-324 // The next double after zero ...
    2.2250738585072013831e-308 // is not the "smallest
    representable double"
    3.3621031431120935063e-4932

    Compiled with g++. g++ -v says "gcc version 4.1.2 20060928".
     
    , Feb 1, 2007
    #1
    1. Advertising

  2. P.J. Plauger Guest

    <> wrote in message
    news:...

    > The output of the following program
    > ----------------------------------------------------------
    > #include <iostream>
    > #include <iomanip>
    > #include <float.h>
    > #include <fpu_control.h>
    > #include <math.h>
    >
    > using namespace std;
    >
    > int main()
    > {
    > cout << setprecision(20);
    >
    > cout << nextafter(0.0, 1.0) << endl;
    > cout << DBL_MIN << endl;
    > cout << LDBL_MIN << endl;
    > }
    > ------------------------------------------------------------
    > is this:
    >
    > 4.9406564584124654418e-324 // The next double after zero ...
    > 2.2250738585072013831e-308 // is not the "smallest
    > representable double"
    > 3.3621031431120935063e-4932
    >
    > Compiled with g++. g++ -v says "gcc version 4.1.2 20060928".


    DBL_MIN is the smallest *normalized* value of type double. IEEE 754
    arithmetic supports denormalized values that, demonstrably, can be
    much smaller.

    P.J. Plauger
    Dinkumware, Ltd.
    http://www.dinkumware.com
     
    P.J. Plauger, Feb 1, 2007
    #2
    1. Advertising

  3. Markus Moll Guest

    Hi

    wrote:
    > 4.9406564584124654418e-324 // The next double after zero ...
    > 2.2250738585072013831e-308 // is not the "smallest
    > representable double"
    > 3.3621031431120935063e-4932


    DBL_MIN is the smallest _normalized_ positive floating point number.
    Denormalized numbers can become smaller by a factor of 2^(nr of bits in
    the mantissa) (because they assume the numbers are +/- 0.mantissa *
    2^exp instead of +/- 1.mantissa * 2^exp). Calculating the quotient in
    your example yields 2^-51.9999999999 which matches the 52 bits in the
    mantissa of IEEE 754 double precision numbers.

    See also http://en.wikipedia.org/wiki/IEEE_754#Cases

    hth
    Markus
     
    Markus Moll, Feb 1, 2007
    #3
    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. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    589
    Juan T. Llibre
    Jan 27, 2005
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    933
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,128
    Smokey Grindel
    Dec 2, 2006
  4. Daniel Vallstrom
    Replies:
    7
    Views:
    368
    Daniel Vallstrom
    Oct 19, 2004
  5. David Mathog

    DBL_MAX,DBL_MIN defined as?

    David Mathog, May 12, 2011, in forum: C Programming
    Replies:
    3
    Views:
    7,083
    Tim Prince
    May 12, 2011
Loading...

Share This Page