C++ Math erf()
C++ Math erf()
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 =±无限 |
±1 |
|
x = nan |
nan |
|
示例1
让我们看一下简单的示例。
#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、
示例2
让我们看一下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、
示例3
让我们看一下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值。
示例4
让我们看一下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。