傳回下一個所能顯示的浮點值。
語法
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、、、 nexttowardfnexttowardl |
<math.h> |
<math.h> 或 <cmath> |
_nextafter |
<float.h> |
<float.h> 或 <cfloat> |
nextafter 巨集、 nexttoward 巨集 |
<tgmath.h> |
如需相容性詳細資訊,請參閱相容性。