What is DBL_MAX in C++?

65,521

Solution 1

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

Solution 2

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

Share:
65,521
Christoph
Author by

Christoph

Updated on July 27, 2022

Comments

  • Christoph
    Christoph almost 2 years

    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;