nexttoword()函数表示特定方向上的下一个可表示值。 nextafter()和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);
(from,to):这些是浮点值。
让我们看一个简单的例子。
#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<<'\n'; cout<<nexttoward(from,to); return 0; }
输出:
Values of from and to are:0, -1 -3.6452e-4951
在上面的示例中," from"和" to"具有不同的类型。 nexttoward()函数返回值-3.6452e-4951。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)