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

J

janzon

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".
 
P

P.J. Plauger

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
 
M

Markus Moll

Hi

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top