472,954 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

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 2768
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gianni Mariani | last post by:
The spirit of this arguably pointless exercise, is that the numeric_limits<T> class could be replaced with a totally generic template of compile-time, template computed constants. The problem is...
822
by: Turamnvia Suouriviaskimatta | last post by:
I 'm following various posting in "comp.lang.ada, comp.lang.c++ , comp.realtime, comp.software-eng" groups regarding selection of a programming language of C, C++ or Ada for safety critical...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
16
by: Mark Bruno | last post by:
Hey, I'm learning about the limits header, and I don't understand one snippit of code. If I code: #include <limits.h> #include <stdio.h> int main() { printf("Smallest signed long long:...
4
by: Simon | last post by:
Hi, I am trying to create a round kind of function, (to round float and double to int). In the H file I can do the following with not too much trouble... // #include <limits> #include...
11
by: Ole Nielsby | last post by:
First, sorry if this is off-topic, not strictly being a C++ issue. I could not find a ng on numerics or serialization and I figure this ng is the closest I can get. Now the question: I want...
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
4
by: john | last post by:
The code: #include <iostream> #include <limits> int main() { using namespace std;
2
by: Markus Dehmann | last post by:
I have two integers i1 and i2, the second of which is guaranteed to be between 0 and 99, and I encode them into one double: double encoded = (double)i1 + (double)i2 / (double)100; So, for...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.