ERF(3POSIX)

๐ŸŒธ ERF(3POSIX) โ€” the POSIX Programmer's Manual page for erf, bestie ๐Ÿ’–

okay so before we even get into it, you need the tea: this is ERF(3POSIX), and it lives in the POSIX Programmer's Manual. That's the family it belongs to, that's the vibe. ๐ŸŽ€


โœจ PROLOG โœจ

Real talk, bestie โ€” this manual page is part of the POSIX Programmer's Manual. But heads up: the Linux implementation of this interface may differ (so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior), or honestly? The interface may not be implemented on Linux at all. So like, vibe check your platform first. ๐Ÿฆ‹


๐Ÿ‘‘ NAME ๐Ÿ‘‘

erf, erff, erfl โ€” error functions. that's it, that's the name, iconic.


๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

#include <math.h>

double erf(double x);
float erff(float x);
long double erfl(long double x);

three flavors, same energy: double, float, long double. pick your fighter. ๐Ÿ’…


๐Ÿ’– DESCRIPTION ๐Ÿ’–

The functionality described on this reference page is aligned with the ISO C standard. And if there's any conflict between what's written here and the ISO C standard? That conflict is unintentional, okay, nobody's fighting. 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 that wants to check for error situations, here's the routine: set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. Then on return, check โ€” if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, then an error has occurred. no cap. ๐Ÿ”ฅ


๐ŸŒธ RETURN VALUE ๐ŸŒธ

Upon successful completion, these functions shall return the value of the error function. slay.

  • If x is NaN, a NaN shall be returned.
  • If x is ยฑ0, ยฑ0 shall be returned.
  • If x is ยฑInf, ยฑ1 shall be returned.

If the correct value would cause underflow, a range error may occur, and erf(), erff(), and erfl() shall return an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN, respectively. (yes, each one gets its own MIN, they're matching sets ๐Ÿ’œ)

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, then errno shall be set to [ERANGE]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow floating-point exception shall be raised.

The following sections are informative. ๐Ÿ“ข (translation: they're the bonus content, not the binding rules)

๐Ÿงš 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. math girlies stay winning. ๐Ÿ“โœจ

This example uses the constant M_SQRT1_2 which is part of the XSI option. iykyk.

#include <math.h>

double
Phi(const double x1, const double x2)
{
    return ( erf(x2*M_SQRT1_2) - erf(x1*M_SQRT1_2) ) / 2;
}

look at her. she's doing statistics. ๐Ÿซถ


๐Ÿฆ‹ 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 not besties, they're just coworkers who both have to show up. ๐Ÿ˜ญ


โญ RATIONALE โญ

None.

(genuinely. nothing. the rationale said "no thoughts, head empty" and honestly? respect. ๐Ÿ’…)


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

None.


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

erfc(), feclearexcept(), fetestexcept(), isnan()

And from The Base Definitions volume of POSIX.1โ€2017: Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>


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 was brought to you by IEEE/The Open Group, dated 2017, and the page itself answers to the name ERF(3POSIX). go forth and integrate. ๐ŸŒธโœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from