Pristine Ack-5.5
[Ack-5.5.git] / modules / src / flt_arith / flt_flt2ar.c
1 /*
2   (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3   See the copyright notice in the ACK home directory, in the file "Copyright".
4 */
5
6 /* $Id: flt_flt2ar.c,v 1.6 1994/06/24 11:15:52 ceriel Exp $ */
7
8 #include "flt_misc.h"
9 #include <em_arith.h>
10
11 arith
12 flt_flt2arith(e, uns)
13         register flt_arith *e;
14 {
15         /*      Convert the flt_arith "n" to an arith.
16         */
17         arith   n;
18         struct flt_mantissa a;
19
20         if (uns) uns = 1;
21         flt_status = 0;
22         if (e->flt_sign && uns) {
23                 flt_status = FLT_UNFL;
24                 return 0;
25         }
26         if (e->flt_exp < 0) {
27                 /* absolute value of result < 1.
28                    Return value only depends on sign:
29                 */
30                 return -e->flt_sign;
31         }
32
33         if (e->flt_exp > 8*sizeof(arith)-2 + uns) {
34                 /* probably overflow, but there is one exception:
35                 */
36                 if (e->flt_sign &&
37                     e->flt_exp == 8*sizeof(arith)-1 &&
38                     e->m2 == 0 &&
39                     e->m1 == 0x80000000) {
40                         /* No overflow in this case */
41                         flt_status = 0;
42                 }
43                 else {
44                         flt_status = FLT_OVFL;
45                         e->flt_exp = 8*sizeof(arith)-2 + uns + e->flt_sign;
46                         if (e->flt_sign) {
47                                 e->m1 = 0x80000000;
48                                 e->m2 = 0;
49                         }
50                         else {
51                                 e->m1 = 0xFFFFFFFF;
52                                 e->m2 = 0xFFFFFFFF;
53                         }
54                 }
55         }
56         
57         a = e->flt_mantissa;
58         flt_b64_sft(&a, 63-e->flt_exp);
59         n = a.flt_l_32 | ((a.flt_h_32 << 16) << 16);
60         /* not << 32; this could be an undefined operation */
61         return e->flt_sign ? -n : n;
62 }