erf(), erfc(), erff(), erfl(), erfcf(), erfcl() — Calculate error and complementary error functions
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
SAA |
both |
Format
SAA:
#include <math.h>
double erf(double x);
double erfc(double x);
Compiler
option: LANGLVL(EXTENDED),
LANGLVL(SAA), or LANGLVL(SAA2) XPG4:
#define _XOPEN_SOURCE
#include <math.h>
double erf(double x);
double erfc(double x);
C99:
#define _ISOC99_SOURCE
#include <math.h>
float erff(float x);
long double erfl(long double x);
float erfcf(float x);
long double erfcl(long double x)
C++ TR1 C99:
#define _TR1_C99
#include <math.h>
float erf(float x);
long double erf(long double x);
float erfc(float x);
long double erfc(long double x);
General description
Calculates the error and complementary error functions:
Because the erfc() function calculates the
value of 1.0 - erf(x),
it is used in place of erf() for large values of x.
Note: The following table shows the viable formats for these functions.
See IEEE binary floating-point for more information
about IEEE Binary Floating-Point.
Function | SPC | Hex | IEEE |
---|---|---|---|
erf | X | X | X |
erff | X | X | |
erfl | X | X | |
erfc | X | X | X |
erfcf | X | X | |
erfcl | X | X |
Returned value
Both erf() and erfc() return the calculated value.
If the correct value would cause underflow, 0 is returned and the value of the macro ERANGE is stored in errno. A range error is returned if x is too large.
Special behavior for IEEE: erf() and erfc() are always successful.
Requirements
This function is exposed by specifying on the compile step either the specific option LANGLVL(LONGLONG) or the general option LANGLVL(EXTENDED).
Example
CELEBE01
/* CELEBE01
This example uses &erf. and &erfc. to compute the error
function of two numbers.
*/
#include <stdio.h>
#include <math.h>
double smallx, largex, value;
int main(void)
{
smallx = 0.1;
largex = 10.0;
value = erf(smallx); /* value = 0.112463 */
printf("Error value for 0.1: %f\n", value);
value = erfc(largex); /* value = 2.088488e-45 */
printf("Error value for 10.0: %e\n", value);
}
Output
Error value for 0.1: 0.112463
Error value for 10.0: 2.088488e-45