C++11的std::nextafter()如何产生比std::numeric_limits::min更小的值?

14

我刚刚注意到在我的系统上std::nextafter(0, 1)似乎产生了一个大于0且小于std::numeric_limits::min()的值。

这怎么可能?我以为min()返回大于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;
}

输出:

next: 4.94066e-324
min:  2.22507e-308
next<min: 1
next>0:   1

我的编译器是MinGW 5.3.0 32位版本。


1
好问题,而且喜欢你的名字! - Bathsheba
1个回答

18

2
请注意,次正常数是一个真正的痛点。 - Yakk - Adam Nevraumont
1
@Yakk; 的确,但这样的问题非常适合酒吧问答比赛。 - Bathsheba

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接