I just noticed that std::nextafter(0, 1)
on my system seems to produce a value greater than 0 and lower than std::numeric_limits::min()
.
How is this possible? I thought min()
returns the smallest possible number greater than 0.
#include <iostream>
int main(int argc, char *argv[])
{
double next = std::nextafter(0.0, 1.0);
double min = std::numeric_limits<double>::min();
std::cout << "next: " << next << "\nmin: " << min << "\nnext<min: " << (next < min) << "\nnext>0: " << (next > 0.0) << std::endl;
}
Output:
next: 4.94066e-324
min: 2.22507e-308
next<min: 1
next>0: 1
My compiler is MinGW 5.3.0 32bit.
std::nextafter()
is allowed to return a subnormal number (in your case the smallest subnormal number since you are traversing in an upwards direction from zero), whereas std::numeric_limits::min()
is the smallest non-subnormal number.
Reference: http://en.cppreference.com/w/cpp/numeric/math/nextafter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With