OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [test/] [test_ieee.c] - Blame information for rev 822

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
 
2
#include "test.h"
3
#include <ieeefp.h>
4
 
5
 
6
/* Test fp getround and fp setround */
7
 
8
void
9
_DEFUN_VOID(test_getround)
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 */
28
void
29
_DEFUN_VOID(test_getmask)
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
 
49
void
50
_DEFUN_VOID(test_getsticky)
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
 
70
void
71
_DEFUN_VOID(test_getroundtoi)
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
 
84
double
85
 _DEFUN(dnumber,(msw, lsw),
86
        int msw _AND
87
        int lsw)
88
{
89
 
90
  __ieee_double_shape_type v;
91
  v.parts.lsw = lsw;
92
  v.parts.msw = msw;
93
  return v.value;
94
}
95
 
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)
109
{
110
  n =                dnumber(0x40000000, 0x00000008); /* near 2 */
111
  m =                dnumber(0x40400000, 0x00000003); /* near 3.4 */
112
 
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 */
117
 
118
  newfunc("fpsetround");
119
 
120
  line(1);
121
 
122
  fpsetround(FP_RN);
123
  r1 = n + m;
124
  test_mok(r1, add_rounded_up, 64);
125
 
126
  line(2);
127
  fpsetround(FP_RM);
128
  r2 = n + m;
129
  test_mok(r2, add_rounded_down, 64);
130
 
131
  fpsetround(FP_RP);
132
  line(3);
133
  r3 = n + m;
134
  test_mok(r3,add_rounded_up, 64);
135
 
136
  fpsetround(FP_RZ);
137
  line(4);
138
  r4 = n + m;
139
  test_mok(r4,add_rounded_down,64);
140
 
141
 
142
  fpsetround(FP_RN);
143
  r1 = - n - m;
144
  line(5);
145
  test_mok(r1,sub_rounded_down,64);
146
 
147
  fpsetround(FP_RM);
148
  r2 = - n - m;
149
  line(6);
150
  test_mok(r2,sub_rounded_down,64);
151
 
152
 
153
  fpsetround(FP_RP);
154
  r3 = - n - m;
155
  line(7);
156
  test_mok(r3,sub_rounded_up,64);
157
 
158
  fpsetround(FP_RZ);
159
  r4 = - n - m;
160
  line(8);
161
  test_mok(r4,sub_rounded_up,64);
162
}
163
 
164
 
165
void
166
_DEFUN_VOID(test_ieee)
167
{
168
  fp_rnd old = fpgetround();
169
  test_getround();
170
  test_getmask();
171
  test_getsticky();
172
  test_getroundtoi();
173
 
174
  test_round();
175
  fpsetround(old);
176
 
177
 
178
}
179
 
180
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.