gpt4 book ai didi

c++ - C++ 2011 中的 nextafter 与 nexttoward 函数?

转载 作者:IT老高 更新时间:2023-10-28 22:13:59 26 4
gpt4 key购买 nike

C++ 2011标准库的nextafter和nexttoward函数有什么区别?

最佳答案

由于函数源自 C,它们不能被重载,这意味着函数有两个不同的名称,但具有不同的参数(-type)。以下是原始签名:

float nextafter(float, float);
float nexttoward(float, long double);

现在标准只是说应该有a few overloads在 C++ 中让事情变得更好(§26.8 [c.math] p11):

Moreover, there shall be additional overloads sufficient to ensure:

  1. If any argument corresponding to a double parameter has type long double, then all arguments corresponding to double parameters are effectively cast to long double.
  2. Otherwise, if any argument corresponding to a double parameter has type double or an integer type, then all arguments corresponding to double parameters are effectively cast to double.
  3. Otherwise, all arguments corresponding to double parameters are effectively cast to float.

See also: ISO C 7.5, 7.10.2, 7.10.6.

关于c++ - C++ 2011 中的 nextafter 与 nexttoward 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12063821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com