summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/ieeefp
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/ieeefp')
-rw-r--r--src/regress/lib/libc/ieeefp/Makefile11
-rw-r--r--src/regress/lib/libc/ieeefp/except/Makefile23
-rw-r--r--src/regress/lib/libc/ieeefp/except/except.c116
-rw-r--r--src/regress/lib/libc/ieeefp/inf/Makefile9
-rw-r--r--src/regress/lib/libc/ieeefp/inf/inf.c16
-rw-r--r--src/regress/lib/libc/ieeefp/infinity/Makefile22
-rw-r--r--src/regress/lib/libc/ieeefp/infinity/infinity.c77
-rw-r--r--src/regress/lib/libc/ieeefp/round/Makefile11
-rw-r--r--src/regress/lib/libc/ieeefp/round/round.c3
9 files changed, 214 insertions, 74 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" 4SUBDIR+= except inf infinity round
4SUBDIR+= round
5.else
6SUBDIR+= except round
7.endif
8
9regress: _SUBDIRUSE
10 5
11install: 6install:
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
3PROG= except 3PROG=except
4SRCS= except.c
5NOMAN=
6 4
7install: 5REGRESS_TARGETS+= fltdiv fltinv fltovf fltund
8 6
9regress: ${PROG} 7fltdiv: ${PROG}
10 ./${PROG} 8 ./${PROG} fltdiv
11 9
12.include <bsd.prog.mk> 10fltinv: ${PROG}
11 ./${PROG} fltinv
12
13fltovf: ${PROG}
14 ./${PROG} fltovf
15
16fltund: ${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..1d11877777 100644
--- a/src/regress/lib/libc/ieeefp/except/except.c
+++ b/src/regress/lib/libc/ieeefp/except/except.c
@@ -1,21 +1,47 @@
1/* $OpenBSD: except.c,v 1.10 2006/05/15 14:00:22 kettenis Exp $ */
2
3#include <sys/types.h>
4#include <unistd.h>
1#include <stdio.h> 5#include <stdio.h>
6#include <stdlib.h>
2#include <signal.h> 7#include <signal.h>
3#include <assert.h> 8#include <assert.h>
4#include <ieeefp.h> 9#include <ieeefp.h>
5#include <float.h> 10#include <float.h>
11#include <err.h>
6 12
7void sigfpe(); 13volatile sig_atomic_t signal_status;
8volatile sig_atomic_t signal_cought;
9 14
10static volatile const double one = 1.0; 15volatile const double one = 1.0;
11static volatile const double zero = 0.0; 16volatile const double zero = 0.0;
12static volatile const double huge = DBL_MAX; 17volatile const double huge = DBL_MAX;
13static volatile const double tiny = DBL_MIN; 18volatile const double tiny = DBL_MIN;
14 19
15main() 20void
21sigfpe(int sig, siginfo_t *si, void *v)
16{ 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
34int
35main(int argc, char *argv[])
36{
37 struct sigaction sa;
17 volatile double x; 38 volatile double x;
18 39
40 if (argc != 2) {
41 fprintf(stderr, "usage: %s condition\n", argv[0]);
42 exit(1);
43 }
44
19 /* 45 /*
20 * check to make sure that all exceptions are masked and 46 * check to make sure that all exceptions are masked and
21 * that the accumulated exception status is clear. 47 * that the accumulated exception status is clear.
@@ -23,65 +49,59 @@ main()
23 assert(fpgetmask() == 0); 49 assert(fpgetmask() == 0);
24 assert(fpgetsticky() == 0); 50 assert(fpgetsticky() == 0);
25 51
26 /* set up signal handler */ 52 memset(&sa, 0, sizeof(sa));
27 signal (SIGFPE, sigfpe); 53 sa.sa_sigaction = sigfpe;
28 signal_cought = 0; 54 sa.sa_flags = SA_SIGINFO;
55 sigaction(SIGFPE, &sa, NULL);
56 signal_status = 1;
29 57
30 /* trip divide by zero */ 58 /* trip divide by zero */
31 x = one / zero; 59 x = one / zero;
32 assert (fpgetsticky() & FP_X_DZ); 60 assert(fpgetsticky() & FP_X_DZ);
33 assert (signal_cought == 0);
34 fpsetsticky(0); 61 fpsetsticky(0);
35 62
36 /* trip invalid operation */ 63 /* trip invalid operation */
37 x = zero / zero; 64 x = zero / zero;
38 assert (fpgetsticky() & FP_X_INV); 65 assert(fpgetsticky() & FP_X_INV);
39 assert (signal_cought == 0);
40 fpsetsticky(0); 66 fpsetsticky(0);
41 67
42 /* trip overflow */ 68 /* trip overflow */
43 x = huge * huge; 69 x = huge * huge;
44 assert (fpgetsticky() & FP_X_OFL); 70 assert(fpgetsticky() & FP_X_OFL);
45 assert (signal_cought == 0);
46 fpsetsticky(0); 71 fpsetsticky(0);
47 72
48 /* trip underflow */ 73 /* trip underflow */
49 x = tiny * tiny; 74 x = tiny * tiny;
50 assert (fpgetsticky() & FP_X_UFL); 75 assert(fpgetsticky() & FP_X_UFL);
51 assert (signal_cought == 0);
52 fpsetsticky(0); 76 fpsetsticky(0);
53 77
54#if 0 78 signal_status = 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 79
67 /* unmask and then trip overflow */ 80 if (strcmp(argv[1], "fltdiv") == 0) {
68 fpsetmask(FP_X_OFL); 81 /* unmask and then trip divide by zero */
69 x = huge * huge; 82 fpsetmask(FP_X_DZ);
70 assert (signal_cought == 1); 83 x = one / zero;
71 signal_cought = 0; 84 } else if (strcmp(argv[1], "fltinv") == 0) {
72 85 /* unmask and then trip invalid operation */
73 /* unmask and then trip underflow */ 86 fpsetmask(FP_X_INV);
74 fpsetmask(FP_X_UFL); 87 x = zero / zero;
75 x = tiny * tiny; 88 } else if (strcmp(argv[1], "fltovf") == 0) {
76 assert (signal_cought == 1); 89 /* unmask and then trip overflow */
77 signal_cought = 0; 90 fpsetmask(FP_X_OFL);
78#endif 91 x = huge * huge;
92 } else if (strcmp(argv[1], "fltund") == 0) {
93 /* unmask and then trip underflow */
94 fpsetmask(FP_X_UFL);
95 x = tiny * tiny;
96 } else {
97 errx(1, "unrecognized condition %s", argv[1]);
98 }
79 99
80 exit(0); 100 /*
81} 101 * attempt to trigger the exception on machines where
102 * floating-point exceptions are deferred.
103 */
104 x = one * one;
82 105
83void 106 errx(1, "signal wasn't caught");
84sigfpe()
85{
86 signal_cought = 1;
87} 107}
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
3PROG= inf
4SRCS= inf.c
5
6LDADD+= -lm
7DPADD+= ${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
9int
10main(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
3PROG= infinity
4
5DPADD+= ${LIBM}
6LDADD+= -lm
7
8REGRESS_TARGETS+= add mult neg pumpkin
9
10add: ${PROG}
11 ./${PROG} -a
12
13mult: ${PROG}
14 ./${PROG} -m
15
16neg: ${PROG}
17 ./${PROG} -n
18
19pumpkin: ${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
11void
12sigfpe(int signum)
13{
14 /* looks like we don't handle fp overflow correctly... */
15 _exit(1);
16}
17
18int
19main(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
3PROG= round 3PROG= round
4SRCS= round.c
5NOMAN=
6 4
7install: 5.include <bsd.regress.mk>
8
9regress: ${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
13int 14int
14main() 15main(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