📅  最后修改于: 2020-09-25 08:00:29             🧑  作者: Mango
该函数在
它与nextafter()相同,除了nexttoward()的第二个参数始终为long double
类型。
double nexttoward(double x, long double y);
float nexttoward(float x, long float y);
long double nexttoward(long double x, long double y);
double nexttoward(T x, long double y); // For integral type
nexttoward() 函数接受两个参数,并返回double
, float
或long double
类型的值。
nexttoward() 函数在y方向上返回x之后的下一个可表示值。
#include
#include
using namespace std;
int main()
{
long double y = -1.0;
double x = 0.0;
double result = nexttoward(x, y);
cout << "nexttoward(x, y) = " << result << endl;
return 0;
}
运行该程序时,输出为:
nexttoward(x, y) = -4.94066e-324
#include
#include
#include
using namespace std;
int main()
{
long double y = INFINITY;
int x = INT_MAX;
double result = nexttoward(x,y);
cout << "nexttoward(x, y) = " << result << endl;
return 0;
}
运行该程序时,输出为:
nexttoward(x, y) = 2.14748e+09