當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Math erfc()用法及代碼示例

erfc() 函數計算傳遞給函數的參數的互補誤差函數值。

假設一個數字是 'x':

erfc(x) = 1-erf(x);

用法

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

參數

x: 它是一個浮點值。

返回值

它返回 x 的互補誤差函數值。

參數 返回值
x=+∞ +0
x= -∞ 2
x=nan nan

例子1

讓我們看看 x 的值為 +∞ 時的簡單示例。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= 2.0/0.0;
     cout<<"Value of x is:"<<x<<'\n';
     cout<<"erfc(x):"<<erfc(x);
     return 0;
}

輸出:

Value of x is:inf
erfc(x):0

在上麵的例子中,x 的值為正無窮大。因此,函數 erfc() 返回 0 值。

例子2

當 x 的值為 -∞ 時,讓我們看一個簡單的例子。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= -1.0/0.0;
     cout<<"Value of x is:"<<x<<'\n';
     cout<<"erfc(x):"<<erfc(x);
     return 0;
}

輸出:

Value of x is:-inf
erfc(x):2

在上麵的例子中,x 的值為負無窮大。因此,函數 erfc() 返回 2。

例子3

讓我們看一個簡單的例子,當 x 的值為 nan 時。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= sqrt(-2);
     cout<<"Value of x is:"<<x<<'\n';
     cout<<"erfc(x):"<<erfc(x);
     return 0;
}

輸出:

Value of x is:-nan
erfc(x):-nan

在上麵的例子中,x 的值為 nan。因此,函數 erfc() 返回 nan。






相關用法


注:本文由純淨天空篩選整理自 C++ Math erfc()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。