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".
9 COMPACT EXTEND FORMAT INTO FLOAT OF PROPER SIZE
13 # include "FP_shift.h"
15 # include "FP_types.h"
26 if (size == sizeof(DOUBLE)) {
28 * COMPACT EXTENDED INTO DOUBLE
30 DOUBLE *DBL = (DOUBLE *) (void *) to;
32 if ((f->m1|(f->m2 & DBL_ZERO)) == 0L) {
36 f->exp += DBL_BIAS; /* restore proper bias */
37 if (f->exp > DBL_MAX) {
38 dbl_over: trap(EFOVFL);
45 else if (f->exp < DBL_MIN) {
46 b64_rsft(&(f->mantissa));
48 b64_sft(&(f->mantissa), -f->exp);
54 /* local CAST conversion */
56 /* because of special format shift only 10 bits */
57 /* bit shift mantissa 10 bits */
59 /* first align within words, then do store operation */
61 DBL->d[0] = f->m1 >> DBL_RUNPACK; /* plus 22 == 32 */
62 DBL->d[1] = f->m2 >> DBL_RUNPACK; /* plus 22 == 32 */
63 DBL->d[1] |= (f->m1 << DBL_LUNPACK); /* plus 10 == 32 */
65 /* if not exact then round to nearest */
66 /* on a tie, round to even */
68 #ifdef EXCEPTION_INEXACT
69 if ((f->m2 & DBL_EXACT) != 0) {
72 if (((f->m2 & DBL_EXACT) > DBL_ROUNDUP)
73 || ((f->m2 & DBL_EXACT) == DBL_ROUNDUP
74 && (f->m2 & (DBL_ROUNDUP << 1)))) {
75 DBL->d[1]++; /* rounding up */
76 if (DBL->d[1] == 0L) { /* carry out */
79 if (f->exp == 0 && (DBL->d[0] & ~DBL_MASK)) {
82 if (DBL->d[0] & DBL_CARRYOUT) { /* carry out */
89 /* check for overflow */
93 #ifdef EXCEPTION_INEXACT
98 * STORE EXPONENT AND SIGN:
100 * 1) clear leading bits (B4-B15)
101 * 2) shift and store exponent
104 DBL->d[0] &= DBL_MASK;
106 ((long) (f->exp << DBL_EXPSHIFT) << EXP_STORE);
108 DBL->d[0] |= CARRYBIT;
114 #if FL_MSL_AT_LOW_ADDRESS
115 put4(DBL->d[0], (char *) &DBL->d[0]);
116 put4(DBL->d[1], (char *) &DBL->d[1]);
119 put4(DBL->d[1], (char *) &l);
120 put4(DBL->d[0], (char *) &DBL->d[1]);
127 * COMPACT EXTENDED INTO FLOAT
131 /* local CAST conversion */
132 SGL = (SINGLE *) (void *) to;
133 if ((f->m1 & SGL_ZERO) == 0L) {
137 f->exp += SGL_BIAS; /* restore bias */
138 if (f->exp > SGL_MAX) {
139 sgl_over: trap(EFOVFL);
146 else if (f->exp < SGL_MIN) {
147 b64_rsft(&(f->mantissa));
149 b64_sft(&(f->mantissa), -f->exp);
155 /* shift mantissa and store */
156 *SGL = (f->m1 >> SGL_RUNPACK);
158 /* check for rounding to nearest */
159 /* on a tie, round to even */
160 #ifdef EXCEPTION_INEXACT
162 (f->m1 & SGL_EXACT) != 0L) {
165 if (((f->m1 & SGL_EXACT) > SGL_ROUNDUP)
166 || ((f->m1 & SGL_EXACT) == SGL_ROUNDUP
167 && (f->m1 & (SGL_ROUNDUP << 1)))) {
169 if (f->exp == 0 && (*SGL & ~SGL_MASK)) {
173 if (*SGL & SGL_CARRYOUT) {
177 if (f->exp > SGL_MAX)
180 #ifdef EXCEPTION_INEXACT
185 * STORE EXPONENT AND SIGN:
187 * 1) clear leading bit of fraction
188 * 2) shift and store exponent
191 *SGL &= SGL_MASK; /* B23-B31 are 0 */
192 *SGL |= ((long) (f->exp << SGL_EXPSHIFT) << EXP_STORE);
200 put4(*SGL, (char *) &SGL);