返回下一个可表示的浮点值。
语法
double nextafter( double x, double y );
float nextafterf( float x, float y );
long double nextafterl( long double x, long double y );
double _nextafter( double x, double y );
float _nextafterf( float x, float y ); /* x64 only */
#define nextafter(X, Y) // Requires C11 or later
double nexttoward( double x, long double y );
float nexttowardf( float x, long double y );
long double nexttowardl( long double x, long double y );
#define nexttoward(X, Y) // Requires C11 or later
float nextafter( float x, float y ); /* C++ only, requires <cmath> */
long double nextafter( long double x, long double y ); /* C++ only, requires <cmath> */
float nexttoward( float x, long double y ); /* C++ only, requires <cmath> */
long double nexttoward( long double x, long double y ); /* C++ only, requires <cmath> */
参数
x
要从其开始的浮点值。
y
要达到的浮点值。
返回值
返回 x 方向中 y 之后的返回类型的下一个可表示浮点值。 如果 x 和 y 相等,则函数返回 y,转换为返回类型,且未触发异常。 如果 x 不等于 y,并且结果为非正规或零,则会设置 FE_UNDERFLOW 和 FE_INEXACT 浮点异常状态,并返回正确的结果。 如果 x 或 y 是 NaN,则返回值为输入 NaN 之一。 如果 x 是有限的,并且结果是无穷大或无法在类型中表示,则返回正确的有符号无穷大或 NAN,并设置 FE_OVERFLOW 和 FE_INEXACT 浮点异常状态,并将 errno 设置为 ERANGE。
注解
nextafter 和 nexttoward 函数系列是等同的,只不过参数类型为 y。 如果 x 和 y 相等,则返回的值是转换为返回类型的 y。
由于 C++ 允许重载,因此如果包括 <cmath>,则你可以调用返回 nextafter 和 nexttoward 类型的 float 和 long double 重载。 在 C 程序中,除非使用 <tgmath.h> 宏来调用此函数,否则 nextafter 和 nexttoward 始终返回 double。
如果使用 nextafter 中的 nexttoward 或 <tgmath.h> 宏,自变量的类型将确定选择哪个版本的函数。 有关详细信息,请参阅泛型类型数学。
_nextafter 和 _nextafterf 函数是 Microsoft 特定函数。
_nextafterf 函数仅在编译 x64 时可用。
默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态。
要求
| 例程 | 必需的标头 (C) | 必需的标头 (C++) |
|---|---|---|
nextafter, nextafterf, nextafterl, _nextafterf, nexttoward, nexttowardf, nexttowardl |
<math.h> |
<math.h> 或 <cmath> |
_nextafter |
<float.h> |
<float.h> 或 <cfloat> |
nextafter 宏、nexttoward 宏 |
<tgmath.h> |
有关兼容性的详细信息,请参阅 兼容性。
另请参阅
数学和浮点支持
.- .