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
Answer from Bathsheba on Stack OverflowI'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
Is
DBL_MINthe 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.
smallest double value greater zero - C++ Forum
minimum double value in C/C++ - Stack Overflow
Why is the smallest positive number in 8-byte 2^-1022 and not 2^-1024?
How to represent a really small number in C?
-DBL_MAX in ANSI C, which is defined in float.h.
Floating point numbers (IEEE 754) are symmetrical, so if you can represent the greatest value (DBL_MAX or numeric_limits<double>::max()), just prepend a minus sign.
And then is the cool way:
double f;
(*((uint64_t*)&f))= ~(1LL<<52);
Practice problem from my textbook: The mass of a single molecule of water is about 3.0×10 -23 grams. A quart of water is about 950 grams. Write a program that requests an amount of water, in quarts, and displays the number of water molecules in that amount.
How do I do this? A double has up to 15 points of precision. But this requires 23.
.Machine$double.xmin gives the value of the smallest positive number whose representation meets the requirements of IEEE 754 technical standard for floating point computation. As is mentioned in the Wikipedia article on double-precision floating point numbers, that standard requires that:
If a decimal string with at most 15 significant digits is converted to IEEE 754 double precision representation and then converted back to a string with the same number of significant digits, then the final string should match the original. If an IEEE 754 double precision is converted to a decimal string with at least 17 significant digits and then converted back to double, then the final number must match the original.
The same article goes on to note that, by compromising precision, even smaller positive numbers (which do not meet the standards' precision requirements) can be represented:
The 11 bit width of the exponent allows the representation of numbers between 10-308 and 10308, with full 15–17 decimal digits precision. By compromising precision, the subnormal representation allows even smaller values up to about 5 × 10-324.
R's doubles behave in exactly this way, as is noted in the Details section of ?.Machine:
Note that on most platforms smaller positive values than ‘.Machine$double.xmin’ can occur. On a typical R platform the smallest positive double is about ‘5e-324’.
To confirm that that is the smallest positive value that can be represented using R's doubles and to see the cost in loss of precision, try out a few operations like this:
5e-324
# [1] 4.940656e-324
2e-324
# [1] 0
1.4 * 5e-324
# [1] 4.940656e-324
1.6 * 5e-324
# [1] 9.881313e-324
Here are some representations using SAS, IEEE 754 Big Endian?
data _null_;
y=constant('big');
put y hex16.;
put y E21.3;
run;quit;
Biggest
7FEFFFFFFFFFFFFF 1.79769313486230E+308
data _null_;
y=constant('small');
put y hex16.;
put y E21.3;
run;quit;
Smallest
0010000000000000 2.22507385850720E-308
I am not sure the smallest because SAS may set aside some values for missings.