diff options
Diffstat (limited to 'src/regress/lib/libc/ieeefp')
| -rw-r--r-- | src/regress/lib/libc/ieeefp/Makefile | 11 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/Makefile | 13 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/except.c | 79 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/inf/Makefile | 9 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/inf/inf.c | 16 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/infinity/Makefile | 22 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/infinity/infinity.c | 77 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/round/Makefile | 11 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/round/round.c | 3 |
9 files changed, 180 insertions, 61 deletions
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile index 4e2e517b03..89ff51a2e7 100644 --- a/src/regress/lib/libc/ieeefp/Makefile +++ b/src/regress/lib/libc/ieeefp/Makefile | |||
| @@ -1,12 +1,7 @@ | |||
| 1 | # $NetBSD: Makefile,v 1.4 1995/10/03 21:59:36 phil Exp $ | 1 | # $OpenBSD: Makefile,v 1.6 2004/01/15 18:53:23 miod Exp $ |
| 2 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ | ||
| 2 | 3 | ||
| 3 | .if ${MACHINE} == "pc532" | 4 | SUBDIR+= except inf infinity round |
| 4 | SUBDIR+= round | ||
| 5 | .else | ||
| 6 | SUBDIR+= except round | ||
| 7 | .endif | ||
| 8 | |||
| 9 | regress: _SUBDIRUSE | ||
| 10 | 5 | ||
| 11 | install: | 6 | install: |
| 12 | 7 | ||
diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile index 91f24f15f6..ff620e016b 100644 --- a/src/regress/lib/libc/ieeefp/except/Makefile +++ b/src/regress/lib/libc/ieeefp/except/Makefile | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | # $NetBSD: Makefile,v 1.1 1995/04/26 00:27:25 jtc Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:22:26 art Exp $ |
| 2 | 2 | ||
| 3 | PROG= except | 3 | PROG=except |
| 4 | SRCS= except.c | ||
| 5 | NOMAN= | ||
| 6 | 4 | ||
| 7 | install: | 5 | .include <bsd.regress.mk> |
| 8 | |||
| 9 | regress: ${PROG} | ||
| 10 | ./${PROG} | ||
| 11 | |||
| 12 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c index 0ffdcdd468..4e8c17d427 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
| @@ -1,19 +1,37 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.6 2004/04/02 03:06:12 mickey Exp $ */ | ||
| 2 | |||
| 1 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> | ||
| 2 | #include <signal.h> | 5 | #include <signal.h> |
| 3 | #include <assert.h> | 6 | #include <assert.h> |
| 4 | #include <ieeefp.h> | 7 | #include <ieeefp.h> |
| 5 | #include <float.h> | 8 | #include <float.h> |
| 6 | 9 | ||
| 7 | void sigfpe(); | 10 | volatile sig_atomic_t signal_caught; |
| 8 | volatile sig_atomic_t signal_cought; | 11 | |
| 12 | volatile const double one = 1.0; | ||
| 13 | volatile const double zero = 0.0; | ||
| 14 | volatile const double huge = DBL_MAX; | ||
| 15 | volatile const double tiny = DBL_MIN; | ||
| 16 | |||
| 17 | void | ||
| 18 | sigfpe(int sig, siginfo_t *si, void *v) | ||
| 19 | { | ||
| 20 | char buf[132]; | ||
| 21 | |||
| 22 | if (si) { | ||
| 23 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
| 24 | si->si_addr, si->si_code); | ||
| 25 | write(1, buf, strlen(buf)); | ||
| 26 | } | ||
| 27 | signal_caught = 1; | ||
| 28 | } | ||
| 9 | 29 | ||
| 10 | static volatile const double one = 1.0; | ||
| 11 | static volatile const double zero = 0.0; | ||
| 12 | static volatile const double huge = DBL_MAX; | ||
| 13 | static volatile const double tiny = DBL_MIN; | ||
| 14 | 30 | ||
| 15 | main() | 31 | int |
| 32 | main(int argc, char *argv[]) | ||
| 16 | { | 33 | { |
| 34 | struct sigaction sa; | ||
| 17 | volatile double x; | 35 | volatile double x; |
| 18 | 36 | ||
| 19 | /* | 37 | /* |
| @@ -23,65 +41,60 @@ main() | |||
| 23 | assert(fpgetmask() == 0); | 41 | assert(fpgetmask() == 0); |
| 24 | assert(fpgetsticky() == 0); | 42 | assert(fpgetsticky() == 0); |
| 25 | 43 | ||
| 26 | /* set up signal handler */ | 44 | memset(&sa, 0, sizeof(sa)); |
| 27 | signal (SIGFPE, sigfpe); | 45 | sa.sa_sigaction = sigfpe; |
| 28 | signal_cought = 0; | 46 | sa.sa_flags = SA_SIGINFO; |
| 47 | sigaction(SIGFPE, &sa, NULL); | ||
| 48 | signal_caught = 0; | ||
| 29 | 49 | ||
| 30 | /* trip divide by zero */ | 50 | /* trip divide by zero */ |
| 31 | x = one / zero; | 51 | x = one / zero; |
| 32 | assert (fpgetsticky() & FP_X_DZ); | 52 | assert(fpgetsticky() & FP_X_DZ); |
| 33 | assert (signal_cought == 0); | 53 | assert(signal_caught == 0); |
| 34 | fpsetsticky(0); | 54 | fpsetsticky(0); |
| 35 | 55 | ||
| 36 | /* trip invalid operation */ | 56 | /* trip invalid operation */ |
| 37 | x = zero / zero; | 57 | x = zero / zero; |
| 38 | assert (fpgetsticky() & FP_X_INV); | 58 | assert(fpgetsticky() & FP_X_INV); |
| 39 | assert (signal_cought == 0); | 59 | assert(signal_caught == 0); |
| 40 | fpsetsticky(0); | 60 | fpsetsticky(0); |
| 41 | 61 | ||
| 42 | /* trip overflow */ | 62 | /* trip overflow */ |
| 43 | x = huge * huge; | 63 | x = huge * huge; |
| 44 | assert (fpgetsticky() & FP_X_OFL); | 64 | assert(fpgetsticky() & FP_X_OFL); |
| 45 | assert (signal_cought == 0); | 65 | assert(signal_caught == 0); |
| 46 | fpsetsticky(0); | 66 | fpsetsticky(0); |
| 47 | 67 | ||
| 48 | /* trip underflow */ | 68 | /* trip underflow */ |
| 49 | x = tiny * tiny; | 69 | x = tiny * tiny; |
| 50 | assert (fpgetsticky() & FP_X_UFL); | 70 | assert(fpgetsticky() & FP_X_UFL); |
| 51 | assert (signal_cought == 0); | 71 | assert(signal_caught == 0); |
| 52 | fpsetsticky(0); | 72 | fpsetsticky(0); |
| 53 | 73 | ||
| 54 | #if 0 | ||
| 55 | /* unmask and then trip divide by zero */ | 74 | /* unmask and then trip divide by zero */ |
| 56 | fpsetmask(FP_X_DZ); | 75 | fpsetmask(FP_X_DZ); |
| 57 | x = one / zero; | 76 | x = one / zero; |
| 58 | assert (signal_cought == 1); | 77 | assert(signal_caught == 1); |
| 59 | signal_cought = 0; | 78 | signal_caught = 0; |
| 60 | 79 | ||
| 61 | /* unmask and then trip invalid operation */ | 80 | /* unmask and then trip invalid operation */ |
| 62 | fpsetmask(FP_X_INV); | 81 | fpsetmask(FP_X_INV); |
| 63 | x = zero / zero; | 82 | x = zero / zero; |
| 64 | assert (signal_cought == 1); | 83 | assert(signal_caught == 1); |
| 65 | signal_cought = 0; | 84 | signal_caught = 0; |
| 66 | 85 | ||
| 67 | /* unmask and then trip overflow */ | 86 | /* unmask and then trip overflow */ |
| 68 | fpsetmask(FP_X_OFL); | 87 | fpsetmask(FP_X_OFL); |
| 69 | x = huge * huge; | 88 | x = huge * huge; |
| 70 | assert (signal_cought == 1); | 89 | assert(signal_caught == 1); |
| 71 | signal_cought = 0; | 90 | signal_caught = 0; |
| 72 | 91 | ||
| 73 | /* unmask and then trip underflow */ | 92 | /* unmask and then trip underflow */ |
| 74 | fpsetmask(FP_X_UFL); | 93 | fpsetmask(FP_X_UFL); |
| 75 | x = tiny * tiny; | 94 | x = tiny * tiny; |
| 76 | assert (signal_cought == 1); | 95 | assert (signal_caught == 1); |
| 77 | signal_cought = 0; | 96 | signal_caught = 0; |
| 78 | #endif | ||
| 79 | 97 | ||
| 80 | exit(0); | 98 | exit(0); |
| 81 | } | 99 | } |
| 82 | 100 | ||
| 83 | void | ||
| 84 | sigfpe() | ||
| 85 | { | ||
| 86 | signal_cought = 1; | ||
| 87 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/Makefile b/src/regress/lib/libc/ieeefp/inf/Makefile new file mode 100644 index 0000000000..b9a50e0ce6 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/inf/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 17:22:16 pvalchev Exp $ | ||
| 2 | |||
| 3 | PROG= inf | ||
| 4 | SRCS= inf.c | ||
| 5 | |||
| 6 | LDADD+= -lm | ||
| 7 | DPADD+= ${LIBM} | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/inf.c b/src/regress/lib/libc/ieeefp/inf/inf.c new file mode 100644 index 0000000000..a1956145a6 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/inf/inf.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* $OpenBSD: inf.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Peter Valchev <pvalchev@openbsd.org> Public Domain, 2002. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <math.h> | ||
| 8 | |||
| 9 | int | ||
| 10 | main(int argc, char *argv[]) | ||
| 11 | { | ||
| 12 | if (isinf(HUGE_VAL)) | ||
| 13 | return 0; | ||
| 14 | |||
| 15 | return 1; | ||
| 16 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/Makefile b/src/regress/lib/libc/ieeefp/infinity/Makefile new file mode 100644 index 0000000000..ac102d8a63 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/infinity/Makefile | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $ | ||
| 2 | |||
| 3 | PROG= infinity | ||
| 4 | |||
| 5 | DPADD+= ${LIBM} | ||
| 6 | LDADD+= -lm | ||
| 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 | |||
| 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 new file mode 100644 index 0000000000..3b1b71ec90 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/infinity/infinity.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Miodrag Vallat, 2004 - Public Domain | ||
| 4 | * Inspired from Perl's t/op/arith test #134 | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <math.h> | ||
| 8 | #include <signal.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | void | ||
| 12 | sigfpe(int signum) | ||
| 13 | { | ||
| 14 | /* looks like we don't handle fp overflow correctly... */ | ||
| 15 | _exit(1); | ||
| 16 | } | ||
| 17 | |||
| 18 | int | ||
| 19 | main(int argc, char *argv[]) | ||
| 20 | { | ||
| 21 | int opt; | ||
| 22 | double d, two; | ||
| 23 | int i; | ||
| 24 | char method = 'a'; | ||
| 25 | |||
| 26 | while ((opt = getopt(argc, argv, "amnp")) != -1) | ||
| 27 | method = (char)opt; | ||
| 28 | |||
| 29 | signal(SIGFPE, sigfpe); | ||
| 30 | |||
| 31 | switch (method) { | ||
| 32 | case 'a': | ||
| 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; | ||
| 74 | } | ||
| 75 | |||
| 76 | return (0); | ||
| 77 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/round/Makefile b/src/regress/lib/libc/ieeefp/round/Makefile index 571133436c..9ea6dd8c39 100644 --- a/src/regress/lib/libc/ieeefp/round/Makefile +++ b/src/regress/lib/libc/ieeefp/round/Makefile | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | # $NetBSD: Makefile,v 1.1 1995/04/26 00:27:27 jtc Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:25:34 art Exp $ |
| 2 | 2 | ||
| 3 | PROG= round | 3 | PROG= round |
| 4 | SRCS= round.c | ||
| 5 | NOMAN= | ||
| 6 | 4 | ||
| 7 | install: | 5 | .include <bsd.regress.mk> |
| 8 | |||
| 9 | regress: ${PROG} | ||
| 10 | ./${PROG} | ||
| 11 | |||
| 12 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/round/round.c b/src/regress/lib/libc/ieeefp/round/round.c index b9fcd9771e..807941ea56 100644 --- a/src/regress/lib/libc/ieeefp/round/round.c +++ b/src/regress/lib/libc/ieeefp/round/round.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 1 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ | 2 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ |
| 2 | 3 | ||
| 3 | /* | 4 | /* |
| @@ -11,7 +12,7 @@ | |||
| 11 | #include <float.h> | 12 | #include <float.h> |
| 12 | 13 | ||
| 13 | int | 14 | int |
| 14 | main() | 15 | main(int argc, char *argv[]) |
| 15 | { | 16 | { |
| 16 | /* | 17 | /* |
| 17 | * This test would be better if it actually performed some | 18 | * This test would be better if it actually performed some |
