fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / test / test_ieee.c
bloba126d01e6fc8cd8c8d57d0327675b9f9ed059647
2 #include "test.h"
3 #include <ieeefp.h>
6 /* Test fp getround and fp setround */
8 void
9 _DEFUN_VOID(test_getround)
12 newfunc("fpgetround/fpsetround");
13 line(1);
14 fpsetround(FP_RN);
15 test_iok(fpgetround(), FP_RN);
16 line(2);
17 fpsetround(FP_RM);
18 test_iok(fpgetround(), FP_RM);
19 line(3);
20 fpsetround(FP_RP);
21 test_iok(fpgetround(), FP_RP);
22 line(4);
23 fpsetround(FP_RZ);
24 test_iok(fpgetround(), FP_RZ);
27 /* And fpset/fpgetmask */
28 void
29 _DEFUN_VOID(test_getmask)
31 newfunc("fpsetmask/fpgetmask");
32 line(1);
33 fpsetmask(FP_X_INV);
34 test_iok(fpgetmask(),FP_X_INV);
35 line(2);
36 fpsetmask(FP_X_DX);
37 test_iok(fpgetmask(),FP_X_DX);
38 line(3);
39 fpsetmask(FP_X_OFL );
40 test_iok(fpgetmask(),FP_X_OFL);
41 line(4);
42 fpsetmask(FP_X_UFL);
43 test_iok(fpgetmask(),FP_X_UFL);
44 line(5);
45 fpsetmask(FP_X_IMP);
46 test_iok(fpgetmask(),FP_X_IMP);
49 void
50 _DEFUN_VOID(test_getsticky)
52 newfunc("fpsetsticky/fpgetsticky");
53 line(1);
54 fpsetsticky(FP_X_INV);
55 test_iok(fpgetsticky(),FP_X_INV);
56 line(2);
57 fpsetsticky(FP_X_DX);
58 test_iok(fpgetsticky(),FP_X_DX);
59 line(3);
60 fpsetsticky(FP_X_OFL );
61 test_iok(fpgetsticky(),FP_X_OFL);
62 line(4);
63 fpsetsticky(FP_X_UFL);
64 test_iok(fpgetsticky(),FP_X_UFL);
65 line(5);
66 fpsetsticky(FP_X_IMP);
67 test_iok(fpgetsticky(),FP_X_IMP);
70 void
71 _DEFUN_VOID(test_getroundtoi)
73 newfunc("fpsetroundtoi/fpgetroundtoi");
74 line(1);
75 fpsetroundtoi(FP_RDI_TOZ);
76 test_iok(fpgetroundtoi(),FP_RDI_TOZ);
78 line(2);
79 fpsetroundtoi(FP_RDI_RD);
80 test_iok(fpgetroundtoi(),FP_RDI_RD);
84 double
85 _DEFUN(dnumber,(msw, lsw),
86 int msw _AND
87 int lsw)
90 __ieee_double_shape_type v;
91 v.parts.lsw = lsw;
92 v.parts.msw = msw;
93 return v.value;
96 /* Lets see if changing the rounding alters the arithmetic.
97 Test by creating numbers which will have to be rounded when
98 added, and seeing what happens to them */
99 /* Keep them out here to stop the compiler from folding the results */
100 double n;
101 double m;
102 double add_rounded_up;
103 double add_rounded_down;
104 double sub_rounded_down ;
105 double sub_rounded_up ;
106 double r1,r2,r3,r4;
107 void
108 _DEFUN_VOID(test_round)
110 n = dnumber(0x40000000, 0x00000008); /* near 2 */
111 m = dnumber(0x40400000, 0x00000003); /* near 3.4 */
113 add_rounded_up = dnumber(0x40410000, 0x00000004); /* For RN, RP */
114 add_rounded_down = dnumber(0x40410000, 0x00000003); /* For RM, RZ */
115 sub_rounded_down = dnumber(0xc0410000, 0x00000004); /* for RN, RM */
116 sub_rounded_up = dnumber(0xc0410000, 0x00000003); /* for RP, RZ */
118 newfunc("fpsetround");
120 line(1);
122 fpsetround(FP_RN);
123 r1 = n + m;
124 test_mok(r1, add_rounded_up, 64);
126 line(2);
127 fpsetround(FP_RM);
128 r2 = n + m;
129 test_mok(r2, add_rounded_down, 64);
131 fpsetround(FP_RP);
132 line(3);
133 r3 = n + m;
134 test_mok(r3,add_rounded_up, 64);
136 fpsetround(FP_RZ);
137 line(4);
138 r4 = n + m;
139 test_mok(r4,add_rounded_down,64);
142 fpsetround(FP_RN);
143 r1 = - n - m;
144 line(5);
145 test_mok(r1,sub_rounded_down,64);
147 fpsetround(FP_RM);
148 r2 = - n - m;
149 line(6);
150 test_mok(r2,sub_rounded_down,64);
153 fpsetround(FP_RP);
154 r3 = - n - m;
155 line(7);
156 test_mok(r3,sub_rounded_up,64);
158 fpsetround(FP_RZ);
159 r4 = - n - m;
160 line(8);
161 test_mok(r4,sub_rounded_up,64);
165 void
166 _DEFUN_VOID(test_ieee)
168 fp_rnd old = fpgetround();
169 test_getround();
170 test_getmask();
171 test_getsticky();
172 test_getroundtoi();
174 test_round();
175 fpsetround(old);