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 | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/ieeefp/except/except.c | 91 | ||||
-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/round/Makefile | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/ieeefp/round/round.c | 45 |
7 files changed, 179 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..f9a6035fa9 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2002/02/23 01:25:11 art Exp $ | ||
2 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ | ||
3 | |||
4 | SUBDIR+= except inf 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..ff620e016b --- /dev/null +++ b/src/regress/lib/libc/ieeefp/except/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:22:26 art Exp $ | ||
2 | |||
3 | PROG=except | ||
4 | |||
5 | .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..7df9abea07 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* $OpenBSD: except.c,v 1.5 2003/09/02 23:52:16 david Exp $ */ | ||
2 | |||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <signal.h> | ||
6 | #include <assert.h> | ||
7 | #include <ieeefp.h> | ||
8 | #include <float.h> | ||
9 | |||
10 | volatile sig_atomic_t signal_cought; | ||
11 | |||
12 | static volatile const double one = 1.0; | ||
13 | static volatile const double zero = 0.0; | ||
14 | static volatile const double huge = DBL_MAX; | ||
15 | static volatile const double tiny = DBL_MIN; | ||
16 | |||
17 | static void | ||
18 | sigfpe(int signo) | ||
19 | { | ||
20 | signal_cought = 1; | ||
21 | } | ||
22 | |||
23 | int | ||
24 | main(int argc, char *argv[]) | ||
25 | { | ||
26 | volatile double x; | ||
27 | |||
28 | /* | ||
29 | * check to make sure that all exceptions are masked and | ||
30 | * that the accumulated exception status is clear. | ||
31 | */ | ||
32 | assert(fpgetmask() == 0); | ||
33 | assert(fpgetsticky() == 0); | ||
34 | |||
35 | /* set up signal handler */ | ||
36 | signal (SIGFPE, sigfpe); | ||
37 | signal_cought = 0; | ||
38 | |||
39 | /* trip divide by zero */ | ||
40 | x = one / zero; | ||
41 | assert (fpgetsticky() & FP_X_DZ); | ||
42 | assert (signal_cought == 0); | ||
43 | fpsetsticky(0); | ||
44 | |||
45 | /* trip invalid operation */ | ||
46 | x = zero / zero; | ||
47 | assert (fpgetsticky() & FP_X_INV); | ||
48 | assert (signal_cought == 0); | ||
49 | fpsetsticky(0); | ||
50 | |||
51 | /* trip overflow */ | ||
52 | x = huge * huge; | ||
53 | assert (fpgetsticky() & FP_X_OFL); | ||
54 | assert (signal_cought == 0); | ||
55 | fpsetsticky(0); | ||
56 | |||
57 | /* trip underflow */ | ||
58 | x = tiny * tiny; | ||
59 | assert (fpgetsticky() & FP_X_UFL); | ||
60 | assert (signal_cought == 0); | ||
61 | fpsetsticky(0); | ||
62 | |||
63 | #if 0 | ||
64 | /* unmask and then trip divide by zero */ | ||
65 | fpsetmask(FP_X_DZ); | ||
66 | x = one / zero; | ||
67 | assert (signal_cought == 1); | ||
68 | signal_cought = 0; | ||
69 | |||
70 | /* unmask and then trip invalid operation */ | ||
71 | fpsetmask(FP_X_INV); | ||
72 | x = zero / zero; | ||
73 | assert (signal_cought == 1); | ||
74 | signal_cought = 0; | ||
75 | |||
76 | /* unmask and then trip overflow */ | ||
77 | fpsetmask(FP_X_OFL); | ||
78 | x = huge * huge; | ||
79 | assert (signal_cought == 1); | ||
80 | signal_cought = 0; | ||
81 | |||
82 | /* unmask and then trip underflow */ | ||
83 | fpsetmask(FP_X_UFL); | ||
84 | x = tiny * tiny; | ||
85 | assert (signal_cought == 1); | ||
86 | signal_cought = 0; | ||
87 | #endif | ||
88 | |||
89 | exit(0); | ||
90 | } | ||
91 | |||
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/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 | } | ||