问题
What is the difference between the nextafter and the nexttoward functions of the C++ 2011 standard library ?
回答1:
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);
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:
- If any argument corresponding to a
doubleparameter has typelong double,then all arguments corresponding todoubleparameters are effectively cast tolong double.- Otherwise, if any argument corresponding to a
doubleparameter has typedoubleor an integer type, then all arguments corresponding todoubleparameters are effectively cast todouble.- Otherwise, all arguments corresponding to
doubleparameters are effectively cast tofloat.See also: ISO C 7.5, 7.10.2, 7.10.6.
回答2:
Read man page:
The nexttoward() functions do the same as the nextafter() functions, except that they have a long double second argument.
来源:https://stackoverflow.com/questions/12063821/nextafter-vs-nexttoward-functions-in-c-2011