From 1d7384540d665cdb91806c51a5b917ad6e152388 Mon Sep 17 00:00:00 2001 From: miod <> Date: Fri, 16 Jan 2004 19:34:37 +0000 Subject: 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. --- src/regress/lib/libc/ieeefp/infinity/Makefile | 17 ++++++- src/regress/lib/libc/ieeefp/infinity/infinity.c | 59 ++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/regress/lib/libc/ieeefp/infinity/Makefile b/src/regress/lib/libc/ieeefp/infinity/Makefile index a593fcf37d..ac102d8a63 100644 --- a/src/regress/lib/libc/ieeefp/infinity/Makefile +++ b/src/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 diff --git a/src/regress/lib/libc/ieeefp/infinity/infinity.c b/src/regress/lib/libc/ieeefp/infinity/infinity.c index 0f60b4762b..3b1b71ec90 100644 --- a/src/regress/lib/libc/ieeefp/infinity/infinity.c +++ b/src/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 #include +#include 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); } -- cgit v1.2.3-55-g6feb