erf(x)函数详解

首页 / C++入门教程 / erf(x)函数详解

erf()函数计算传递给该函数的参数的错误函数值。

C++ Math erf() function

erf - 语法

假设数字是" x":

float erf( float x);
double erf( double x);
long double erf( long double x);
double erf( integral x);

erf - 参数

x :这是一个浮点值。

erf - 返回值

它返回x的误差函数值。

参数 返回值
x=±0 ±0
x=± infinite ±1
x=nan nan

erf - 例子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。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-erf-function.html

来源:LearnFk无涯教程网

erf - 例子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。

erf - 例子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值。

erf - 例子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。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

趣谈网络协议 -〔刘超〕

如何做好一场技术演讲 -〔极客时间〕

深入浅出计算机组成原理 -〔徐文浩〕

图解 Google V8 -〔李兵〕

To B市场品牌实战课 -〔曹林〕

React Hooks 核心原理与实战 -〔王沛〕

说透5G -〔杨四昌〕

郭东白的架构课 -〔郭东白〕

网络排查案例课 -〔杨胜辉〕

好记忆不如烂笔头。留下您的足迹吧 :)