summaryrefslogtreecommitdiff
path: root/regress/lib/libc
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2004-01-16 19:34:38 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2004-01-16 19:34:38 +0000
commit7317e942cfa29a56abdf29fbc27ec542c2739bc3 (patch)
treec946e2679463455bad57198cabdbc9f4d21a1933 /regress/lib/libc
parentd8dc7ec89b882a404c52b10ce3c57171173ac793 (diff)
Test more ways of producing a positive infinity, and then test negative
infinity as well to prevent entropy leak; the usual suspects still fail all tests.
Diffstat (limited to 'regress/lib/libc')
-rw-r--r--regress/lib/libc/ieeefp/infinity/Makefile17
-rw-r--r--regress/lib/libc/ieeefp/infinity/infinity.c59
2 files changed, 67 insertions, 9 deletions
diff --git a/regress/lib/libc/ieeefp/infinity/Makefile b/regress/lib/libc/ieeefp/infinity/Makefile
index a593fcf37db..ac102d8a63e 100644
--- a/regress/lib/libc/ieeefp/infinity/Makefile
+++ b/regress/lib/libc/ieeefp/infinity/Makefile
@@ -1,9 +1,22 @@
-# $OpenBSD: Makefile,v 1.1 2004/01/15 18:53:24 miod Exp $
+# $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $
PROG= infinity
-SRCS= infinity.c
DPADD+= ${LIBM}
LDADD+= -lm
+REGRESS_TARGETS+= add mult neg pumpkin
+
+add: ${PROG}
+ ./${PROG} -a
+
+mult: ${PROG}
+ ./${PROG} -m
+
+neg: ${PROG}
+ ./${PROG} -n
+
+pumpkin: ${PROG}
+ ./${PROG} -p
+
.include <bsd.regress.mk>
diff --git a/regress/lib/libc/ieeefp/infinity/infinity.c b/regress/lib/libc/ieeefp/infinity/infinity.c
index 0f60b4762b8..3b1b71ec90b 100644
--- a/regress/lib/libc/ieeefp/infinity/infinity.c
+++ b/regress/lib/libc/ieeefp/infinity/infinity.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: infinity.c,v 1.1 2004/01/15 18:53:24 miod Exp $ */
+/* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */
/*
* Written by Miodrag Vallat, 2004 - Public Domain
* Inspired from Perl's t/op/arith test #134
@@ -6,6 +6,7 @@
#include <math.h>
#include <signal.h>
+#include <unistd.h>
void
sigfpe(int signum)
@@ -17,16 +18,60 @@ sigfpe(int signum)
int
main(int argc, char *argv[])
{
- double d, u;
+ int opt;
+ double d, two;
int i;
+ char method = 'a';
+
+ while ((opt = getopt(argc, argv, "amnp")) != -1)
+ method = (char)opt;
signal(SIGFPE, sigfpe);
- d = 1.0;
- for (i = 2000; i != 0; i--) {
- d = d * 2.0;
+ switch (method) {
+ case 'a':
+ /* try to produce +Inf through addition */
+ d = 1.0;
+ for (i = 2000; i != 0; i--) {
+ d = d + d;
+ }
+ /* result should be _positive_ infinity */
+ if (!isinf(d) || copysign(1.0, d) < 0.0)
+ return (1);
+ break;
+ case 'm':
+ /* try to produce +Inf through multiplication */
+ d = 1.0;
+ two = 2.0;
+ for (i = 2000; i != 0; i--) {
+ d = d * two;
+ }
+ /* result should be _positive_ infinity */
+ if (!isinf(d) || copysign(1.0, d) < 0.0)
+ return (1);
+ break;
+ case 'n':
+ /* try to produce -Inf through subtraction */
+ d = -1.0;
+ for (i = 2000; i != 0; i--) {
+ d = d + d;
+ }
+ /* result should be _negative_ infinity */
+ if (!isinf(d) || copysign(1.0, d) > 0.0)
+ return (1);
+ break;
+ case 'p':
+ /* try to produce -Inf through multiplication */
+ d = -1.0;
+ two = 2.0;
+ for (i = 2000; i != 0; i--) {
+ d = d * two;
+ }
+ /* result should be _negative_ infinity */
+ if (!isinf(d) || copysign(1.0, d) > 0.0)
+ return (1);
+ break;
}
- /* result should be _positive_ infinity */
- return ((isinf(d) && copysign(1.0, d) > 0.0) ? 0 : 1);
+ return (0);
}