469,923 Members | 1,636 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

some problem with the min exponent of float and double in <limits> header?

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??
thanks.

Mar 18 '07 #1
1 2583
"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
Mar 18 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Gianni Mariani | last post: by
822 posts views Thread by Turamnvia Suouriviaskimatta | last post: by
16 posts views Thread by Mark Bruno | last post: by
11 posts views Thread by Ole Nielsby | last post: by
15 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
4 posts views Thread by john | last post: by
2 posts views Thread by Markus Dehmann | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.