diff options
| author | miod <> | 2004-01-16 19:34:37 +0000 |
|---|---|---|
| committer | miod <> | 2004-01-16 19:34:37 +0000 |
| commit | 1d7384540d665cdb91806c51a5b917ad6e152388 (patch) | |
| tree | 0ecf047fe559923a042a7b510dfd183368919b9d /src | |
| parent | b4594fd38896c2ffb37c430cb680d9a4a2c6ad0d (diff) | |
| download | openbsd-1d7384540d665cdb91806c51a5b917ad6e152388.tar.gz openbsd-1d7384540d665cdb91806c51a5b917ad6e152388.tar.bz2 openbsd-1d7384540d665cdb91806c51a5b917ad6e152388.zip | |
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 'src')
| -rw-r--r-- | src/regress/lib/libc/ieeefp/infinity/Makefile | 17 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/infinity/infinity.c | 59 |
2 files changed, 67 insertions, 9 deletions
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 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/01/15 18:53:24 miod Exp $ | 1 | # $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $ |
| 2 | 2 | ||
| 3 | PROG= infinity | 3 | PROG= infinity |
| 4 | SRCS= infinity.c | ||
| 5 | 4 | ||
| 6 | DPADD+= ${LIBM} | 5 | DPADD+= ${LIBM} |
| 7 | LDADD+= -lm | 6 | LDADD+= -lm |
| 8 | 7 | ||
| 8 | REGRESS_TARGETS+= add mult neg pumpkin | ||
| 9 | |||
| 10 | add: ${PROG} | ||
| 11 | ./${PROG} -a | ||
| 12 | |||
| 13 | mult: ${PROG} | ||
| 14 | ./${PROG} -m | ||
| 15 | |||
| 16 | neg: ${PROG} | ||
| 17 | ./${PROG} -n | ||
| 18 | |||
| 19 | pumpkin: ${PROG} | ||
| 20 | ./${PROG} -p | ||
| 21 | |||
| 9 | .include <bsd.regress.mk> | 22 | .include <bsd.regress.mk> |
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 @@ | |||
| 1 | /* $OpenBSD: infinity.c,v 1.1 2004/01/15 18:53:24 miod Exp $ */ | 1 | /* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Miodrag Vallat, 2004 - Public Domain | 3 | * Written by Miodrag Vallat, 2004 - Public Domain |
| 4 | * Inspired from Perl's t/op/arith test #134 | 4 | * Inspired from Perl's t/op/arith test #134 |
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <math.h> | 7 | #include <math.h> |
| 8 | #include <signal.h> | 8 | #include <signal.h> |
| 9 | #include <unistd.h> | ||
| 9 | 10 | ||
| 10 | void | 11 | void |
| 11 | sigfpe(int signum) | 12 | sigfpe(int signum) |
| @@ -17,16 +18,60 @@ sigfpe(int signum) | |||
| 17 | int | 18 | int |
| 18 | main(int argc, char *argv[]) | 19 | main(int argc, char *argv[]) |
| 19 | { | 20 | { |
| 20 | double d, u; | 21 | int opt; |
| 22 | double d, two; | ||
| 21 | int i; | 23 | int i; |
| 24 | char method = 'a'; | ||
| 25 | |||
| 26 | while ((opt = getopt(argc, argv, "amnp")) != -1) | ||
| 27 | method = (char)opt; | ||
| 22 | 28 | ||
| 23 | signal(SIGFPE, sigfpe); | 29 | signal(SIGFPE, sigfpe); |
| 24 | 30 | ||
| 25 | d = 1.0; | 31 | switch (method) { |
| 26 | for (i = 2000; i != 0; i--) { | 32 | case 'a': |
| 27 | d = d * 2.0; | 33 | /* try to produce +Inf through addition */ |
| 34 | d = 1.0; | ||
| 35 | for (i = 2000; i != 0; i--) { | ||
| 36 | d = d + d; | ||
| 37 | } | ||
| 38 | /* result should be _positive_ infinity */ | ||
| 39 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
| 40 | return (1); | ||
| 41 | break; | ||
| 42 | case 'm': | ||
| 43 | /* try to produce +Inf through multiplication */ | ||
| 44 | d = 1.0; | ||
| 45 | two = 2.0; | ||
| 46 | for (i = 2000; i != 0; i--) { | ||
| 47 | d = d * two; | ||
| 48 | } | ||
| 49 | /* result should be _positive_ infinity */ | ||
| 50 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
| 51 | return (1); | ||
| 52 | break; | ||
| 53 | case 'n': | ||
| 54 | /* try to produce -Inf through subtraction */ | ||
| 55 | d = -1.0; | ||
| 56 | for (i = 2000; i != 0; i--) { | ||
| 57 | d = d + d; | ||
| 58 | } | ||
| 59 | /* result should be _negative_ infinity */ | ||
| 60 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
| 61 | return (1); | ||
| 62 | break; | ||
| 63 | case 'p': | ||
| 64 | /* try to produce -Inf through multiplication */ | ||
| 65 | d = -1.0; | ||
| 66 | two = 2.0; | ||
| 67 | for (i = 2000; i != 0; i--) { | ||
| 68 | d = d * two; | ||
| 69 | } | ||
| 70 | /* result should be _negative_ infinity */ | ||
| 71 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
| 72 | return (1); | ||
| 73 | break; | ||
| 28 | } | 74 | } |
| 29 | 75 | ||
| 30 | /* result should be _positive_ infinity */ | 76 | return (0); |
| 31 | return ((isinf(d) && copysign(1.0, d) > 0.0) ? 0 : 1); | ||
| 32 | } | 77 | } |
