我问这个问题主要是出于学术兴趣。
这个
documentation
这么说的
std::uniform_real_distribution
[a,b)
a
和
b
是构造函数参数。
.max()
返回
最大可表示值小于
.b()
.
但我却得到了
.b() == .max()
float
,
double
,和
long double
#include <iostream>
#include <iomanip>
#include <random>
int main()
{
auto d = std::uniform_real_distribution<long double>(0, 1);
std::cout << std::setprecision(1000);
std::cout << d.min() << '\n'; // 0
std::cout << d.a() << '\n'; // 0
std::cout << d.max() << '\n'; // 1 <- Here I expect 0.99999...
std::cout << d.b() << '\n'; // 1
}
我发现了
this note
说一些常见的实现用途
[a,b]
范围
浮动
只有。它可以解释
.b()=.max()
对于
浮动
但不是为了
双重的
和
长双倍
我想也可以打印出来
std::nextafter(d.b(), d.a())
. 说书人
为了
它的计算结果是
0.9999999999999999999457898913757247782996273599565029144287109375
,这正是我希望从中得到的
.max()
.