1ERF(3P) POSIX Programmer's Manual ERF(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 erf, erff, erfl — error functions
13
15 #include <math.h>
16
17 double erf(double x);
18 float erff(float x);
19 long double erfl(long double x);
20
22 The functionality described on this reference page is aligned with the
23 ISO C standard. Any conflict between the requirements described here
24 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
25 defers to the ISO C standard.
26
27 These functions shall compute the error function of their argument x,
28 defined as:
29
30 √_2π_x0∫e^ −t^2 dt
31
32 An application wishing to check for error situations should set errno
33 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
34 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
35 FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
36 occurred.
37
39 Upon successful completion, these functions shall return the value of
40 the error function.
41
42 If x is NaN, a NaN shall be returned.
43
44 If x is ±0, ±0 shall be returned.
45
46 If x is ±Inf, ±1 shall be returned.
47
48 If the correct value would cause underflow, a range error may occur,
49 and erf(), erff(), and erfl() shall return an implementation-defined
50 value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN,
51 respectively.
52
53 If the IEC 60559 Floating-Point option is supported, 2 * x/sqrt(π)
54 should be returned.
55
57 These functions may fail if:
58
59 Range Error The result underflows.
60
61 If the integer expression (math_errhandling & MATH_ERRNO)
62 is non-zero, then errno shall be set to [ERANGE]. If the
63 integer expression (math_errhandling & MATH_ERREXCEPT) is
64 non-zero, then the underflow floating-point exception shall
65 be raised.
66
67 The following sections are informative.
68
70 Computing the Probability for a Normal Variate
71 This example shows how to use erf() to compute the probability that a
72 normal variate assumes a value in the range [x1,x2] with x1≤x2.
73
74 This example uses the constant M_SQRT1_2 which is part of the XSI
75 option.
76
77
78 #include <math.h>
79
80 double
81 Phi(const double x1, const double x2)
82 {
83 return ( erf(x2*M_SQRT1_2) - erf(x1*M_SQRT1_2) ) / 2;
84 }
85
87 Underflow occurs when |x| < DBL_MIN * (sqrt(π)/2).
88
89 On error, the expressions (math_errhandling & MATH_ERRNO) and
90 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
91 at least one of them must be non-zero.
92
94 None.
95
97 None.
98
100 erfc(), feclearexcept(), fetestexcept(), isnan()
101
102 The Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of
103 Error Conditions for Mathematical Functions, <math.h>
104
106 Portions of this text are reprinted and reproduced in electronic form
107 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
108 table Operating System Interface (POSIX), The Open Group Base Specifi‐
109 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
110 Electrical and Electronics Engineers, Inc and The Open Group. In the
111 event of any discrepancy between this version and the original IEEE and
112 The Open Group Standard, the original IEEE and The Open Group Standard
113 is the referee document. The original Standard can be obtained online
114 at http://www.opengroup.org/unix/online.html .
115
116 Any typographical or formatting errors that appear in this page are
117 most likely to have been introduced during the conversion of the source
118 files to man page format. To report such errors, see https://www.ker‐
119 nel.org/doc/man-pages/reporting_bugs.html .
120
121
122
123IEEE/The Open Group 2017 ERF(3P)