nexttoword()函数表示特定方向上的下一个可表示值。 nextafter()和nexttoward()这两个函数的工作类似,并返回相同的值。唯一的区别在于语法。
nexttoward - 语法
float nexttoward(float from, long double to); double nexttoward(double from, long double to); long double nexttoward(long double from, long double to); double nexttoward(integral from, long double to);
nexttoward - 参数
(from,to):这些是浮点值。
nexttoward - 返回值
- 如果" from"等于" to",则返回" from"的值。
- 如果没有错误发生,则返回" from"的下一个可表示值。
nexttoward - 示例
让我们看一个简单的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long double from=0.0;
double to= -1.0;
cout<<"Values of from and to are:"<<from<<", "<<to<<
;
cout<<nexttoward(from,to);
return 0;
}
输出:
Values of from and to are:0, -1 -3.6452e-4951
在上面的示例中," from"和" to"具有不同的类型。 nexttoward()函数返回值-3.6452e-4951。