Add headers, documentation, and tests for erf() and erfc().

This commit is contained in:
Stephen Heumann 2022-12-17 22:26:59 -06:00
parent 53fcb84352
commit 265a16d2f5
4 changed files with 45 additions and 0 deletions

View File

@ -102,6 +102,12 @@ long double cosl(long double);
double cosh(double);
float coshf(float);
long double coshl(long double);
double erf(double);
float erff(float);
long double erfl(long double);
double erfc(double);
float erfcf(float);
long double erfcl(long double);
double exp(double);
float expf(float);
long double expl(long double);

View File

@ -47,6 +47,8 @@
#define cos(x) __tg_x(cos,(x))
#define cosh(x) __tg_x(cosh,(x))
#define copysign(x,y) __tg_real_x_y(copysign,(x),(y))
#define erf(x) __tg_real_x(erf,(x))
#define erfc(x) __tg_real_x(erfc,(x))
#define exp(x) __tg_x(exp,(x))
#define exp2(x) __tg_real_x(exp2,(x))
#define expm1(x) __tg_real_x(expm1,(x))

View File

@ -333,6 +333,29 @@ int main(void) {
expect_exact(sqrt(+INFINITY), +INFINITY);
expect_domain_error(sqrt(-1.0));
expect_approx(sqrt(100.0), 10.0);
expect_exact(erf(+0.0), +0.0);
expect_exact(erff(-0.0), -0.0);
expect_exact(erf(+INFINITY), +1.0);
expect_exact(erfl(-INFINITY), -1.0);
expect_approx(erfl(-4.20L), -9.999999971445058e-01L);
expect_approx(erfl(-3.00L), -9.999779095030014e-01L);
expect_approx(erfl(-0.01L), -1.128341555584948e-02L);
expect_approx(erfl(0.30L), 3.286267594591276e-01L);
expect_approx(erfl(1.20L), 9.103139782296354e-01L);
expect_approx(erfl(4.01L), 9.999999858030606e-01L);
expect_approx(erfl(1e-4900L), 1.128379167095513e-4900L);
expect_exact(erfc(-INFINITY), 2.0);
expect_exact(erfcf(+INFINITY), +0.0);
expect_exact(erfcl(+0.0), 1.0);
expect_approx(erfcl(-4.45L), 1.999999999689114e+00L);
expect_approx(erfcl(-2.50L), 1.999593047982555e+00L);
expect_approx(erfcl(-0.40L), 1.428392355046668e+00L);
expect_approx(erfcl(0.10L), 8.875370839817150e-01L);
expect_approx(erfcl(0.95L), 1.791091927267220e-01L);
expect_approx(erfcl(9.99L), 2.553157649309533e-45L);
expect_approx(erfcl(105.0L), 4.300838032791244e-4791L);
expect_exact(ceil(+0.0), +0.0);
expect_exact(ceilf(-0.0), -0.0);

View File

@ -1167,6 +1167,20 @@ long double copysignl(long double x, long double y);
These functions return a value with the magnitude of x and the sign of y. If x is a NaN, they return a NaN with the same NaN code but with the sign bit of y.
#include <math.h>
double erf(double x);
float erff(float x);
long double erfl(long double x);
These functions compute the error function of x.
#include <math.h>
double erfc(double x);
float erfcf(float x);
long double erfcl(long double x);
These functions compute the complementary error function of x. Mathematically, erfc(x) equals 1 - erf(x). However, calling the erfc function rather than computing 1 - erf(x) can give a more precise result when erf(x) is close to 1.
#include <math.h>
double exp2(double x);
float exp2f(float x);