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 | 23 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/except.c | 157 | ||||
| -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, 236 insertions, 93 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..205331548f 100644 --- a/src/regress/lib/libc/ieeefp/except/Makefile +++ b/src/regress/lib/libc/ieeefp/except/Makefile | |||
| @@ -1,12 +1,19 @@ | |||
| 1 | # $NetBSD: Makefile,v 1.1 1995/04/26 00:27:25 jtc Exp $ | 1 | # $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ |
| 2 | 2 | ||
| 3 | PROG= except | 3 | PROG=except |
| 4 | SRCS= except.c | ||
| 5 | NOMAN= | ||
| 6 | 4 | ||
| 7 | install: | 5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund |
| 8 | 6 | ||
| 9 | regress: ${PROG} | 7 | fltdiv: ${PROG} |
| 10 | ./${PROG} | 8 | ./${PROG} fltdiv |
| 11 | 9 | ||
| 12 | .include <bsd.prog.mk> | 10 | fltinv: ${PROG} |
| 11 | ./${PROG} fltinv | ||
| 12 | |||
| 13 | fltovf: ${PROG} | ||
| 14 | ./${PROG} fltovf | ||
| 15 | |||
| 16 | fltund: ${PROG} | ||
| 17 | ./${PROG} fltund | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c index 0ffdcdd468..cc3dcf8e44 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
| @@ -1,21 +1,48 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.12 2010/05/08 19:16:33 naddy Exp $ */ | ||
| 2 | |||
| 3 | #include <sys/types.h> | ||
| 4 | #include <unistd.h> | ||
| 1 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 2 | #include <signal.h> | 8 | #include <signal.h> |
| 3 | #include <assert.h> | 9 | #include <assert.h> |
| 4 | #include <ieeefp.h> | 10 | #include <ieeefp.h> |
| 5 | #include <float.h> | 11 | #include <float.h> |
| 12 | #include <err.h> | ||
| 6 | 13 | ||
| 7 | void sigfpe(); | 14 | volatile sig_atomic_t signal_status; |
| 8 | volatile sig_atomic_t signal_cought; | ||
| 9 | 15 | ||
| 10 | static volatile const double one = 1.0; | 16 | volatile const double one = 1.0; |
| 11 | static volatile const double zero = 0.0; | 17 | volatile const double zero = 0.0; |
| 12 | static volatile const double huge = DBL_MAX; | 18 | volatile const double huge = DBL_MAX; |
| 13 | static volatile const double tiny = DBL_MIN; | 19 | volatile const double tiny = DBL_MIN; |
| 14 | 20 | ||
| 15 | main() | 21 | void |
| 22 | sigfpe(int sig, siginfo_t *si, void *v) | ||
| 16 | { | 23 | { |
| 24 | char buf[132]; | ||
| 25 | |||
| 26 | if (si) { | ||
| 27 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
| 28 | si->si_addr, si->si_code); | ||
| 29 | write(1, buf, strlen(buf)); | ||
| 30 | } | ||
| 31 | _exit(signal_status); | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | int | ||
| 36 | main(int argc, char *argv[]) | ||
| 37 | { | ||
| 38 | struct sigaction sa; | ||
| 17 | volatile double x; | 39 | volatile double x; |
| 18 | 40 | ||
| 41 | if (argc != 2) { | ||
| 42 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
| 43 | exit(1); | ||
| 44 | } | ||
| 45 | |||
| 19 | /* | 46 | /* |
| 20 | * check to make sure that all exceptions are masked and | 47 | * check to make sure that all exceptions are masked and |
| 21 | * that the accumulated exception status is clear. | 48 | * that the accumulated exception status is clear. |
| @@ -23,65 +50,61 @@ main() | |||
| 23 | assert(fpgetmask() == 0); | 50 | assert(fpgetmask() == 0); |
| 24 | assert(fpgetsticky() == 0); | 51 | assert(fpgetsticky() == 0); |
| 25 | 52 | ||
| 26 | /* set up signal handler */ | 53 | memset(&sa, 0, sizeof(sa)); |
| 27 | signal (SIGFPE, sigfpe); | 54 | sa.sa_sigaction = sigfpe; |
| 28 | signal_cought = 0; | 55 | sa.sa_flags = SA_SIGINFO; |
| 29 | 56 | sigaction(SIGFPE, &sa, NULL); | |
| 30 | /* trip divide by zero */ | 57 | signal_status = 1; |
| 31 | x = one / zero; | ||
| 32 | assert (fpgetsticky() & FP_X_DZ); | ||
| 33 | assert (signal_cought == 0); | ||
| 34 | fpsetsticky(0); | ||
| 35 | |||
| 36 | /* trip invalid operation */ | ||
| 37 | x = zero / zero; | ||
| 38 | assert (fpgetsticky() & FP_X_INV); | ||
| 39 | assert (signal_cought == 0); | ||
| 40 | fpsetsticky(0); | ||
| 41 | |||
| 42 | /* trip overflow */ | ||
| 43 | x = huge * huge; | ||
| 44 | assert (fpgetsticky() & FP_X_OFL); | ||
| 45 | assert (signal_cought == 0); | ||
| 46 | fpsetsticky(0); | ||
| 47 | |||
| 48 | /* trip underflow */ | ||
| 49 | x = tiny * tiny; | ||
| 50 | assert (fpgetsticky() & FP_X_UFL); | ||
| 51 | assert (signal_cought == 0); | ||
| 52 | fpsetsticky(0); | ||
| 53 | |||
| 54 | #if 0 | ||
| 55 | /* unmask and then trip divide by zero */ | ||
| 56 | fpsetmask(FP_X_DZ); | ||
| 57 | x = one / zero; | ||
| 58 | assert (signal_cought == 1); | ||
| 59 | signal_cought = 0; | ||
| 60 | |||
| 61 | /* unmask and then trip invalid operation */ | ||
| 62 | fpsetmask(FP_X_INV); | ||
| 63 | x = zero / zero; | ||
| 64 | assert (signal_cought == 1); | ||
| 65 | signal_cought = 0; | ||
| 66 | |||
| 67 | /* unmask and then trip overflow */ | ||
| 68 | fpsetmask(FP_X_OFL); | ||
| 69 | x = huge * huge; | ||
| 70 | assert (signal_cought == 1); | ||
| 71 | signal_cought = 0; | ||
| 72 | |||
| 73 | /* unmask and then trip underflow */ | ||
| 74 | fpsetmask(FP_X_UFL); | ||
| 75 | x = tiny * tiny; | ||
| 76 | assert (signal_cought == 1); | ||
| 77 | signal_cought = 0; | ||
| 78 | #endif | ||
| 79 | |||
| 80 | exit(0); | ||
| 81 | } | ||
| 82 | 58 | ||
| 83 | void | 59 | if (strcmp(argv[1], "fltdiv") == 0) { |
| 84 | sigfpe() | 60 | /* trip divide by zero */ |
| 85 | { | 61 | x = one / zero; |
| 86 | signal_cought = 1; | 62 | assert(fpgetsticky() & FP_X_DZ); |
| 63 | fpsetsticky(0); | ||
| 64 | |||
| 65 | /* and now unmask to get a signal */ | ||
| 66 | signal_status = 0; | ||
| 67 | fpsetmask(FP_X_DZ); | ||
| 68 | x = one / zero; | ||
| 69 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
| 70 | /* trip invalid operation */ | ||
| 71 | x = zero / zero; | ||
| 72 | assert(fpgetsticky() & FP_X_INV); | ||
| 73 | fpsetsticky(0); | ||
| 74 | |||
| 75 | /* and now unmask to get a signal */ | ||
| 76 | signal_status = 0; | ||
| 77 | fpsetmask(FP_X_INV); | ||
| 78 | x = zero / zero; | ||
| 79 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
| 80 | /* trip overflow */ | ||
| 81 | x = huge * huge; | ||
| 82 | assert(fpgetsticky() & FP_X_OFL); | ||
| 83 | fpsetsticky(0); | ||
| 84 | |||
| 85 | /* and now unmask to get a signal */ | ||
| 86 | signal_status = 0; | ||
| 87 | fpsetmask(FP_X_OFL); | ||
| 88 | x = huge * huge; | ||
| 89 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
| 90 | /* trip underflow */ | ||
| 91 | x = tiny * tiny; | ||
| 92 | assert(fpgetsticky() & FP_X_UFL); | ||
| 93 | fpsetsticky(0); | ||
| 94 | |||
| 95 | /* and now unmask to get a signal */ | ||
| 96 | signal_status = 0; | ||
| 97 | fpsetmask(FP_X_UFL); | ||
| 98 | x = tiny * tiny; | ||
| 99 | } else { | ||
| 100 | errx(1, "unrecognized condition %s", argv[1]); | ||
| 101 | } | ||
| 102 | |||
| 103 | /* | ||
| 104 | * attempt to trigger the exception on machines where | ||
| 105 | * floating-point exceptions are deferred. | ||
| 106 | */ | ||
| 107 | x = one * one; | ||
| 108 | |||
| 109 | errx(1, "signal wasn't caught"); | ||
| 87 | } | 110 | } |
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 |
