什么是C ++中的DBL_MAX?

时间:2022-10-02 20:33:59

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.

我正在查看我在网上找到的一个程序,我发现作者在少数情况下使用了DBL_MAX。我不确定它是什么,所以我研究了一下,但没有太多解释它是什么以及它用于什么。

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;

3 个解决方案

#1


23  

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

正如其他人所说的那样,在C ++的头文件 中定义的DBL_MAX或C中的 是最大可表示的有限浮点(双)数的值

In C++ you can get the same value using class std::numeric_limits defined in header <limits>

在C ++中,您可以使用header 中定义的类std :: numeric_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

在www.ideone.com(在线C ++编译器)输出是

1.79769e+308
1.79769e+308

#2


3  

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.

它是float.h或 中定义的常量。此标头描述了特定系统和所使用的编译器实现的浮动类型的特征。

DBL_MAX is maximum finite representable floating-point number.

DBL_MAX是最大有限可表示的浮点数。

http://en.cppreference.com/w/cpp/types/climits

#3


0  

The maximum finite representable floating-point number.

最大有限可表示的浮点数。

Take a look here if you find anything similar.

如果您发现任何类似的东西,请看这里。


#1


23  

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

正如其他人所说的那样,在C ++的头文件 中定义的DBL_MAX或C中的 是最大可表示的有限浮点(双)数的值

In C++ you can get the same value using class std::numeric_limits defined in header <limits>

在C ++中,您可以使用header 中定义的类std :: numeric_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

在www.ideone.com(在线C ++编译器)输出是

1.79769e+308
1.79769e+308

#2


3  

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.

它是float.h或 中定义的常量。此标头描述了特定系统和所使用的编译器实现的浮动类型的特征。

DBL_MAX is maximum finite representable floating-point number.

DBL_MAX是最大有限可表示的浮点数。

http://en.cppreference.com/w/cpp/types/climits

#3


0  

The maximum finite representable floating-point number.

最大有限可表示的浮点数。

Take a look here if you find anything similar.

如果您发现任何类似的东西,请看这里。