source: trunk/libs/newlib/src/newlib/libm/test/test_ieee.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.3 KB
Line 
1
2#include "test.h"
3#include <ieeefp.h>
4
5
6/* Test fp getround and fp setround */
7
8void
9test_getround (void)
10{
11
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);
25}
26
27/* And fpset/fpgetmask */
28void
29test_getmask (void)
30{
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);
47}
48
49void
50test_getsticky (void)
51{
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);
68}
69
70void
71test_getroundtoi (void)
72{
73  newfunc("fpsetroundtoi/fpgetroundtoi");
74  line(1);
75  fpsetroundtoi(FP_RDI_TOZ);
76  test_iok(fpgetroundtoi(),FP_RDI_TOZ);
77
78  line(2);
79  fpsetroundtoi(FP_RDI_RD);
80  test_iok(fpgetroundtoi(),FP_RDI_RD);
81
82}
83
84double
85 dnumber (int msw,
86        int lsw)
87{
88 
89  __ieee_double_shape_type v;
90  v.parts.lsw = lsw;
91  v.parts.msw = msw;
92  return v.value;
93}
94
95  /* Lets see if changing the rounding alters the arithmetic.
96     Test by creating numbers which will have to be rounded when
97     added, and seeing what happens to them */
98 /* Keep them out here to stop  the compiler from folding the results */
99double n;
100double m;
101double add_rounded_up;
102double add_rounded_down;
103double sub_rounded_down ;
104double sub_rounded_up ;
105  double r1,r2,r3,r4;
106void
107test_round (void)
108{
109  n =                dnumber(0x40000000, 0x00000008); /* near 2 */
110  m =                dnumber(0x40400000, 0x00000003); /* near 3.4 */
111 
112  add_rounded_up   = dnumber(0x40410000, 0x00000004); /* For RN, RP */
113  add_rounded_down = dnumber(0x40410000, 0x00000003); /* For RM, RZ */
114  sub_rounded_down = dnumber(0xc0410000, 0x00000004); /* for RN, RM */
115  sub_rounded_up   = dnumber(0xc0410000, 0x00000003); /* for RP, RZ */
116
117  newfunc("fpsetround");
118 
119  line(1);
120 
121  fpsetround(FP_RN);
122  r1 = n + m;
123  test_mok(r1, add_rounded_up, 64);
124 
125  line(2);
126  fpsetround(FP_RM);
127  r2 = n + m;
128  test_mok(r2, add_rounded_down, 64);
129 
130  fpsetround(FP_RP);
131  line(3);
132  r3 = n + m;
133  test_mok(r3,add_rounded_up, 64);
134 
135  fpsetround(FP_RZ);
136  line(4);
137  r4 = n + m;
138  test_mok(r4,add_rounded_down,64);
139
140
141  fpsetround(FP_RN);
142  r1 = - n - m;
143  line(5);
144  test_mok(r1,sub_rounded_down,64);
145 
146  fpsetround(FP_RM);
147  r2 = - n - m;
148  line(6);
149  test_mok(r2,sub_rounded_down,64);
150
151
152  fpsetround(FP_RP);
153  r3 = - n - m;
154  line(7);
155  test_mok(r3,sub_rounded_up,64);
156
157  fpsetround(FP_RZ);
158  r4 = - n - m;
159  line(8);
160  test_mok(r4,sub_rounded_up,64);
161}
162
163
164void
165test_ieee (void)
166{
167  fp_rnd old = fpgetround();
168  test_getround();
169  test_getmask();
170  test_getsticky();
171  test_getroundtoi();
172
173  test_round();
174  fpsetround(old);
175
176 
177}
178
179
Note: See TracBrowser for help on using the repository browser.