Share via


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_UNDERFLOW 則會設定 和 FE_INEXACT 浮點例外狀況狀態,並傳回正確的結果。 如果 xy 為 NAN,則傳回值是其中一個輸入 NAN。 如果 x 為有限,且結果在類型中是無限或不可表示的,則會傳回正確帶正負號的無限大或 NAN, FE_OVERFLOW 而且會設定 和 FE_INEXACT 浮點例外狀況狀態,並且 errno 設定為 ERANGE

備註

nextafternexttoward 函式系列相同,只不過 y 的參數類型不同。 如果 xy 相等,傳回的值會是轉換成傳回型別的 y

因為 C++ 允許多載,因此,如果您包含 <cmath> ,您可以呼叫 的多載 nextafter 和 傳 nexttowardfloatlong double 型別。 在 C 程式中,除非您使用 <tgmath.h> 宏來呼叫此函式, nextafter 而且 nexttoward 一律會傳回 double

如果您使用 nextafter 的 或 nexttoward<tgmath.h> ,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學

_nextafterf_nextafter 式是 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