nextafter, nextafterf, nextafterl, _nextafter, _nextafterf, nexttoward, nexttowardf, nexttowardl

返回下一个可表示的浮点值。

语法

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 higher

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 higher

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
要达到的浮点值。

返回值

返回 y 方向中 x 之后的返回类型的下一个可表示浮点值。 如果 xy 相等,则函数返回 y,转换为返回类型,且未触发异常。 如果 x 不等于 y,并且结果为非正规或零,则会设置 FE_UNDERFLOWFE_INEXACT 浮点异常状态,并返回正确的结果。 如果 xy 是 NaN,则返回值为输入 NaN 之一。 如果 x 是有限的,并且结果是无穷大或无法在类型中表示,则返回正确的有符号无穷大或 NAN,并设置 FE_OVERFLOWFE_INEXACT 浮点异常状态,并将 errno 设置为 ERANGE

注解

nextafternexttoward 函数系列是等同的,只不过参数类型为 y。 如果 xy 相等,则返回的值是转换为返回类型的 y

由于 C++ 允许重载,因此如果包括 <cmath>,则你可以调用返回 floatlong double 类型的 nextafternexttoward 重载。 在 C 程序中,除非使用 <tgmath.h> 宏来调用此函数,否则 nextafternexttoward 始终返回 double

如果使用 <tgmath.h> 中的 nextafternexttoward 宏,自变量的类型将确定选择哪个版本的函数。 有关详细信息,请参阅泛型类型数学

_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>

有关兼容性的详细信息,请参阅 兼容性

另请参阅

数学和浮点支持
isnan_isnan_isnanf