diff options
Diffstat (limited to 'src/regress/lib/libc/ieeefp')
| -rw-r--r-- | src/regress/lib/libc/ieeefp/Makefile | 8 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/Makefile | 19 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/except.c | 109 | ||||
| -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 | 5 | ||||
| -rw-r--r-- | src/regress/lib/libc/ieeefp/round/round.c | 45 |
9 files changed, 310 insertions, 0 deletions
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile new file mode 100644 index 0000000000..89ff51a2e7 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 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 $ | ||
| 3 | |||
| 4 | SUBDIR+= except inf infinity round | ||
| 5 | |||
| 6 | install: | ||
| 7 | |||
| 8 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile new file mode 100644 index 0000000000..205331548f --- /dev/null +++ b/src/regress/lib/libc/ieeefp/except/Makefile | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ | ||
| 2 | |||
| 3 | PROG=except | ||
| 4 | |||
| 5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund | ||
| 6 | |||
| 7 | fltdiv: ${PROG} | ||
| 8 | ./${PROG} fltdiv | ||
| 9 | |||
| 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 new file mode 100644 index 0000000000..0f25cadefc --- /dev/null +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.11 2007/10/22 21:07:10 miod Exp $ */ | ||
| 2 | |||
| 3 | #include <sys/types.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <signal.h> | ||
| 8 | #include <assert.h> | ||
| 9 | #include <ieeefp.h> | ||
| 10 | #include <float.h> | ||
| 11 | #include <err.h> | ||
| 12 | |||
| 13 | volatile sig_atomic_t signal_status; | ||
| 14 | |||
| 15 | volatile const double one = 1.0; | ||
| 16 | volatile const double zero = 0.0; | ||
| 17 | volatile const double huge = DBL_MAX; | ||
| 18 | volatile const double tiny = DBL_MIN; | ||
| 19 | |||
| 20 | void | ||
| 21 | sigfpe(int sig, siginfo_t *si, void *v) | ||
| 22 | { | ||
| 23 | char buf[132]; | ||
| 24 | |||
| 25 | if (si) { | ||
| 26 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
| 27 | si->si_addr, si->si_code); | ||
| 28 | write(1, buf, strlen(buf)); | ||
| 29 | } | ||
| 30 | _exit(signal_status); | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | int | ||
| 35 | main(int argc, char *argv[]) | ||
| 36 | { | ||
| 37 | struct sigaction sa; | ||
| 38 | volatile double x; | ||
| 39 | |||
| 40 | if (argc != 2) { | ||
| 41 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
| 42 | exit(1); | ||
| 43 | } | ||
| 44 | |||
| 45 | /* | ||
| 46 | * check to make sure that all exceptions are masked and | ||
| 47 | * that the accumulated exception status is clear. | ||
| 48 | */ | ||
| 49 | assert(fpgetmask() == 0); | ||
| 50 | assert(fpgetsticky() == 0); | ||
| 51 | |||
| 52 | memset(&sa, 0, sizeof(sa)); | ||
| 53 | sa.sa_sigaction = sigfpe; | ||
| 54 | sa.sa_flags = SA_SIGINFO; | ||
| 55 | sigaction(SIGFPE, &sa, NULL); | ||
| 56 | signal_status = 1; | ||
| 57 | |||
| 58 | if (strcmp(argv[1], "fltdiv") == 0) { | ||
| 59 | /* trip divide by zero */ | ||
| 60 | x = one / zero; | ||
| 61 | assert(fpgetsticky() & FP_X_DZ); | ||
| 62 | fpsetsticky(0); | ||
| 63 | |||
| 64 | /* and now unmask to get a signal */ | ||
| 65 | signal_status = 0; | ||
| 66 | fpsetmask(FP_X_DZ); | ||
| 67 | x = one / zero; | ||
| 68 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
| 69 | /* trip invalid operation */ | ||
| 70 | x = zero / zero; | ||
| 71 | assert(fpgetsticky() & FP_X_INV); | ||
| 72 | fpsetsticky(0); | ||
| 73 | |||
| 74 | /* and now unmask to get a signal */ | ||
| 75 | signal_status = 0; | ||
| 76 | fpsetmask(FP_X_INV); | ||
| 77 | x = zero / zero; | ||
| 78 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
| 79 | /* trip overflow */ | ||
| 80 | x = huge * huge; | ||
| 81 | assert(fpgetsticky() & FP_X_OFL); | ||
| 82 | fpsetsticky(0); | ||
| 83 | |||
| 84 | /* and now unmask to get a signal */ | ||
| 85 | signal_status = 0; | ||
| 86 | fpsetmask(FP_X_OFL); | ||
| 87 | x = huge * huge; | ||
| 88 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
| 89 | /* trip underflow */ | ||
| 90 | x = tiny * tiny; | ||
| 91 | assert(fpgetsticky() & FP_X_UFL); | ||
| 92 | fpsetsticky(0); | ||
| 93 | |||
| 94 | /* and now unmask to get a signal */ | ||
| 95 | signal_status = 0; | ||
| 96 | fpsetmask(FP_X_UFL); | ||
| 97 | x = tiny * tiny; | ||
| 98 | } else { | ||
| 99 | errx(1, "unrecognized condition %s", argv[1]); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | ||
| 103 | * attempt to trigger the exception on machines where | ||
| 104 | * floating-point exceptions are deferred. | ||
| 105 | */ | ||
| 106 | x = one * one; | ||
| 107 | |||
| 108 | errx(1, "signal wasn't caught"); | ||
| 109 | } | ||
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 new file mode 100644 index 0000000000..9ea6dd8c39 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/round/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:25:34 art Exp $ | ||
| 2 | |||
| 3 | PROG= round | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/round/round.c b/src/regress/lib/libc/ieeefp/round/round.c new file mode 100644 index 0000000000..807941ea56 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/round/round.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* $OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Written by J.T. Conklin, Apr 18, 1995 | ||
| 6 | * Public domain. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <ieeefp.h> | ||
| 12 | #include <float.h> | ||
| 13 | |||
| 14 | int | ||
| 15 | main(int argc, char *argv[]) | ||
| 16 | { | ||
| 17 | /* | ||
| 18 | * This test would be better if it actually performed some | ||
| 19 | * calculations to verify the selected rounding mode. But | ||
| 20 | * this is probably acceptable since the fp{get,set}round | ||
| 21 | * functions usually just get or set the processors fpu | ||
| 22 | * control word. | ||
| 23 | */ | ||
| 24 | |||
| 25 | assert(fpgetround() == FP_RN); | ||
| 26 | assert(FLT_ROUNDS == 1); | ||
| 27 | |||
| 28 | assert(fpsetround(FP_RP) == FP_RN); | ||
| 29 | assert(fpgetround() == FP_RP); | ||
| 30 | assert(FLT_ROUNDS == 2); | ||
| 31 | |||
| 32 | assert(fpsetround(FP_RM) == FP_RP); | ||
| 33 | assert(fpgetround() == FP_RM); | ||
| 34 | assert(FLT_ROUNDS == 3); | ||
| 35 | |||
| 36 | assert(fpsetround(FP_RZ) == FP_RM); | ||
| 37 | assert(fpgetround() == FP_RZ); | ||
| 38 | assert(FLT_ROUNDS == 0); | ||
| 39 | |||
| 40 | assert(fpsetround(FP_RN) == FP_RZ); | ||
| 41 | assert(fpgetround() == FP_RN); | ||
| 42 | assert(FLT_ROUNDS == 1); | ||
| 43 | |||
| 44 | exit(0); | ||
| 45 | } | ||
