What is the difference between the nextafter and the nexttoward functions of the C++ 2011 standard library ?
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.
Read man page:
The nexttoward() functions do the same as the nextafter() functions, except that they have a long double second argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With