This source file includes following definitions.
- dbl_fsub
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 #include "float.h"
30 #include "dbl_float.h"
31
32
33
34
35 int
36 dbl_fsub(
37 dbl_floating_point *leftptr,
38 dbl_floating_point *rightptr,
39 dbl_floating_point *dstptr,
40 unsigned int *status)
41 {
42 register unsigned int signless_upper_left, signless_upper_right, save;
43 register unsigned int leftp1, leftp2, rightp1, rightp2, extent;
44 register unsigned int resultp1 = 0, resultp2 = 0;
45
46 register int result_exponent, right_exponent, diff_exponent;
47 register int sign_save, jumpsize;
48 register boolean inexact = FALSE, underflowtrap;
49
50
51 Dbl_copyfromptr(leftptr,leftp1,leftp2);
52 Dbl_copyfromptr(rightptr,rightp1,rightp2);
53
54
55
56 Dbl_xortointp1(leftp1,rightp1,save);
57
58
59
60
61 if ((result_exponent = Dbl_exponent(leftp1)) == DBL_INFINITY_EXPONENT)
62 {
63 if (Dbl_iszero_mantissa(leftp1,leftp2))
64 {
65 if (Dbl_isnotnan(rightp1,rightp2))
66 {
67 if (Dbl_isinfinity(rightp1,rightp2) && save==0)
68 {
69
70
71
72 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
73 Set_invalidflag();
74 Dbl_makequietnan(resultp1,resultp2);
75 Dbl_copytoptr(resultp1,resultp2,dstptr);
76 return(NOEXCEPTION);
77 }
78
79
80
81 Dbl_copytoptr(leftp1,leftp2,dstptr);
82 return(NOEXCEPTION);
83 }
84 }
85 else
86 {
87
88
89
90 if (Dbl_isone_signaling(leftp1))
91 {
92
93 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
94
95 Set_invalidflag();
96 Dbl_set_quiet(leftp1);
97 }
98
99
100
101 else if (Dbl_is_signalingnan(rightp1))
102 {
103
104 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
105
106 Set_invalidflag();
107 Dbl_set_quiet(rightp1);
108 Dbl_copytoptr(rightp1,rightp2,dstptr);
109 return(NOEXCEPTION);
110 }
111
112
113
114 Dbl_copytoptr(leftp1,leftp2,dstptr);
115 return(NOEXCEPTION);
116 }
117 }
118
119
120
121 if (Dbl_isinfinity_exponent(rightp1))
122 {
123 if (Dbl_iszero_mantissa(rightp1,rightp2))
124 {
125
126 Dbl_invert_sign(rightp1);
127 Dbl_copytoptr(rightp1,rightp2,dstptr);
128 return(NOEXCEPTION);
129 }
130
131
132
133 if (Dbl_isone_signaling(rightp1))
134 {
135
136 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
137
138 Set_invalidflag();
139 Dbl_set_quiet(rightp1);
140 }
141
142
143
144 Dbl_copytoptr(rightp1,rightp2,dstptr);
145 return(NOEXCEPTION);
146 }
147
148
149
150
151 Dbl_copytoint_exponentmantissap1(leftp1,signless_upper_left);
152 Dbl_copytoint_exponentmantissap1(rightp1,signless_upper_right);
153
154
155 if(Dbl_ismagnitudeless(leftp2,rightp2,signless_upper_left,signless_upper_right))
156 {
157
158
159 Dbl_xorfromintp1(save,rightp1,rightp1);
160 Dbl_xorfromintp1(save,leftp1,leftp1);
161 Dbl_swap_lower(leftp2,rightp2);
162 result_exponent = Dbl_exponent(leftp1);
163 Dbl_invert_sign(leftp1);
164 }
165
166
167 if((right_exponent = Dbl_exponent(rightp1)) == 0)
168 {
169
170 if(Dbl_iszero_mantissa(rightp1,rightp2))
171 {
172
173 if(Dbl_iszero_exponentmantissa(leftp1,leftp2))
174 {
175
176 Dbl_invert_sign(rightp1);
177 if(Is_rounding_mode(ROUNDMINUS))
178 {
179 Dbl_or_signs(leftp1,rightp1);
180 }
181 else
182 {
183 Dbl_and_signs(leftp1,rightp1);
184 }
185 }
186 else
187 {
188
189
190
191 if( (result_exponent == 0) && Is_underflowtrap_enabled() )
192 {
193
194 sign_save = Dbl_signextendedsign(leftp1);
195 Dbl_leftshiftby1(leftp1,leftp2);
196 Dbl_normalize(leftp1,leftp2,result_exponent);
197 Dbl_set_sign(leftp1,sign_save);
198 Dbl_setwrapped_exponent(leftp1,result_exponent,unfl);
199 Dbl_copytoptr(leftp1,leftp2,dstptr);
200
201 return(UNDERFLOWEXCEPTION);
202 }
203 }
204 Dbl_copytoptr(leftp1,leftp2,dstptr);
205 return(NOEXCEPTION);
206 }
207
208
209 Dbl_clear_sign(rightp1);
210 if(result_exponent == 0 )
211 {
212
213
214
215 if( (int) save >= 0 )
216 {
217 Dbl_subtract(leftp1,leftp2,rightp1,rightp2,
218 resultp1,resultp2);
219 if(Dbl_iszero_mantissa(resultp1,resultp2))
220 {
221 if(Is_rounding_mode(ROUNDMINUS))
222 {
223 Dbl_setone_sign(resultp1);
224 }
225 else
226 {
227 Dbl_setzero_sign(resultp1);
228 }
229 Dbl_copytoptr(resultp1,resultp2,dstptr);
230 return(NOEXCEPTION);
231 }
232 }
233 else
234 {
235 Dbl_addition(leftp1,leftp2,rightp1,rightp2,
236 resultp1,resultp2);
237 if(Dbl_isone_hidden(resultp1))
238 {
239 Dbl_copytoptr(resultp1,resultp2,dstptr);
240 return(NOEXCEPTION);
241 }
242 }
243 if(Is_underflowtrap_enabled())
244 {
245
246 sign_save = Dbl_signextendedsign(resultp1);
247 Dbl_leftshiftby1(resultp1,resultp2);
248 Dbl_normalize(resultp1,resultp2,result_exponent);
249 Dbl_set_sign(resultp1,sign_save);
250 Dbl_setwrapped_exponent(resultp1,result_exponent,unfl);
251 Dbl_copytoptr(resultp1,resultp2,dstptr);
252
253 return(UNDERFLOWEXCEPTION);
254 }
255 Dbl_copytoptr(resultp1,resultp2,dstptr);
256 return(NOEXCEPTION);
257 }
258 right_exponent = 1;
259
260 }
261 else
262 {
263 Dbl_clear_signexponent_set_hidden(rightp1);
264 }
265 Dbl_clear_exponent_set_hidden(leftp1);
266 diff_exponent = result_exponent - right_exponent;
267
268
269
270
271
272
273
274 if(diff_exponent > DBL_THRESHOLD)
275 {
276 diff_exponent = DBL_THRESHOLD;
277 }
278
279
280 Dbl_right_align(rightp1,rightp2,diff_exponent,
281 extent);
282
283
284 if( (int) save >= 0 )
285 {
286
287
288
289
290
291 Dbl_subtract_withextension(leftp1,leftp2,rightp1,rightp2,
292 extent,resultp1,resultp2);
293 if(Dbl_iszero_hidden(resultp1))
294 {
295
296
297
298
299
300
301
302
303
304
305 sign_save = Dbl_signextendedsign(resultp1);
306 Dbl_leftshiftby1_withextent(resultp1,resultp2,extent,resultp1,resultp2);
307
308
309
310
311
312 if(Dbl_iszero(resultp1,resultp2))
313
314 {
315 if(Is_rounding_mode(ROUNDMINUS)) Dbl_setone_sign(resultp1);
316 Dbl_copytoptr(resultp1,resultp2,dstptr);
317 return(NOEXCEPTION);
318 }
319 result_exponent--;
320
321 if(Dbl_isone_hidden(resultp1))
322 {
323 if(result_exponent==0)
324 {
325
326
327 goto underflow;
328 }
329 else
330 {
331
332 Dbl_set_sign(resultp1,sign_save);
333 Ext_leftshiftby1(extent);
334 goto round;
335 }
336 }
337
338
339
340 if(!(underflowtrap = Is_underflowtrap_enabled()) &&
341 result_exponent==0) goto underflow;
342
343
344
345 Ext_leftshiftby1(extent);
346
347
348
349
350
351
352 while(Dbl_iszero_hiddenhigh7mantissa(resultp1))
353 {
354 Dbl_leftshiftby8(resultp1,resultp2);
355 if((result_exponent -= 8) <= 0 && !underflowtrap)
356 goto underflow;
357 }
358
359 if(Dbl_iszero_hiddenhigh3mantissa(resultp1))
360 {
361
362 Dbl_leftshiftby4(resultp1,resultp2);
363 if((result_exponent -= 4) <= 0 && !underflowtrap)
364 goto underflow;
365 }
366
367
368 if((jumpsize = Dbl_hiddenhigh3mantissa(resultp1)) > 7)
369 {
370
371 if(result_exponent <= 0) goto underflow;
372 Dbl_set_sign(resultp1,sign_save);
373 Dbl_set_exponent(resultp1,result_exponent);
374 Dbl_copytoptr(resultp1,resultp2,dstptr);
375 return(NOEXCEPTION);
376 }
377 Dbl_sethigh4bits(resultp1,sign_save);
378 switch(jumpsize)
379 {
380 case 1:
381 {
382 Dbl_leftshiftby3(resultp1,resultp2);
383 result_exponent -= 3;
384 break;
385 }
386 case 2:
387 case 3:
388 {
389 Dbl_leftshiftby2(resultp1,resultp2);
390 result_exponent -= 2;
391 break;
392 }
393 case 4:
394 case 5:
395 case 6:
396 case 7:
397 {
398 Dbl_leftshiftby1(resultp1,resultp2);
399 result_exponent -= 1;
400 break;
401 }
402 }
403 if(result_exponent > 0)
404 {
405 Dbl_set_exponent(resultp1,result_exponent);
406 Dbl_copytoptr(resultp1,resultp2,dstptr);
407 return(NOEXCEPTION);
408 }
409
410 underflow:
411 if(Is_underflowtrap_enabled())
412 {
413 Dbl_set_sign(resultp1,sign_save);
414 Dbl_setwrapped_exponent(resultp1,result_exponent,unfl);
415 Dbl_copytoptr(resultp1,resultp2,dstptr);
416
417 return(UNDERFLOWEXCEPTION);
418 }
419
420
421
422
423 Dbl_fix_overshift(resultp1,resultp2,(1-result_exponent),extent);
424 Dbl_clear_signexponent(resultp1);
425 Dbl_set_sign(resultp1,sign_save);
426 Dbl_copytoptr(resultp1,resultp2,dstptr);
427 return(NOEXCEPTION);
428 }
429
430 }
431 else
432 {
433
434 Dbl_addition(leftp1,leftp2,rightp1,rightp2,resultp1,resultp2);
435 if(Dbl_isone_hiddenoverflow(resultp1))
436 {
437
438 Dbl_rightshiftby1_withextent(resultp2,extent,extent);
439 Dbl_arithrightshiftby1(resultp1,resultp2);
440 result_exponent++;
441 }
442 }
443
444
445
446
447
448 round:
449 if(Ext_isnotzero(extent))
450 {
451 inexact = TRUE;
452 switch(Rounding_mode())
453 {
454 case ROUNDNEAREST:
455 if(Ext_isone_sign(extent))
456 {
457
458 if(Ext_isnotzero_lower(extent) ||
459 Dbl_isone_lowmantissap2(resultp2))
460 {
461
462 Dbl_increment(resultp1,resultp2);
463 }
464 }
465 break;
466
467 case ROUNDPLUS:
468 if(Dbl_iszero_sign(resultp1))
469 {
470
471 Dbl_increment(resultp1,resultp2);
472 }
473 break;
474
475 case ROUNDMINUS:
476 if(Dbl_isone_sign(resultp1))
477 {
478
479 Dbl_increment(resultp1,resultp2);
480 }
481
482 case ROUNDZERO:;
483
484 }
485 if(Dbl_isone_hiddenoverflow(resultp1)) result_exponent++;
486 }
487 if(result_exponent == DBL_INFINITY_EXPONENT)
488 {
489
490 if(Is_overflowtrap_enabled())
491 {
492 Dbl_setwrapped_exponent(resultp1,result_exponent,ovfl);
493 Dbl_copytoptr(resultp1,resultp2,dstptr);
494 if (inexact)
495 if (Is_inexacttrap_enabled())
496 return(OVERFLOWEXCEPTION | INEXACTEXCEPTION);
497 else Set_inexactflag();
498 return(OVERFLOWEXCEPTION);
499 }
500 else
501 {
502 inexact = TRUE;
503 Set_overflowflag();
504 Dbl_setoverflow(resultp1,resultp2);
505 }
506 }
507 else Dbl_set_exponent(resultp1,result_exponent);
508 Dbl_copytoptr(resultp1,resultp2,dstptr);
509 if(inexact)
510 if(Is_inexacttrap_enabled()) return(INEXACTEXCEPTION);
511 else Set_inexactflag();
512 return(NOEXCEPTION);
513 }