nextafter()函数表示特定方向上的下一个可表示值。
假设两个数字是"from"和"to" 。因此,nextafter()函数将在" to"方向上找到" from"的下一个值。
float nextafter( float from, float to); double nextafter( double from, double to); long double nextafter( long double from, long double to); promoted nextafter( arithmetic from, arithmetic to);
(from,to):这些是浮点值。
让我们看一个简单的示例,其中" from"和" to"的值相等。
#include <iostream> #include<math.h> using namespace std; int main() { float from=6.7; float to=6.7; cout<<"Values of from and to are:"<<from<<", "<<to<<'\n'; cout<<nextafter(from,to); return 0; }
输出:
Values of from and to are:6.7, 6.7 6.7
在上面的示例中," from"和" to"的值相等。因此,该函数返回值'from'。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-nextafter-function.html
来源:LearnFk无涯教程网
让我们看一个简单的示例,其中" from"和" to"是同一类型。
#include <iostream> #include<math.h> using namespace std; int main() { double from=0.0; double to=6.0; cout<<"Values of from and to are:"<<from<<", "<<to<<'\n'; cout<<nextafter(from,to); return 0; }
输出:
Values of from and to are:0, 6 4.94066e-324
在上面的示例中,"from"和"to"具有相同的类型,但不相等。 nextafter()函数返回值即4.94066e -324
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)