diff options
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libc/ieeefp/except/except.c | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c index 7df9abea07..4e8c17d427 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.5 2003/09/02 23:52:16 david Exp $ */ | 1 | /* $OpenBSD: except.c,v 1.6 2004/04/02 03:06:12 mickey Exp $ */ |
| 2 | 2 | ||
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| @@ -7,22 +7,31 @@ | |||
| 7 | #include <ieeefp.h> | 7 | #include <ieeefp.h> |
| 8 | #include <float.h> | 8 | #include <float.h> |
| 9 | 9 | ||
| 10 | volatile sig_atomic_t signal_cought; | 10 | volatile sig_atomic_t signal_caught; |
| 11 | 11 | ||
| 12 | static volatile const double one = 1.0; | 12 | volatile const double one = 1.0; |
| 13 | static volatile const double zero = 0.0; | 13 | volatile const double zero = 0.0; |
| 14 | static volatile const double huge = DBL_MAX; | 14 | volatile const double huge = DBL_MAX; |
| 15 | static volatile const double tiny = DBL_MIN; | 15 | volatile const double tiny = DBL_MIN; |
| 16 | 16 | ||
| 17 | static void | 17 | void |
| 18 | sigfpe(int signo) | 18 | sigfpe(int sig, siginfo_t *si, void *v) |
| 19 | { | 19 | { |
| 20 | signal_cought = 1; | 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; | ||
| 21 | } | 28 | } |
| 22 | 29 | ||
| 30 | |||
| 23 | int | 31 | int |
| 24 | main(int argc, char *argv[]) | 32 | main(int argc, char *argv[]) |
| 25 | { | 33 | { |
| 34 | struct sigaction sa; | ||
| 26 | volatile double x; | 35 | volatile double x; |
| 27 | 36 | ||
| 28 | /* | 37 | /* |
| @@ -32,59 +41,59 @@ main(int argc, char *argv[]) | |||
| 32 | assert(fpgetmask() == 0); | 41 | assert(fpgetmask() == 0); |
| 33 | assert(fpgetsticky() == 0); | 42 | assert(fpgetsticky() == 0); |
| 34 | 43 | ||
| 35 | /* set up signal handler */ | 44 | memset(&sa, 0, sizeof(sa)); |
| 36 | signal (SIGFPE, sigfpe); | 45 | sa.sa_sigaction = sigfpe; |
| 37 | signal_cought = 0; | 46 | sa.sa_flags = SA_SIGINFO; |
| 47 | sigaction(SIGFPE, &sa, NULL); | ||
| 48 | signal_caught = 0; | ||
| 38 | 49 | ||
| 39 | /* trip divide by zero */ | 50 | /* trip divide by zero */ |
| 40 | x = one / zero; | 51 | x = one / zero; |
| 41 | assert (fpgetsticky() & FP_X_DZ); | 52 | assert(fpgetsticky() & FP_X_DZ); |
| 42 | assert (signal_cought == 0); | 53 | assert(signal_caught == 0); |
| 43 | fpsetsticky(0); | 54 | fpsetsticky(0); |
| 44 | 55 | ||
| 45 | /* trip invalid operation */ | 56 | /* trip invalid operation */ |
| 46 | x = zero / zero; | 57 | x = zero / zero; |
| 47 | assert (fpgetsticky() & FP_X_INV); | 58 | assert(fpgetsticky() & FP_X_INV); |
| 48 | assert (signal_cought == 0); | 59 | assert(signal_caught == 0); |
| 49 | fpsetsticky(0); | 60 | fpsetsticky(0); |
| 50 | 61 | ||
| 51 | /* trip overflow */ | 62 | /* trip overflow */ |
| 52 | x = huge * huge; | 63 | x = huge * huge; |
| 53 | assert (fpgetsticky() & FP_X_OFL); | 64 | assert(fpgetsticky() & FP_X_OFL); |
| 54 | assert (signal_cought == 0); | 65 | assert(signal_caught == 0); |
| 55 | fpsetsticky(0); | 66 | fpsetsticky(0); |
| 56 | 67 | ||
| 57 | /* trip underflow */ | 68 | /* trip underflow */ |
| 58 | x = tiny * tiny; | 69 | x = tiny * tiny; |
| 59 | assert (fpgetsticky() & FP_X_UFL); | 70 | assert(fpgetsticky() & FP_X_UFL); |
| 60 | assert (signal_cought == 0); | 71 | assert(signal_caught == 0); |
| 61 | fpsetsticky(0); | 72 | fpsetsticky(0); |
| 62 | 73 | ||
| 63 | #if 0 | ||
| 64 | /* unmask and then trip divide by zero */ | 74 | /* unmask and then trip divide by zero */ |
| 65 | fpsetmask(FP_X_DZ); | 75 | fpsetmask(FP_X_DZ); |
| 66 | x = one / zero; | 76 | x = one / zero; |
| 67 | assert (signal_cought == 1); | 77 | assert(signal_caught == 1); |
| 68 | signal_cought = 0; | 78 | signal_caught = 0; |
| 69 | 79 | ||
| 70 | /* unmask and then trip invalid operation */ | 80 | /* unmask and then trip invalid operation */ |
| 71 | fpsetmask(FP_X_INV); | 81 | fpsetmask(FP_X_INV); |
| 72 | x = zero / zero; | 82 | x = zero / zero; |
| 73 | assert (signal_cought == 1); | 83 | assert(signal_caught == 1); |
| 74 | signal_cought = 0; | 84 | signal_caught = 0; |
| 75 | 85 | ||
| 76 | /* unmask and then trip overflow */ | 86 | /* unmask and then trip overflow */ |
| 77 | fpsetmask(FP_X_OFL); | 87 | fpsetmask(FP_X_OFL); |
| 78 | x = huge * huge; | 88 | x = huge * huge; |
| 79 | assert (signal_cought == 1); | 89 | assert(signal_caught == 1); |
| 80 | signal_cought = 0; | 90 | signal_caught = 0; |
| 81 | 91 | ||
| 82 | /* unmask and then trip underflow */ | 92 | /* unmask and then trip underflow */ |
| 83 | fpsetmask(FP_X_UFL); | 93 | fpsetmask(FP_X_UFL); |
| 84 | x = tiny * tiny; | 94 | x = tiny * tiny; |
| 85 | assert (signal_cought == 1); | 95 | assert (signal_caught == 1); |
| 86 | signal_cought = 0; | 96 | signal_caught = 0; |
| 87 | #endif | ||
| 88 | 97 | ||
| 89 | exit(0); | 98 | exit(0); |
| 90 | } | 99 | } |
