namespace std {
float
nextafter(float x,
float y); // (1) C++11からC++20まで
double
nextafter(double x,
double y); // (2) C++11からC++20まで
long double
nextafter(long double x,
long double y); // (3) C++11からC++20まで
constexpr floating-point-type
nextafter(floating-point-type x,
floating-point-type y); // (4) C++23
Promoted
nextafter(Arithmetic1 x,
Arithmetic2 y); // (5) C++11
constexpr Promoted
nextafter(Arithmetic1 x,
Arithmetic2 y); // (5) C++23
float
nextafterf(float x,
float y); // (6) C++17
constexpr float
nextafterf(float x,
float y); // (6) C++23
long double
nextafterl(long double x,
long double y); // (7) C++17
constexpr long double
nextafterl(long double x,
long double y); // (7) C++23
}
概要
指定方向への次の表現可能な値を取得する。
この関数は、パラメータx
の値をパラメータy
の値の方向に対して、その環境で表現可能な最小の値だけ進める。
- (1) :
float
に対するオーバーロード - (2) :
double
に対するオーバーロード - (3) :
long double
に対するオーバーロード - (4) : 浮動小数点数型に対するオーバーロード
- (5) : 算術型に対するオーバーロード (大きい精度にキャストして計算される。整数は
double
で計算される) - (6) :
float
型規定 - (7) :
long double
型規定
戻り値
パラメータx
の値をパラメータy
の方向に、表現可能な最小の値だけ進めた値を返す。
x
とy
が等値である場合、y
を返す。
進めた結果が無限大、もしくは表現できない場合、値域エラーとなる。
備考
例
出力例
1.4013e-45
-1.4013e-45
備考
特定の環境では、早期に constexpr
対応されている場合がある:
- GCC 4.6.1 以上
バージョン
言語
- C++11
処理系
- Clang: 3.0 ✅
- GCC: 4.3 ✅
- ICC: ??
- Visual C++: ??
参照
- P0533R9 constexpr for
<cmath>
and<cstdlib>
- C++23での、一部関数の
constexpr
対応
- C++23での、一部関数の
- P1467R9 Extended floating-point types and standard names