diff options
author | 2008-06-11 15:07:34 +0000 | |
---|---|---|
committer | 2008-06-11 15:07:34 +0000 | |
commit | 4ab43f456d3cce1315b0c5ab44beaffd0d6bcf4c (patch) | |
tree | 3c6aa937cdea65269102621ccc890cc871b44f7c | |
parent | Import vlan support from upstream libpcap. This allows, eg, "tcpdump vla 3" (diff) | |
download | wireguard-openbsd-4ab43f456d3cce1315b0c5ab44beaffd0d6bcf4c.tar.xz wireguard-openbsd-4ab43f456d3cce1315b0c5ab44beaffd0d6bcf4c.zip |
regression tests for the upcomming tgamma bits
-rw-r--r-- | regress/lib/libm/Makefile | 4 | ||||
-rw-r--r-- | regress/lib/libm/tgamma/Makefile | 8 | ||||
-rw-r--r-- | regress/lib/libm/tgamma/tgamma.c | 105 |
3 files changed, 115 insertions, 2 deletions
diff --git a/regress/lib/libm/Makefile b/regress/lib/libm/Makefile index dc270439677..b397ee4865e 100644 --- a/regress/lib/libm/Makefile +++ b/regress/lib/libm/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.7 2006/03/15 21:44:41 otto Exp $ +# $OpenBSD: Makefile,v 1.8 2008/06/11 15:07:34 martynas Exp $ -SUBDIR+= exp floor rint toint trivial1 +SUBDIR+= exp floor rint tgamma toint trivial1 install: diff --git a/regress/lib/libm/tgamma/Makefile b/regress/lib/libm/tgamma/Makefile new file mode 100644 index 00000000000..b8ec38ca4a3 --- /dev/null +++ b/regress/lib/libm/tgamma/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1 2008/06/11 15:07:34 martynas Exp $ + +PROG=tgamma + +LDADD=-lm +DPADD=${LIBM} + +.include <bsd.regress.mk> diff --git a/regress/lib/libm/tgamma/tgamma.c b/regress/lib/libm/tgamma/tgamma.c new file mode 100644 index 00000000000..a3b1b6964a6 --- /dev/null +++ b/regress/lib/libm/tgamma/tgamma.c @@ -0,0 +1,105 @@ +/* $OpenBSD: tgamma.c,v 1.1 2008/06/11 15:07:34 martynas Exp $ */ + +/* Written by Martynas Venckus, 2008, Public domain. */ + +#include <err.h> +#include <errno.h> +#include <math.h> + +extern int errno; + +#if defined(__vax__) +#define _IEEE 0 +#else +#define _IEEE 1 +#endif + +double +infnan(int iarg) +{ + switch (iarg) { + case ERANGE: + errno = ERANGE; + return (HUGE); + case -ERANGE: + errno = EDOM; + return (-HUGE); + default: + errno = EDOM; + return (0); + } +} + +int +_isinf(double x) +{ + if (_IEEE) { + return isinf(x); + } + else { + return errno == ERANGE; + } +} + +int +_isnan(double x) +{ + if (_IEEE) { + return isnan(x); + } + else { + return errno == ERANGE; + } +} + +int +main(void) +{ + double x; + + /* Random values, approx. -177.79..171.63 */ + x = tgamma(11.0); /* (11 - 1)! */ + if (floor(x) != 3628800.0) + errx(1, "tgamma(11.0) = %f", x); + + x = tgamma(3.5); /* 15/8 * sqrt(pi) */ + if (floor(x * 100) != 332.0) + errx(1, "tgamma(3.5) = %f", x); + + x = tgamma(-0.5); /* -2 * sqrt(pi) */ + if (floor(x * 100) != -355.0) + errx(1, "tgamma(-0.5) = %f", x); + + /* Special cases */ + x = tgamma(-1); /* Negative integers */ + if (!_isnan(x)) + errx(1, "tgamma(-1) = %f", x); + + x = tgamma(-177.8); /* x ~< -177.79 */ + if (x != 0) + errx(1, "tgamma(-177.8) = %f", x); + + x = tgamma(171.64); /* x ~> 171.63 */ + if (!_isinf(x)) + errx(1, "tgamma(171.64) = %f", x); + + x = tgamma(0); + if (!_isinf(x)) + errx(1, "tgamma(0) = %f", x); + + x = tgamma(-HUGE_VAL); + if (!_isnan(x)) + errx(1, "tgamma(-HUGE_VAL) = %f", x); + + x = tgamma(HUGE_VAL); + if (!_isinf(x)) + errx(1, "tgamma(HUGE_VAL) = %f", x); + +#if _IEEE /* VAX doesn't have NaN */ + x = tgamma(0.0/0.0); + if (!_isnan(x)) + errx(1, "tgamma(NaN) = %f", x); +#endif + + return 0; +} |