📅  最后修改于: 2020-09-25 07:59:42             🧑  作者: Mango
该函数在
double nextafter(double x, double y);
float nextafter(float x, float y);
long double nextafter(long double x, long double y);
Promoted nextafter(Type1 x, Type2 y); // Additional overloads
从C++ 11开始,如果传递给nextafter()的任何参数为long double
,则返回类型Promoted
为long double
。如果不是,则返回类型Promoted
为double
。
nextafter() 函数在y方向上返回x之后的下一个可表示值。
#include
#include
using namespace std;
int main()
{
double x = 0.0, y = 1.0;
double resultInDouble = nextafter(x,y);
cout << "nextafter(x, y) = " << resultInDouble << endl;
return 0;
}
运行该程序时,输出为:
nextafter(x, y) = 4.94066e-324
#include
#include
using namespace std;
int main()
{
float y = 1.0;
double x = INFINITY;
double result = nextafter(x,y);
cout << "nextafter(x, y) = " << result << endl;
return 0;
}
运行该程序时,输出为:
nextafter(x, y) = 1.79769e+308