This source file includes following definitions.
- sgl_to_sgl_fcnvuf
- sgl_to_dbl_fcnvuf
- dbl_to_sgl_fcnvuf
- dbl_to_dbl_fcnvuf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 #include "float.h"
33 #include "sgl_float.h"
34 #include "dbl_float.h"
35 #include "cnv_float.h"
36
37
38
39
40
41
42
43
44
45 int
46 sgl_to_sgl_fcnvuf(
47 unsigned int *srcptr,
48 unsigned int *nullptr,
49 sgl_floating_point *dstptr,
50 unsigned int *status)
51 {
52 register unsigned int src, result = 0;
53 register int dst_exponent;
54
55 src = *srcptr;
56
57
58 if (src == 0) {
59 Sgl_setzero(result);
60 *dstptr = result;
61 return(NOEXCEPTION);
62 }
63
64
65
66 dst_exponent = 16;
67
68
69
70
71
72 Find_ms_one_bit(src,dst_exponent);
73
74 src <<= dst_exponent+1;
75 Sgl_set_mantissa(result, src >> SGL_EXP_LENGTH);
76 Sgl_set_exponent(result, 30+SGL_BIAS - dst_exponent);
77
78
79 if (Suint_isinexact_to_sgl(src)) {
80 switch (Rounding_mode()) {
81 case ROUNDPLUS:
82 Sgl_increment(result);
83 break;
84 case ROUNDMINUS:
85 break;
86 case ROUNDNEAREST:
87 Sgl_roundnearest_from_suint(src,result);
88 break;
89 }
90 if (Is_inexacttrap_enabled()) {
91 *dstptr = result;
92 return(INEXACTEXCEPTION);
93 }
94 else Set_inexactflag();
95 }
96 *dstptr = result;
97 return(NOEXCEPTION);
98 }
99
100
101
102
103
104 int
105 sgl_to_dbl_fcnvuf(
106 unsigned int *srcptr,
107 unsigned int *nullptr,
108 dbl_floating_point *dstptr,
109 unsigned int *status)
110 {
111 register int dst_exponent;
112 register unsigned int src, resultp1 = 0, resultp2 = 0;
113
114 src = *srcptr;
115
116
117 if (src == 0) {
118 Dbl_setzero(resultp1,resultp2);
119 Dbl_copytoptr(resultp1,resultp2,dstptr);
120 return(NOEXCEPTION);
121 }
122
123
124
125 dst_exponent = 16;
126
127
128
129
130
131 Find_ms_one_bit(src,dst_exponent);
132
133 src <<= dst_exponent+1;
134 Dbl_set_mantissap1(resultp1, src >> DBL_EXP_LENGTH);
135 Dbl_set_mantissap2(resultp2, src << (32-DBL_EXP_LENGTH));
136 Dbl_set_exponent(resultp1, (30+DBL_BIAS) - dst_exponent);
137 Dbl_copytoptr(resultp1,resultp2,dstptr);
138 return(NOEXCEPTION);
139 }
140
141
142
143
144
145 int
146 dbl_to_sgl_fcnvuf(
147 dbl_unsigned *srcptr,
148 unsigned int *nullptr,
149 sgl_floating_point *dstptr,
150 unsigned int *status)
151 {
152 int dst_exponent;
153 unsigned int srcp1, srcp2, result = 0;
154
155 Duint_copyfromptr(srcptr,srcp1,srcp2);
156
157
158 if (srcp1 == 0 && srcp2 == 0) {
159 Sgl_setzero(result);
160 *dstptr = result;
161 return(NOEXCEPTION);
162 }
163
164
165
166 dst_exponent = 16;
167 if (srcp1 == 0) {
168
169
170
171
172
173 Find_ms_one_bit(srcp2,dst_exponent);
174
175 srcp1 = srcp2 << dst_exponent+1;
176 srcp2 = 0;
177
178
179
180
181 dst_exponent += 32;
182 }
183 else {
184
185
186
187
188
189
190 Find_ms_one_bit(srcp1,dst_exponent);
191
192 if (dst_exponent >= 0) {
193 Variable_shift_double(srcp1,srcp2,(31-dst_exponent),
194 srcp1);
195 srcp2 <<= dst_exponent+1;
196 }
197 }
198 Sgl_set_mantissa(result, srcp1 >> SGL_EXP_LENGTH);
199 Sgl_set_exponent(result, (62+SGL_BIAS) - dst_exponent);
200
201
202 if (Duint_isinexact_to_sgl(srcp1,srcp2)) {
203 switch (Rounding_mode()) {
204 case ROUNDPLUS:
205 Sgl_increment(result);
206 break;
207 case ROUNDMINUS:
208 break;
209 case ROUNDNEAREST:
210 Sgl_roundnearest_from_duint(srcp1,srcp2,result);
211 break;
212 }
213 if (Is_inexacttrap_enabled()) {
214 *dstptr = result;
215 return(INEXACTEXCEPTION);
216 }
217 else Set_inexactflag();
218 }
219 *dstptr = result;
220 return(NOEXCEPTION);
221 }
222
223
224
225
226
227 int
228 dbl_to_dbl_fcnvuf(
229 dbl_unsigned *srcptr,
230 unsigned int *nullptr,
231 dbl_floating_point *dstptr,
232 unsigned int *status)
233 {
234 register int dst_exponent;
235 register unsigned int srcp1, srcp2, resultp1 = 0, resultp2 = 0;
236
237 Duint_copyfromptr(srcptr,srcp1,srcp2);
238
239
240 if (srcp1 == 0 && srcp2 ==0) {
241 Dbl_setzero(resultp1,resultp2);
242 Dbl_copytoptr(resultp1,resultp2,dstptr);
243 return(NOEXCEPTION);
244 }
245
246
247
248 dst_exponent = 16;
249 if (srcp1 == 0) {
250
251
252
253
254
255 Find_ms_one_bit(srcp2,dst_exponent);
256
257 srcp1 = srcp2 << dst_exponent+1;
258 srcp2 = 0;
259
260
261
262
263 dst_exponent += 32;
264 }
265 else {
266
267
268
269
270
271 Find_ms_one_bit(srcp1,dst_exponent);
272
273 if (dst_exponent >= 0) {
274 Variable_shift_double(srcp1,srcp2,(31-dst_exponent),
275 srcp1);
276 srcp2 <<= dst_exponent+1;
277 }
278 }
279 Dbl_set_mantissap1(resultp1, srcp1 >> DBL_EXP_LENGTH);
280 Shiftdouble(srcp1,srcp2,DBL_EXP_LENGTH,resultp2);
281 Dbl_set_exponent(resultp1, (62+DBL_BIAS) - dst_exponent);
282
283
284 if (Duint_isinexact_to_dbl(srcp2)) {
285 switch (Rounding_mode()) {
286 case ROUNDPLUS:
287 Dbl_increment(resultp1,resultp2);
288 break;
289 case ROUNDMINUS:
290 break;
291 case ROUNDNEAREST:
292 Dbl_roundnearest_from_duint(srcp2,resultp1,
293 resultp2);
294 break;
295 }
296 if (Is_inexacttrap_enabled()) {
297 Dbl_copytoptr(resultp1,resultp2,dstptr);
298 return(INEXACTEXCEPTION);
299 }
300 else Set_inexactflag();
301 }
302 Dbl_copytoptr(resultp1,resultp2,dstptr);
303 return(NOEXCEPTION);
304 }
305