ERF(3P)
π ERF(3P) β the error function page, bestie edition π
okay so real talk first: this is ERF(3P) from the POSIX Programmer's Manual, and we're doing the whole thing, every crumb, no skips. π
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. Heads up though β the Linux implementation of this interface may differ (so go read the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not be implemented on Linux at all. π
β¨ NAME β¨
erf, erff, erfl β error functions. that's the whole name section, she's short and iconic π
π SYNOPSIS π
#include <math.h>
double erf(double x);
float erff(float x);
long double erfl(long double x);
π¦ DESCRIPTION π¦
The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional β like, not on purpose, bestie. This volume of POSIX.1β2017 defers to the ISO C standard. periodt. π
These functions shall compute the error function of their argument x, defined as:
__β«e^ βt^2 dt
Now, if you're an application and you wanna check for error situations, here's the ritual: set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. Then on return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero β congrats, an error has occurred. π
π RETURN VALUE π
Upon successful completion, these functions shall return the value of the error function. slay.
- If
xisNaN, aNaNshall be returned. - If
xisΒ±0,Β±0shall be returned. - If
xisΒ±Inf,Β±1shall be returned. - If the correct value would cause underflow, a range error may occur, and
erf(),erff(), anderfl()shall return an implementation-defined value no greater in magnitude thanDBL_MIN,FLT_MIN, andLDBL_MIN, respectively. (yes, all three, in that order, iykyk.) - If the IEC 60559 Floating-Point option is supported,
2 * x/sqrt(Ο)should be returned.
π ERRORS π
These functions may fail if:
- Range Error β The result underflows.
- If the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[ERANGE]. If the integer expression(math_errhandling & MATH_ERREXCEPT)is non-zero, then the underflow floating-point exception shall be raised. π¨
- If the integer expression
The following sections are informative. (translation: the drama is over, this part is just vibes and lore π)
π§ EXAMPLES π§
Computing the Probability for a Normal Variate
This example shows how to use erf() to compute the probability that a normal variate assumes a value in the range [x1,x2] with x1β€x2.
This example uses the constant M_SQRT1_2 which is part of the XSI option. π
#include <math.h>
double
Phi(const double x1, const double x2)
{
return ( erf(x2*M_SQRT1_2) - erf(x1*M_SQRT1_2) ) / 2;
}
π«Ά APPLICATION USAGE π«Ά
Underflow occurs when |x| < DBL_MIN * (sqrt(Ο)/2).
On error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other, but at least one of them must be non-zero. they're doing their own thing, but somebody's gotta show up. π
β RATIONALE β
None.
(yes really. she said nothing. iconic behavior honestly.)
π₯ FUTURE DIRECTIONS π₯
None.
π SEE ALSO π
erfc(), feclearexcept(), fetestexcept(), isnan()
The Base Definitions volume of POSIX.1β2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! πΈ this one came from IEEE/The Open Group, 2017 β ERF(3P), POSIX Programmer's Manual energy, and she ate. β¨ππ¦ go call erf() on something and be free. π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms