summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2008-09-07 20:36:11 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2008-09-07 20:36:11 +0000
commit319618ea76ca9de5c1e1b02bff3bddbdf5c46dc7 (patch)
tree402fb699f6a3a45a23dce26a3952cfee3d992421 /regress
parent6e9298963b5a9bb500e3f8308cd681b32638fb31 (diff)
- replace dtoa w/ David's gdtoa, version 2008-03-15
- provide proper dtoa locks - use the real strtof implementation - add strtold, __hdtoa, __hldtoa - add %a/%A support - don't lose precision in printf, don't round to double anymore - implement extended-precision versions of libc functions: fpclassify, isnan, isinf, signbit, isnormal, isfinite, now that the ieee.h is fixed - separate vax versions of strtof, and __hdtoa - add complex math support. added functions: cacos, casin, catan, ccos, csin, ctan, cacosh, casinh, catanh, ccosh, csinh, ctanh, cexp, clog, cabs, cpow, csqrt, carg, cimag, conj, cproj, creal, cacosf, casinf, catanf, ccosf, csinf, ctanf, cacoshf, casinhf, catanhf, ccoshf, csinhf, ctanhf, cexpf, clogf, cabsf, cpowf, csqrtf, cargf, cimagf, conjf, cprojf, crealf - add fdim, fmax, fmin - add log2. (adapted implementation e_log.c. could be more acruate & faster, but it's good enough for now) - remove wrappers & cruft in libm, supposed to work-around mistakes in SVID, etc.; use ieee versions. fixes issues in python 2.6 for djm@ - make _digittoint static - proper definitions for i386, and amd64 in ieee.h - sh, powerpc don't really have extended-precision - add missing definitions for mips64 (quad), m{6,8}k (96-bit) float.h for LDBL_* - merge lead to frac for m{6,8}k, for gdtoa to work properly - add FRAC*BITS & EXT_TO_ARRAY32 definitions in ieee.h, for hdtoa&ldtoa to use - add EXT_IMPLICIT_NBIT definition, which indicates implicit normalization bit - add regression tests for libc: fpclassify and printf - arith.h & gd_qnan.h definitions - update ieee.h: hppa doesn't have quad-precision, hppa64 does - add missing prototypes to gdtoaimp - on 64-bit platforms make sure gdtoa doesn't use a long when it really wants an int - etc., what i may have forgotten... - bump libm major, due to removed&changed symbols - no libc bump, since this is riding on djm's libc major crank from a day ago discussed with / requested by / testing theo, sthen@, djm@, jsg@, merdely@, jsing@, tedu@, brad@, jakemsr@, and others. looks good to millert@ parts of the diff ok kettenis@ this commit does not include: - man page changes
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libc/Makefile8
-rw-r--r--regress/lib/libc/fpclassify/Makefile5
-rw-r--r--regress/lib/libc/fpclassify/fpclassify.c76
-rw-r--r--regress/lib/libc/printf/Makefile5
-rw-r--r--regress/lib/libc/printf/fp.c217
-rw-r--r--regress/lib/libm/tgamma/tgamma.c14
6 files changed, 316 insertions, 9 deletions
diff --git a/regress/lib/libc/Makefile b/regress/lib/libc/Makefile
index 689f87aa03b..dc9beab1e15 100644
--- a/regress/lib/libc/Makefile
+++ b/regress/lib/libc/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.26 2007/09/03 14:42:43 millert Exp $
+# $OpenBSD: Makefile,v 1.27 2008/09/07 20:36:10 martynas Exp $
-SUBDIR+= _setjmp alloca atexit basename cxa-atexit db dirname getaddrinfo
-SUBDIR+= getcap getopt_long hsearch longjmp locale malloc
-SUBDIR+= netdb popen regex setjmp setjmp-signal sigreturn sigsetjmp
+SUBDIR+= _setjmp alloca atexit basename cxa-atexit db dirname fpclassify
+SUBDIR+= getaddrinfo getcap getopt_long hsearch longjmp locale malloc
+SUBDIR+= netdb popen printf regex setjmp setjmp-signal sigreturn sigsetjmp
SUBDIR+= sprintf strerror strtod strtonum telldir time vis
.if (${MACHINE_ARCH} != "vax")
diff --git a/regress/lib/libc/fpclassify/Makefile b/regress/lib/libc/fpclassify/Makefile
new file mode 100644
index 00000000000..96916d20e70
--- /dev/null
+++ b/regress/lib/libc/fpclassify/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $
+
+PROG= fpclassify
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/fpclassify/fpclassify.c b/regress/lib/libc/fpclassify/fpclassify.c
new file mode 100644
index 00000000000..174c04d983f
--- /dev/null
+++ b/regress/lib/libc/fpclassify/fpclassify.c
@@ -0,0 +1,76 @@
+/* $OpenBSD: fpclassify.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */
+/*-
+ * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/tools/regression/lib/libc/gen/test-fpclassify.c,v 1.3 2003/03/27 05:32:28 das Exp $
+ */
+
+#include <assert.h>
+#include <float.h>
+#include <math.h>
+#include <stdlib.h>
+
+int
+main(void)
+{
+
+ assert(fpclassify((float)0) == FP_ZERO);
+ assert(fpclassify((float)-0.0) == FP_ZERO);
+ assert(fpclassify((float)1) == FP_NORMAL);
+ assert(fpclassify((float)1000) == FP_NORMAL);
+#ifndef __alpha__
+ assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL);
+#endif /* !__alpha__ */
+ assert(fpclassify(HUGE_VALF) == FP_INFINITE);
+ assert(fpclassify((float)HUGE_VAL) == FP_INFINITE);
+ assert(fpclassify((float)HUGE_VALL) == FP_INFINITE);
+ assert(fpclassify(NAN) == FP_NAN);
+
+ assert(fpclassify((double)0) == FP_ZERO);
+ assert(fpclassify((double)-0) == FP_ZERO);
+ assert(fpclassify((double)1) == FP_NORMAL);
+ assert(fpclassify((double)1000) == FP_NORMAL);
+#ifndef __alpha__
+ assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL);
+#endif /* !__alpha__ */
+ assert(fpclassify(HUGE_VAL) == FP_INFINITE);
+ assert(fpclassify((double)HUGE_VALF) == FP_INFINITE);
+ assert(fpclassify((double)HUGE_VALL) == FP_INFINITE);
+ assert(fpclassify((double)NAN) == FP_NAN);
+
+ assert(fpclassify((long double)0) == FP_ZERO);
+ assert(fpclassify((long double)-0.0) == FP_ZERO);
+ assert(fpclassify((long double)1) == FP_NORMAL);
+ assert(fpclassify((long double)1000) == FP_NORMAL);
+#if (LDBL_MANT_DIG > DBL_MANT_DIG)
+ assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL);
+#endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) */
+ assert(fpclassify(HUGE_VALL) == FP_INFINITE);
+ assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE);
+ assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE);
+ assert(fpclassify((long double)NAN) == FP_NAN);
+
+ return (0);
+}
diff --git a/regress/lib/libc/printf/Makefile b/regress/lib/libc/printf/Makefile
new file mode 100644
index 00000000000..c2e2732d6e1
--- /dev/null
+++ b/regress/lib/libc/printf/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $
+
+PROG= fp
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/printf/fp.c b/regress/lib/libc/printf/fp.c
new file mode 100644
index 00000000000..6ed52fdb494
--- /dev/null
+++ b/regress/lib/libc/printf/fp.c
@@ -0,0 +1,217 @@
+/* $OpenBSD: fp.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */
+/*-
+ * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test for printf() floating point formats.
+ */
+
+#include <assert.h>
+#include <err.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define testfmt(result, fmt, ...) \
+ _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__)
+void _testfmt(const char *, int, const char *, const char *, ...);
+void smash_stack(void);
+
+int
+main(int argc, char *argv[])
+{
+ /*
+ * Basic tests of decimal output functionality.
+ */
+ testfmt(" 1.000000E+00", "%13E", 1.0);
+ testfmt(" 1.000000", "%13f", 1.0);
+ testfmt(" 1", "%13G", 1.0);
+ testfmt(" 1.000000E+00", "%13LE", 1.0L);
+ testfmt(" 1.000000", "%13Lf", 1.0L);
+ testfmt(" 1", "%13LG", 1.0L);
+
+ testfmt("2.718282", "%.*f", -2, 2.7182818);
+
+ testfmt("1.234568e+06", "%e", 1234567.8);
+ testfmt("1234567.800000", "%f", 1234567.8);
+ testfmt("1.23457E+06", "%G", 1234567.8);
+ testfmt("1.234568e+06", "%Le", 1234567.8L);
+ testfmt("1234567.800000", "%Lf", 1234567.8L);
+ testfmt("1.23457E+06", "%LG", 1234567.8L);
+
+#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
+ testfmt("123456789.864210", "%Lf", 123456789.8642097531L);
+ testfmt("-1.23457E+08", "%LG", -123456789.8642097531L);
+ testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L);
+ testfmt(" 3.141592653589793238e-4000", "%L27.18Le",
+ 3.14159265358979323846e-4000L);
+#endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */
+
+ /*
+ * Infinities and NaNs
+ */
+#ifdef NAN
+ testfmt("nan", "%e", NAN);
+ testfmt("NAN", "%F", NAN);
+ testfmt("nan", "%g", NAN);
+ testfmt("NAN", "%LE", (long double)NAN);
+ testfmt(" nan", "%05e", NAN);
+#endif /* NAN */
+
+ testfmt("INF", "%E", HUGE_VAL);
+ testfmt("-inf", "%f", -HUGE_VAL);
+ testfmt("+inf", "%+g", HUGE_VAL);
+ testfmt(" inf", "%4.2Le", HUGE_VALL);
+ testfmt("-inf", "%Lf", -HUGE_VALL);
+ testfmt(" inf", "%05e", HUGE_VAL);
+ testfmt(" -inf", "%05e", -HUGE_VAL);
+
+ /*
+ * Padding
+ */
+ testfmt("0.000000e+00", "%e", 0.0);
+ testfmt("0.000000", "%F", (double)0.0);
+ testfmt("0", "%G", 0.0);
+ testfmt(" 0", "%3.0Lg", 0.0L);
+ testfmt(" 0", "%5.0f", 0.001);
+
+ /*
+ * Precision specifiers
+ */
+ testfmt("1.0123e+00", "%.4e", 1.0123456789);
+ testfmt("1.0123", "%.4f", 1.0123456789);
+ testfmt("1.012", "%.4g", 1.0123456789);
+ testfmt("1.2346e-02", "%.4e", 0.0123456789);
+ testfmt("0.0123", "%.4f", 0.0123456789);
+ testfmt("0.01235", "%.4g", 0.0123456789);
+
+ /*
+ * Signed conversions
+ */
+ testfmt("+2.500000e-01", "%+e", 0.25);
+ testfmt("+0.000000", "%+F", 0.0);
+ testfmt("-1", "%+g", -1.0);
+
+ testfmt("-1.000000e+00", "% e", -1.0);
+ testfmt("+1.000000", "% +f", 1.0);
+ testfmt(" 1", "% g", 1.0);
+ testfmt(" 0", "% g", 0.0);
+
+ /*
+ * ``Alternate form''
+ */
+ testfmt("1.250e+00", "%#.3e", 1.25);
+ testfmt("123.000000", "%#f", 123.0);
+ testfmt(" 12345.", "%#7.5g", 12345.0);
+ testfmt(" 1.00000", "%#8g", 1.0);
+ testfmt("0.0", "%#.2g", 0.0);
+
+ /*
+ * Padding and decimal point placement
+ */
+ testfmt("03.2E+00", "%08.1E", 3.25);
+ testfmt("003.25", "%06.2F", 3.25);
+ testfmt("0003.25", "%07.4G", 3.25);
+
+ testfmt("3.14159e-05", "%g", 3.14159e-5);
+ testfmt("0.000314159", "%g", 3.14159e-4);
+ testfmt("3.14159e+06", "%g", 3.14159e6);
+ testfmt("314159", "%g", 3.14159e5);
+ testfmt("314159.", "%#g", 3.14159e5);
+
+ testfmt(" 9.000000e+03", "%13e", 9000.0);
+ testfmt(" 9000.000000", "%12f", 9000.0);
+ testfmt(" 9000", "%5g", 9000.0);
+ testfmt(" 900000.", "%#8g", 900000.0);
+ testfmt(" 9e+06", "%6g", 9000000.0);
+ testfmt(" 9.000000e-04", "%13e", 0.0009);
+ testfmt(" 0.000900", "%9f", 0.0009);
+ testfmt(" 0.0009", "%7g", 0.0009);
+ testfmt(" 9e-05", "%6g", 0.00009);
+ testfmt(" 9.00000e-05", "%#12g", 0.00009);
+ testfmt(" 9.e-05", "%#7.1g", 0.00009);
+
+ testfmt(" 0.0", "%4.1f", 0.0);
+ testfmt("90.0", "%4.1f", 90.0);
+ testfmt(" 100", "%4.0f", 100.0);
+ testfmt("9.0e+01", "%4.1e", 90.0);
+ testfmt("1e+02", "%4.0e", 100.0);
+
+ /*
+ * Hexadecimal floating point (%a, %A) tests. Some of these
+ * are only valid if the implementation converts to hex digits
+ * on nibble boundaries.
+ */
+ testfmt("0x0p+0", "%a", 0x0.0p0);
+ testfmt("0X0.P+0", "%#LA", 0x0.0p0L);
+#ifdef NAN
+ testfmt("inf", "%La", (long double)INFINITY);
+ testfmt("+INF", "%+A", INFINITY);
+ testfmt("nan", "%La", (long double)NAN);
+ testfmt("NAN", "%A", NAN);
+#endif /* NAN */
+
+ testfmt(" 0x1.23p+0", "%10a", 0x1.23p0);
+ testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500);
+ testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40);
+ testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4);
+ testfmt("0x1p-1074", "%a", 0x1p-1074);
+ testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024);
+
+ return (0);
+}
+
+void
+smash_stack(void)
+{
+ static uint32_t junk = 0xdeadbeef;
+ uint32_t buf[512];
+ int i;
+
+ for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++)
+ buf[i] = junk;
+}
+
+void
+_testfmt(const char *result, int line, const char *argstr, const char *fmt,...)
+{
+ char s[100];
+ va_list ap;
+
+ va_start(ap, fmt);
+ smash_stack();
+ vsnprintf(s, sizeof(s), fmt, ap);
+ if (strcmp(result, s) != 0) {
+ fprintf(stderr,
+ "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n",
+ line, fmt, argstr, s, result);
+ abort();
+ }
+}
diff --git a/regress/lib/libm/tgamma/tgamma.c b/regress/lib/libm/tgamma/tgamma.c
index a3b1b6964a6..491fe6efcbb 100644
--- a/regress/lib/libm/tgamma/tgamma.c
+++ b/regress/lib/libm/tgamma/tgamma.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tgamma.c,v 1.1 2008/06/11 15:07:34 martynas Exp $ */
+/* $OpenBSD: tgamma.c,v 1.2 2008/09/07 20:36:10 martynas Exp $ */
/* Written by Martynas Venckus, 2008, Public domain. */
@@ -83,8 +83,12 @@ main(void)
if (!_isinf(x))
errx(1, "tgamma(171.64) = %f", x);
- x = tgamma(0);
- if (!_isinf(x))
+ x = tgamma(0.0);
+ if (!_isinf(x) || x < 0)
+ errx(1, "tgamma(0) = %f", x);
+
+ x = tgamma(-0.0);
+ if (!_isinf(x) || x > 0)
errx(1, "tgamma(0) = %f", x);
x = tgamma(-HUGE_VAL);
@@ -95,8 +99,8 @@ main(void)
if (!_isinf(x))
errx(1, "tgamma(HUGE_VAL) = %f", x);
-#if _IEEE /* VAX doesn't have NaN */
- x = tgamma(0.0/0.0);
+#ifdef NAN
+ x = tgamma(NAN);
if (!_isnan(x))
errx(1, "tgamma(NaN) = %f", x);
#endif