diff options
| author | 1995-10-18 08:37:01 +0000 | |
|---|---|---|
| committer | 1995-10-18 08:37:01 +0000 | |
| commit | df930be708d50e9715f173caa26ffe1b7599b157 (patch) | |
| tree | aa317e49e28cb999c9cf3db7f00c20903fe6010a /regress/lib/libc/ieeefp/except/except.c | |
| download | wireguard-openbsd-df930be708d50e9715f173caa26ffe1b7599b157.tar.xz wireguard-openbsd-df930be708d50e9715f173caa26ffe1b7599b157.zip | |
initial import of NetBSD tree
Diffstat (limited to 'regress/lib/libc/ieeefp/except/except.c')
| -rw-r--r-- | regress/lib/libc/ieeefp/except/except.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/regress/lib/libc/ieeefp/except/except.c b/regress/lib/libc/ieeefp/except/except.c new file mode 100644 index 00000000000..0ffdcdd468f --- /dev/null +++ b/regress/lib/libc/ieeefp/except/except.c @@ -0,0 +1,87 @@ +#include <stdio.h> +#include <signal.h> +#include <assert.h> +#include <ieeefp.h> +#include <float.h> + +void sigfpe(); +volatile sig_atomic_t signal_cought; + +static volatile const double one = 1.0; +static volatile const double zero = 0.0; +static volatile const double huge = DBL_MAX; +static volatile const double tiny = DBL_MIN; + +main() +{ + volatile double x; + + /* + * check to make sure that all exceptions are masked and + * that the accumulated exception status is clear. + */ + assert(fpgetmask() == 0); + assert(fpgetsticky() == 0); + + /* set up signal handler */ + signal (SIGFPE, sigfpe); + signal_cought = 0; + + /* trip divide by zero */ + x = one / zero; + assert (fpgetsticky() & FP_X_DZ); + assert (signal_cought == 0); + fpsetsticky(0); + + /* trip invalid operation */ + x = zero / zero; + assert (fpgetsticky() & FP_X_INV); + assert (signal_cought == 0); + fpsetsticky(0); + + /* trip overflow */ + x = huge * huge; + assert (fpgetsticky() & FP_X_OFL); + assert (signal_cought == 0); + fpsetsticky(0); + + /* trip underflow */ + x = tiny * tiny; + assert (fpgetsticky() & FP_X_UFL); + assert (signal_cought == 0); + fpsetsticky(0); + +#if 0 + /* unmask and then trip divide by zero */ + fpsetmask(FP_X_DZ); + x = one / zero; + assert (signal_cought == 1); + signal_cought = 0; + + /* unmask and then trip invalid operation */ + fpsetmask(FP_X_INV); + x = zero / zero; + assert (signal_cought == 1); + signal_cought = 0; + + /* unmask and then trip overflow */ + fpsetmask(FP_X_OFL); + x = huge * huge; + assert (signal_cought == 1); + signal_cought = 0; + + /* unmask and then trip underflow */ + fpsetmask(FP_X_UFL); + x = tiny * tiny; + assert (signal_cought == 1); + signal_cought = 0; +#endif + + exit(0); +} + +void +sigfpe() +{ + signal_cought = 1; +} |
