This source file includes following definitions.
- sgl_to_sgl_fcnvxf
- sgl_to_dbl_fcnvxf
- dbl_to_sgl_fcnvxf
- dbl_to_dbl_fcnvxf
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
33
34
35 #include "float.h"
36 #include "sgl_float.h"
37 #include "dbl_float.h"
38 #include "cnv_float.h"
39
40
41
42
43
44 int
45 sgl_to_sgl_fcnvxf(
46 int *srcptr,
47 unsigned int *nullptr,
48 sgl_floating_point *dstptr,
49 unsigned int *status)
50 {
51 register int src, dst_exponent;
52 register unsigned int result = 0;
53
54 src = *srcptr;
55
56
57
58 if (src < 0) {
59 Sgl_setone_sign(result);
60 Int_negate(src);
61 }
62 else {
63 Sgl_setzero_sign(result);
64
65 if (src == 0) {
66 Sgl_setzero(result);
67 *dstptr = result;
68 return(NOEXCEPTION);
69 }
70 }
71
72
73
74 dst_exponent = 16;
75
76
77
78
79
80 Find_ms_one_bit(src,dst_exponent);
81
82 if (dst_exponent >= 0) src <<= dst_exponent;
83 else src = 1 << 30;
84 Sgl_set_mantissa(result, src >> (SGL_EXP_LENGTH-1));
85 Sgl_set_exponent(result, 30+SGL_BIAS - dst_exponent);
86
87
88 if (Int_isinexact_to_sgl(src)) {
89 switch (Rounding_mode()) {
90 case ROUNDPLUS:
91 if (Sgl_iszero_sign(result))
92 Sgl_increment(result);
93 break;
94 case ROUNDMINUS:
95 if (Sgl_isone_sign(result))
96 Sgl_increment(result);
97 break;
98 case ROUNDNEAREST:
99 Sgl_roundnearest_from_int(src,result);
100 }
101 if (Is_inexacttrap_enabled()) {
102 *dstptr = result;
103 return(INEXACTEXCEPTION);
104 }
105 else Set_inexactflag();
106 }
107 *dstptr = result;
108 return(NOEXCEPTION);
109 }
110
111
112
113
114
115 int
116 sgl_to_dbl_fcnvxf(
117 int *srcptr,
118 unsigned int *nullptr,
119 dbl_floating_point *dstptr,
120 unsigned int *status)
121 {
122 register int src, dst_exponent;
123 register unsigned int resultp1 = 0, resultp2 = 0;
124
125 src = *srcptr;
126
127
128
129 if (src < 0) {
130 Dbl_setone_sign(resultp1);
131 Int_negate(src);
132 }
133 else {
134 Dbl_setzero_sign(resultp1);
135
136 if (src == 0) {
137 Dbl_setzero(resultp1,resultp2);
138 Dbl_copytoptr(resultp1,resultp2,dstptr);
139 return(NOEXCEPTION);
140 }
141 }
142
143
144
145 dst_exponent = 16;
146
147
148
149
150
151 Find_ms_one_bit(src,dst_exponent);
152
153 if (dst_exponent >= 0) src <<= dst_exponent;
154 else src = 1 << 30;
155 Dbl_set_mantissap1(resultp1, src >> DBL_EXP_LENGTH - 1);
156 Dbl_set_mantissap2(resultp2, src << (33-DBL_EXP_LENGTH));
157 Dbl_set_exponent(resultp1, (30+DBL_BIAS) - dst_exponent);
158 Dbl_copytoptr(resultp1,resultp2,dstptr);
159 return(NOEXCEPTION);
160 }
161
162
163
164
165
166 int
167 dbl_to_sgl_fcnvxf(
168 dbl_integer *srcptr,
169 unsigned int *nullptr,
170 sgl_floating_point *dstptr,
171 unsigned int *status)
172 {
173 int dst_exponent, srcp1;
174 unsigned int result = 0, srcp2;
175
176 Dint_copyfromptr(srcptr,srcp1,srcp2);
177
178
179
180 if (srcp1 < 0) {
181 Sgl_setone_sign(result);
182 Dint_negate(srcp1,srcp2);
183 }
184 else {
185 Sgl_setzero_sign(result);
186
187 if (srcp1 == 0 && srcp2 == 0) {
188 Sgl_setzero(result);
189 *dstptr = result;
190 return(NOEXCEPTION);
191 }
192 }
193
194
195
196 dst_exponent = 16;
197 if (srcp1 == 0) {
198
199
200
201
202
203 Find_ms_one_bit(srcp2,dst_exponent);
204
205 if (dst_exponent >= 0) {
206 srcp1 = srcp2 << dst_exponent;
207 srcp2 = 0;
208 }
209 else {
210 srcp1 = srcp2 >> 1;
211 srcp2 <<= 31;
212 }
213
214
215
216
217 dst_exponent += 32;
218 }
219 else {
220
221
222
223
224
225
226 Find_ms_one_bit(srcp1,dst_exponent);
227
228 if (dst_exponent > 0) {
229 Variable_shift_double(srcp1,srcp2,(32-dst_exponent),
230 srcp1);
231 srcp2 <<= dst_exponent;
232 }
233
234
235
236
237
238 else srcp1 >>= -(dst_exponent);
239 }
240 Sgl_set_mantissa(result, srcp1 >> SGL_EXP_LENGTH - 1);
241 Sgl_set_exponent(result, (62+SGL_BIAS) - dst_exponent);
242
243
244 if (Dint_isinexact_to_sgl(srcp1,srcp2)) {
245 switch (Rounding_mode()) {
246 case ROUNDPLUS:
247 if (Sgl_iszero_sign(result))
248 Sgl_increment(result);
249 break;
250 case ROUNDMINUS:
251 if (Sgl_isone_sign(result))
252 Sgl_increment(result);
253 break;
254 case ROUNDNEAREST:
255 Sgl_roundnearest_from_dint(srcp1,srcp2,result);
256 }
257 if (Is_inexacttrap_enabled()) {
258 *dstptr = result;
259 return(INEXACTEXCEPTION);
260 }
261 else Set_inexactflag();
262 }
263 *dstptr = result;
264 return(NOEXCEPTION);
265 }
266
267
268
269
270
271 int
272 dbl_to_dbl_fcnvxf(
273 dbl_integer *srcptr,
274 unsigned int *nullptr,
275 dbl_floating_point *dstptr,
276 unsigned int *status)
277 {
278 register int srcp1, dst_exponent;
279 register unsigned int srcp2, resultp1 = 0, resultp2 = 0;
280
281 Dint_copyfromptr(srcptr,srcp1,srcp2);
282
283
284
285 if (srcp1 < 0) {
286 Dbl_setone_sign(resultp1);
287 Dint_negate(srcp1,srcp2);
288 }
289 else {
290 Dbl_setzero_sign(resultp1);
291
292 if (srcp1 == 0 && srcp2 ==0) {
293 Dbl_setzero(resultp1,resultp2);
294 Dbl_copytoptr(resultp1,resultp2,dstptr);
295 return(NOEXCEPTION);
296 }
297 }
298
299
300
301 dst_exponent = 16;
302 if (srcp1 == 0) {
303
304
305
306
307
308 Find_ms_one_bit(srcp2,dst_exponent);
309
310 if (dst_exponent >= 0) {
311 srcp1 = srcp2 << dst_exponent;
312 srcp2 = 0;
313 }
314 else {
315 srcp1 = srcp2 >> 1;
316 srcp2 <<= 31;
317 }
318
319
320
321
322 dst_exponent += 32;
323 }
324 else {
325
326
327
328
329
330 Find_ms_one_bit(srcp1,dst_exponent);
331
332 if (dst_exponent > 0) {
333 Variable_shift_double(srcp1,srcp2,(32-dst_exponent),
334 srcp1);
335 srcp2 <<= dst_exponent;
336 }
337
338
339
340
341
342 else srcp1 >>= -(dst_exponent);
343 }
344 Dbl_set_mantissap1(resultp1, srcp1 >> (DBL_EXP_LENGTH-1));
345 Shiftdouble(srcp1,srcp2,DBL_EXP_LENGTH-1,resultp2);
346 Dbl_set_exponent(resultp1, (62+DBL_BIAS) - dst_exponent);
347
348
349 if (Dint_isinexact_to_dbl(srcp2)) {
350 switch (Rounding_mode()) {
351 case ROUNDPLUS:
352 if (Dbl_iszero_sign(resultp1)) {
353 Dbl_increment(resultp1,resultp2);
354 }
355 break;
356 case ROUNDMINUS:
357 if (Dbl_isone_sign(resultp1)) {
358 Dbl_increment(resultp1,resultp2);
359 }
360 break;
361 case ROUNDNEAREST:
362 Dbl_roundnearest_from_dint(srcp2,resultp1,
363 resultp2);
364 }
365 if (Is_inexacttrap_enabled()) {
366 Dbl_copytoptr(resultp1,resultp2,dstptr);
367 return(INEXACTEXCEPTION);
368 }
369 else Set_inexactflag();
370 }
371 Dbl_copytoptr(resultp1,resultp2,dstptr);
372 return(NOEXCEPTION);
373 }