我认为区别在于返回值给出了关于解决平局的输入,比如这段代码:
int main()
{
std::cout.precision(100);
double input = std::nextafter(0.05, 0.0) / 0.1;
double x1 = floor(0.5 + input);
double x2 = round(input);
std::cout << x1 << std::endl;
std::cout << x2 << std::endl;
}
输出结果为:
1
0
但最终它们只是不同的结果,选择自己喜欢的。我看到很多“老”C/C++程序使用
floor(0.5 + input)
而不是round(input)
。这是否有历史原因?CPU最便宜吗?