I was looking at a program I found online and I see that the author used DBL_MAX in a few cases. I wasn't sure what it was so I researched a little, but there was not much explaining what it is and what its used for.
Can anyone explain what it is and why you should use it?
Some examples of use in the code were:
localT.maxTemp = -DBL_MAX;
double avg = -DBL_MAX;
As it was said by others DBL_MAX defined in header <cfloat> in C++ or <float.h> in C is the value of maximum representable finite floating-point (double) number In C++ you can get the same value using class std::numeric_limits defined in header <limits> It is a constant defined in float.h or <cfloat>.
FLT_MAX_10_EXP or DBL_MAX_10_EXP or LDBL_MAX_10_EXP: Maximum integer value for the exponent of a base-10 expression that would generate a normalized floating-point number. FLT_MAX or DBL_MAX or LDBL_MAX: Maximum finite representable floating-point number.
The standard requires FLT_MAX, DBL_MAX, and LDBL_MAX to be at least 1E+37, and FLT_MIN, DBL_MIN, and LDBL_MIN to be at most 1E-37. Each of the *_MAX values is the maximum representa Should you leave more than $1,000 in a checking account? Float is 4 bytes with precision of 6 decimal places ranging from 1.2E-38 to 3.4E+38
Totally correct, but the exponent bias is 1023, and the maximum exponent is reserved for infinity and nan, hence DBL_MAX has an exponent of 2046 - 1023 = 1023. – Stephen Canon May 6 '15 at 1:09
It is a constant defined in float.h
or <cfloat>
. This header describes the characteristics of floating types for the specific system and compiler implemetation used.
DBL_MAX
is maximum finite representable floating-point number.
http://en.cppreference.com/w/cpp/types/climits
As it was said by others DBL_MAX
defined in header <cfloat>
in C++ or <float.h>
in C is the value of maximum representable finite floating-point (double) number
In C++ you can get the same value using class std::numeric_limits
defined in header <limits>
std::numeric_limits<double>::max()
Here is an example of using the both approaches
#include <iostream>
#include <cfloat>
#include <limits>
int main()
{
std::cout << DBL_MAX << std::endl;
std::cout << std::numeric_limits<double>::max() << std::endl;
return 0;
}
At www.ideone.com (on-line C++ compiler) the output is
1.79769e+308
1.79769e+308
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With