This source file includes following definitions.
- sgl_to_dbl_fcnvff
- dbl_to_sgl_fcnvff
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 #include "float.h"
32 #include "sgl_float.h"
33 #include "dbl_float.h"
34 #include "cnv_float.h"
35
36
37
38
39
40 int
41 sgl_to_dbl_fcnvff(
42 sgl_floating_point *srcptr,
43 unsigned int *nullptr,
44 dbl_floating_point *dstptr,
45 unsigned int *status)
46 {
47 register unsigned int src, resultp1, resultp2;
48 register int src_exponent;
49
50 src = *srcptr;
51 src_exponent = Sgl_exponent(src);
52 Dbl_allp1(resultp1) = Sgl_all(src);
53
54
55
56 if (src_exponent == SGL_INFINITY_EXPONENT) {
57
58
59
60 if (Sgl_iszero_mantissa(src)) {
61
62
63
64 Dbl_setinfinity_exponentmantissa(resultp1,resultp2);
65 Dbl_copytoptr(resultp1,resultp2,dstptr);
66 return(NOEXCEPTION);
67 }
68 else {
69
70
71
72 if (Sgl_isone_signaling(src)) {
73
74 if (Is_invalidtrap_enabled())
75 return(INVALIDEXCEPTION);
76
77 else {
78 Set_invalidflag();
79 Sgl_set_quiet(src);
80 }
81 }
82
83
84
85 Dbl_setinfinity_exponent(resultp1);
86 Sgl_to_dbl_mantissa(src,resultp1,resultp2);
87 Dbl_copytoptr(resultp1,resultp2,dstptr);
88 return(NOEXCEPTION);
89 }
90 }
91
92
93
94 if (src_exponent == 0) {
95
96
97
98 if (Sgl_isnotzero_mantissa(src)) {
99
100
101
102 Sgl_clear_signexponent(src);
103 Sgl_leftshiftby1(src);
104 Sgl_normalize(src,src_exponent);
105 Sgl_to_dbl_exponent(src_exponent,resultp1);
106 Sgl_to_dbl_mantissa(src,resultp1,resultp2);
107 }
108 else {
109 Dbl_setzero_exponentmantissa(resultp1,resultp2);
110 }
111 Dbl_copytoptr(resultp1,resultp2,dstptr);
112 return(NOEXCEPTION);
113 }
114
115
116
117 Sgl_to_dbl_exponent(src_exponent, resultp1);
118 Sgl_to_dbl_mantissa(Sgl_mantissa(src), resultp1,resultp2);
119 Dbl_copytoptr(resultp1,resultp2,dstptr);
120 return(NOEXCEPTION);
121 }
122
123
124
125
126
127 int
128 dbl_to_sgl_fcnvff(
129 dbl_floating_point *srcptr,
130 unsigned int *nullptr,
131 sgl_floating_point *dstptr,
132 unsigned int *status)
133 {
134 register unsigned int srcp1, srcp2, result;
135 register int src_exponent, dest_exponent, dest_mantissa;
136 register boolean inexact = FALSE, guardbit = FALSE, stickybit = FALSE;
137 register boolean lsb_odd = FALSE;
138 boolean is_tiny = FALSE;
139
140 Dbl_copyfromptr(srcptr,srcp1,srcp2);
141 src_exponent = Dbl_exponent(srcp1);
142 Sgl_all(result) = Dbl_allp1(srcp1);
143
144
145
146 if (src_exponent == DBL_INFINITY_EXPONENT) {
147
148
149
150 if (Dbl_iszero_mantissa(srcp1,srcp2)) {
151
152
153
154 Sgl_setinfinity_exponentmantissa(result);
155 *dstptr = result;
156 return(NOEXCEPTION);
157 }
158
159
160
161 if (Dbl_isone_signaling(srcp1)) {
162
163 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
164 else {
165 Set_invalidflag();
166
167 Dbl_set_quiet(srcp1);
168 }
169 }
170
171
172
173 Sgl_setinfinity_exponent(result);
174 Sgl_set_mantissa(result,Dallp1(srcp1)<<3 | Dallp2(srcp2)>>29);
175 if (Sgl_iszero_mantissa(result)) Sgl_set_quiet(result);
176 *dstptr = result;
177 return(NOEXCEPTION);
178 }
179
180
181
182 Dbl_to_sgl_exponent(src_exponent,dest_exponent);
183 if (dest_exponent > 0) {
184 Dbl_to_sgl_mantissa(srcp1,srcp2,dest_mantissa,inexact,guardbit,
185 stickybit,lsb_odd);
186 }
187 else {
188 if (Dbl_iszero_exponentmantissa(srcp1,srcp2)){
189 Sgl_setzero_exponentmantissa(result);
190 *dstptr = result;
191 return(NOEXCEPTION);
192 }
193 if (Is_underflowtrap_enabled()) {
194 Dbl_to_sgl_mantissa(srcp1,srcp2,dest_mantissa,inexact,
195 guardbit,stickybit,lsb_odd);
196 }
197 else {
198
199
200
201 Dbl_to_sgl_denormalized(srcp1,srcp2,dest_exponent,
202 dest_mantissa,inexact,guardbit,stickybit,lsb_odd,
203 is_tiny);
204 }
205 }
206
207
208
209 if (inexact) {
210 switch (Rounding_mode()) {
211 case ROUNDPLUS:
212 if (Sgl_iszero_sign(result)) dest_mantissa++;
213 break;
214 case ROUNDMINUS:
215 if (Sgl_isone_sign(result)) dest_mantissa++;
216 break;
217 case ROUNDNEAREST:
218 if (guardbit) {
219 if (stickybit || lsb_odd) dest_mantissa++;
220 }
221 }
222 }
223 Sgl_set_exponentmantissa(result,dest_mantissa);
224
225
226
227
228 if ((dest_exponent>0 || Is_underflowtrap_enabled()) &&
229 Sgl_isone_hidden(result)) dest_exponent++;
230
231
232
233
234 if (dest_exponent >= SGL_INFINITY_EXPONENT) {
235
236 if (Is_overflowtrap_enabled()) {
237
238
239
240 if (dest_exponent >= SGL_INFINITY_EXPONENT+SGL_WRAP)
241 return(UNIMPLEMENTEDEXCEPTION);
242
243
244
245
246 Sgl_setwrapped_exponent(result,dest_exponent,ovfl);
247 *dstptr = result;
248 if (inexact)
249 if (Is_inexacttrap_enabled())
250 return(OVERFLOWEXCEPTION|INEXACTEXCEPTION);
251 else Set_inexactflag();
252 return(OVERFLOWEXCEPTION);
253 }
254 Set_overflowflag();
255 inexact = TRUE;
256
257 Sgl_setoverflow(result);
258 }
259
260
261
262 else if (dest_exponent <= 0) {
263
264 if (Is_underflowtrap_enabled()) {
265
266
267
268 if (dest_exponent <= -(SGL_WRAP))
269 return(UNIMPLEMENTEDEXCEPTION);
270
271
272
273 Sgl_setwrapped_exponent(result,dest_exponent,unfl);
274 *dstptr = result;
275 if (inexact)
276 if (Is_inexacttrap_enabled())
277 return(UNDERFLOWEXCEPTION|INEXACTEXCEPTION);
278 else Set_inexactflag();
279 return(UNDERFLOWEXCEPTION);
280 }
281
282
283
284 if (inexact && is_tiny) Set_underflowflag();
285
286 }
287 else Sgl_set_exponent(result,dest_exponent);
288 *dstptr = result;
289
290
291
292 if (inexact)
293 if (Is_inexacttrap_enabled()) return(INEXACTEXCEPTION);
294 else Set_inexactflag();
295 return(NOEXCEPTION);
296 }