"Wayne Shu" <Wa******@gmail.comwrote in message

news:11**********************@l77g2000hsb.googlegr oups.com

Hei everyone:

Just see the output of the following program

#include <iostream>

#include <cstdlib>

#include <limits>

int main()

{

std::cout << "minimum exponent of double: " <<

std::numeric_limits<double>::min_exponent

<< "\nmaximum exponent of double: " <<

std::numeric_limits<double>::max_exponent

<< "\nminimum exponent of float: " <<

std::numeric_limits<float>::min_exponent

<< "\nmaximum exponent of float: " <<

std::numeric_limits<float>::max_exponent

<< std::endl;

system("pause");

return 0;

}

I use the vc8 and gcc 3.4 compile it, and the output is the same:

minimum exponent of double: -1021

maximum exponent of double: 1024

minimum exponent of float: -125

maximum exponent of float: 128

but in the IEEE-754(IEEE Standard for Binary Floating-Point

Arithmetic)

the minimum and maximum exponent of double is -1022 and +1023

the minimum and maximum exponent of float is -126 and +127

Why they are not the same?

min_exponent and max_exponent in the <limitsheader are not the same

mean in the IEEE standard?

someone explain it for me??

Subtract one from each of the C++ numbers you are getting and you get the

IEEE values.

This adjustment by 1 is specifed in the C++ standard. I don't know why. See

section 18.2.1.1 of the standard, especially:

static const int min_exponent;

23 Minimum negative integer such that radix raised to the power of one less

than that integer is a normalized floating point number.

26 Meaningful for all floating point types.

static const int max_exponent;

27 Maximum positive integer such that radix raised to the power one less

than that integer is a representable finite floating point number.

--

John Carson