C++ Standard Library C++ STL Library

C++ <cmath> - erf() Function



The C++ <cmath> erf() function returns the error function of the argument. The error function of x is defined as:

erf function

Error functions usually occur in probability, statistics and partial differential equation describing diffusion.

Error Function

Syntax

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

Parameters

x Specify the value.

Return Value

Returns the error function of the argument.

Example:

In the example below, erf() function returns the error function of the given value.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<erf(0)<<"\n";
  cout<<erf(1)<<"\n";
  cout<<erf(2)<<"\n";
  cout<<erf(-1)<<"\n";
  cout<<erf(-2)<<"\n";    
  return 0;
}

The output of the above code will be:

0
0.842701
0.995322
-0.842701
-0.995322

❮ C++ <cmath> Library