Is DBL_MIN the smallest positive double?

冷暖自知 提交于 2019-12-08 16:53:27

问题


Q: Is DBL_MIN the smallest positive double?

The code below seems to anwser this question with no. But if this is true, how is DBL_MIN the defined and what is its use or purpose.

Platform: Windows7 & Visual Studio 2013

double next_to_zero = std::nextafter(0.0,DBL_MIN);
bool b =  DBL_MIN <= next_to_zero;
std::cout << std::boolalpha 
          << "is dbl_min the smallest representable double? "
          << b << '\n';

std::cout << std::setprecision(56)
          << "dbl_min = " << DBL_MIN << '\n'
          << "next to zero = " << next_to_zero;

outputs:

is dbl_min the smallest representable double? false

dbl_min = 2.2250738585072013830902327173324040642192159804623318306e-308

next to zero = 4.9406564584124654417656879286822137236505980261432476443e-324


回答1:


I'm restricting this answer, perhaps unnecessarily, to IEEE754 floating point.

DBL_MIN is not allowed to be a subnormal number.

But std::nextafter is allowed to return a subnormal number.

Hence the return value of the latter could be less than DBL_MIN.

For more details see https://en.wikipedia.org/wiki/Denormal_number



来源:https://stackoverflow.com/questions/39746861/is-dbl-min-the-smallest-positive-double

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!