nextafter在C ++ 2011中的nexttoward函数? [英] nextafter vs nexttoward functions in C++ 2011?
问题描述
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:
- 如果对应于
double
参数的任何参数具有类型long double,
double
参数有效地转换为long double
。 - 对应于
double
参数的参数具有类型double
或整数类型,则对应于double
参数有效地转换为double
。 - 否则,所有与
double
参数有效地转换为float
。
- If any argument corresponding to a
double
parameter has typelong double,
then all arguments corresponding todouble
parameters are effectively cast tolong double
. - Otherwise, if any argument corresponding to a
double
parameter has typedouble
or an integer type, then all arguments corresponding todouble
parameters are effectively cast todouble
. - Otherwise, all arguments corresponding to
double
parameters are effectively cast tofloat
.
另请参阅: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屋!