什么是C ++中的DBL_MAX? [英] What is DBL_MAX in C++?
问题描述
我在看一个我在网上找到的程序,我看到作者在少数情况下使用DBL_MAX。我不知道是什么,所以我研究了一点,但没有太多解释它是什么,它用于什么。
任何人都可以解释它是什么以及为什么应该使用它?
are:
localT.maxTemp = -DBL_MAX;
double avg = -DBL_MAX;
在C ++或< float.h>
< cfloat> 中定义的> DBL_MAX > C是最大可表示有限浮点(双)数的值
std获得相同的值: :< limits>
$ c
$ b std :: numeric_limits< double> :: max()
两种方法
#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;
}
在www.ideone.com(在线C ++编译器)
1.79769e + 308
1.79769e + 308
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>
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
这篇关于什么是C ++中的DBL_MAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!