473,467 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2800
"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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.