Question

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;
Was it helpful?

Solution

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

OTHER TIPS

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

The maximum finite representable floating-point number.

Take a look here if you find anything similar.


Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top