erf()函数计算传递给该函数的参数的错误函数值。
假设数字是" x":
float erf( float x); double erf( double x); long double erf( long double x); double erf( integral x);
x :这是一个浮点值。
它返回x的误差函数值。
参数 | 返回值 |
---|---|
x=±0 | ±0 |
x=± infinite | ±1 |
x=nan | nan |
让我们看一个简单的例子。
#include <iostream> #include<math.h> using namespace std; int main() { double x= 6.2; cout<<"Value of x is : "<<x<<'\n'; cout<<"erf(x) : "<<erf(x); return 0; }
输出:
Value of x is : 6.2 erf(x) : 1
在上面的示例中,x的值为6.2。 erf()函数返回值即1。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-erf-function.html
来源:LearnFk无涯教程网
让我们看一个简单的例子,当x的值是无穷大时。
#include <iostream> #include<math.h> using namespace std; int main() { double x= 1.0/0.0; cout<<"Value of x is : "<<x<<'\n'; cout<<"erf(x) : "<<erf(x); return 0; }
输出:
Value of x is : inf erf(x) : 1
在上面的示例中,x的值是无限的。因此,函数erf()返回值1。
让我们看一个简单的例子,当x的值为零时。
#include <iostream> #include<math.h> using namespace std; int main() { float x= 0.0; cout<<"Value of x is : "<<x<<'\n'; cout<<"erf(x) : "<<erf(x); return 0; }
输出:
Value of x is : 0 erf(x) : 0
在上面的示例中,x的值为零。因此,函数erf()返回0值。
让我们看一下x的值为nan时的简单示例。
#include <iostream> #include<math.h> using namespace std; int main() { float x= 0.0/0.0; cout<<"Value of x is : "<<x<<'\n'; cout<<"erf(x) : "<<erf(x); return 0; }
输出:
Value of x is : -nan erf(x) : -nan
在上面的示例中,x的值为nan。因此,函数erf()返回nan。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)