Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is DBL_MAX in C++? [closed]

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;
like image 645
Christoph Avatar asked Apr 24 '14 20:04

Christoph


People also ask

What is DBL_Max in C++?

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>.

What is LDBL_max_10_exp in C++?

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.

What is the maximum float value of LDBL_Max?

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

What is the maximum exponent of DBL_Max?

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


2 Answers

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

like image 123
4pie0 Avatar answered Sep 28 '22 02:09

4pie0


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
like image 42
Vlad from Moscow Avatar answered Sep 28 '22 02:09

Vlad from Moscow