nextafter在C ++ 2011中的nexttoward函数? [英] nextafter vs nexttoward functions in C++ 2011?

查看:180
本文介绍了nextafter在C ++ 2011中的nexttoward函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the difference between the nextafter and the nexttoward functions of the C++ 2011 standard library ?

推荐答案

从C,它们不能被重载,这意味着两个不同的名称为相同但具有不同的参数(类型)的函数。以下是原始签名:

Since the functions originate from C, they can't be overloaded, which means two different names for functions that do the same but have different parameter(-type)s. Here are the original signatures:

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

现在标准只是说应该有一些重载,使得C ++中的更好(§26.8[c.math] p11 ) :

And now the standard just says there should be a few overloads to make things nicer in C++ (§26.8 [c.math] p11):


此外,还有额外的重载,足以确保:

Moreover, there shall be additional overloads sufficient to ensure:


  1. 如果对应于 double 参数的任何参数具有类型 long double, double 参数有效地转换为 long double

  2. 对应于 double 参数的参数具有类型 double 或整数类型,则对应于 double 参数有效地转换为 double

  3. 否则,所有与 double 参数有效地转换为 float

  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.

另请参阅:ISO C 7.5,7.10.2,7.10.6。

See also: ISO C 7.5, 7.10.2, 7.10.6.

这篇关于nextafter在C ++ 2011中的nexttoward函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆