13

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

Community
  • 1
  • 1
user1235183
  • 3,002
  • 1
  • 27
  • 66
  • C++ std::numeric_limits::min documentation: http://en.cppreference.com/w/cpp/types/numeric_limits/min –  Sep 28 '16 at 12:09

2 Answers2

13

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

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • 2
    So, DBL_MIN is the smallest normal double value? – user1235183 Sep 28 '16 at 12:13
  • 1
    Yes, that's the one. – Bathsheba Sep 28 '16 at 12:13
  • It's also worth noting that, on Intel, the floating point registers are 80-bit long double, and can hold even more values. – Martin Bonner supports Monica Sep 28 '16 at 12:25
  • "Some systems handle denormal values in hardware, in the same way as normal values. Others leave the handling of denormal values to system software, only handling normal values and zero in hardware. Handling denormal values in software always leads to a significant decrease in performance." – Andrew Dec 30 '19 at 04:35
  • "When denormal values are entirely computed in hardware, implementation techniques exist to allow their processing at speeds comparable to normal numbers; however, the speed of computation is significantly reduced on many modern processors; in extreme cases, instructions involving denormal operands may run as much as 100 times slower. This speed difference can be a security risk. ... Some applications need to contain code to avoid denormal numbers, either to maintain accuracy, or in order to avoid the performance penalty in some processors." – Andrew Dec 30 '19 at 04:35
3

Is DBL_MIN the smallest positive double?

Not certainly.
DBL_MIN is the smallest positive normal double.

DBL_TRUE_MIN is the smallest positive double (since C++17). It will be smaller than DBL_MIN when double supports subnormals.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256