C++官网参考链接:https://cplusplus.com/reference/cmath/nexttoward/
函数
nexttoward
C99
double nexttoward(double x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y);
C++11
double nexttoward(double x, long double y );
float nexttoward(float x, long double y );
long double nexttoward(long double x, long double y);
double nexttoward(Type1 x, long double y); // additional overloads
下一个可表示的朝向精确值的值
返回x之后沿y方向的下一个可表示值。
此函数的行为与nextafter相同,但y可能更精确。
C99
头文件
C++11
在此头文件(
参数
x
基础值。
y
返回值的近似值。
如果两个形参比较相等,函数返回y(转换为返回类型)。
返回值
在y方向上x之后的下一个可表示的值。
如果x是该类型中可表示的最大有限值,而结果是无穷大或不可表示的,则会发生上溢范围错误。
如果发生上溢范围错误:
—math_errhandling设置了MATH_ERRNO:全局变量errno设置为ERANGE。
—math_errhandling设置了MATH_ERREXCEPT:引发FE_OVERFLOW。
用例
/* nexttoward example */
#include
#include
int main ()
{
printf ("first representable value greater than zero: %e\n", nexttoward(0.0,1.0L));
printf ("first representable value less than zero: %e\n", nexttoward(0.0,-1.0L));
return 0;
}
可能的输出:
另请参考
nextafter Next representable value (function) (下一个可表示的值(函数))