cleaned up a bit

This commit is contained in:
ceriel 1988-08-04 18:10:34 +00:00
parent cdb038ed6f
commit dc72163d44
2 changed files with 47 additions and 53 deletions

View file

@ -20,15 +20,14 @@ EXTEND *f;
_double *to; _double *to;
int size; int size;
{ {
DOUBLE *DBL;
int error = 0; int error = 0;
SINGLE *SGL;
int exact;
if (size == sizeof(_double)) { if (size == sizeof(_double)) {
/* /*
* COMPACT EXTENDED INTO DOUBLE * COMPACT EXTENDED INTO DOUBLE
*/ */
DOUBLE *DBL;
if ((f->m1|(f->m2 & DBL_ZERO)) == 0L) { if ((f->m1|(f->m2 & DBL_ZERO)) == 0L) {
zrf8(to); zrf8(to);
return; return;
@ -51,10 +50,6 @@ dbl_over: trap(EFOVFL);
/* local CAST conversion */ /* local CAST conversion */
DBL = (DOUBLE *) to; DBL = (DOUBLE *) to;
/* check if answer is exact */
/* (the last 11 bits are zero (0) */
exact = ((f->m2 & DBL_EXACT) == 0) ? 1 : 0;
/* because of special format shift only 10 bits */ /* because of special format shift only 10 bits */
/* bit shift mantissa 10 bits */ /* bit shift mantissa 10 bits */
@ -67,8 +62,10 @@ dbl_over: trap(EFOVFL);
/* if not exact then round to nearest */ /* if not exact then round to nearest */
if (!exact) { #ifdef EXCEPTION_INEXACT
/* INEXACT(); */ if ((f->m2 & DBL_EXACT) != 0) {
INEXACT();
#endif
if (f->m2 & DBL_ROUNDUP) { if (f->m2 & DBL_ROUNDUP) {
DBL->_s.p2++; /* rounding up */ DBL->_s.p2++; /* rounding up */
if (DBL->_s.p2 == 0L) { /* carry out */ if (DBL->_s.p2 == 0L) { /* carry out */
@ -80,27 +77,40 @@ dbl_over: trap(EFOVFL);
f->exp++; f->exp++;
} }
} }
/* check for overflow */
if (f->exp > DBL_MAX)
goto dbl_over;
} }
#ifdef EXCEPTION_INEXACT
} }
/* check for overflow */ #endif
if (f->exp > DBL_MAX)
goto dbl_over;
/* /*
* STORE EXPONENT: * STORE EXPONENT AND SIGN:
* *
* 1) clear leading bits (B4-B15) * 1) clear leading bits (B4-B15)
* 2) shift and store exponent * 2) shift and store exponent
*/ */
DBL->_s.p1.fract &= DBL_MASK; DBL->_s.p1.fract &= DBL_MASK;
f->exp <<= DBL_EXPSHIFT; DBL->_s.p1.fract |=
DBL->_s.p1.fract |= ((long) f->exp << EXP_STORE); ((long) (f->exp << DBL_EXPSHIFT) << EXP_STORE);
if (f->sign)
DBL->_s.p1.fract |= CARRYBIT;
/*
* STORE MANTISSA
*/
put4(DBL->_s.p1.fract, (char *) &DBL->_s.p1.fract);
put4(DBL->_s.p2, (char *) &DBL->_s.p2);
} }
else { else {
/* /*
* COMPACT EXTENDED INTO FLOAT * COMPACT EXTENDED INTO FLOAT
*/ */
SINGLE *SGL;
/* local CAST conversion */ /* local CAST conversion */
SGL = (SINGLE *) to; SGL = (SINGLE *) to;
if ((f->m1 & SGL_ZERO) == 0L) { if ((f->m1 & SGL_ZERO) == 0L) {
@ -122,21 +132,16 @@ sgl_over: trap(EFOVFL);
if (error++) if (error++)
return; return;
} }
/* check if the answer is exact */
/* the last 40 bits are zero */
/* check first last bits of mantissa 1 */
exact = ((f->m1 & SGL_EXACT) == 0) ? 1 : 0;
/* check last 32 bits in mantissa 2 */
if (exact) /* first part masks to zero */
exact = (f->m2 == 0L) ? 1 : 0;
/* shift mantissa and store */ /* shift mantissa and store */
SGL->fract = (f->m1 >> SGL_RUNPACK); SGL->fract = (f->m1 >> SGL_RUNPACK);
/* check for rounding to nearest */ /* check for rounding to nearest */
if (!exact) { #ifdef EXCEPTION_INEXACT
/* INEXACT(); */ if (f->m2 != 0 ||
(f->m1 & SGL_EXACT) != 0L) {
INEXACT();
#endif
if (f->m1 & SGL_ROUNDUP) { if (f->m1 & SGL_ROUNDUP) {
SGL->fract++; SGL->fract++;
/* check normal */ /* check normal */
@ -144,39 +149,30 @@ sgl_over: trap(EFOVFL);
SGL->fract >>= 1; SGL->fract >>= 1;
f->exp++; f->exp++;
} }
if (f->exp > SGL_MAX)
goto sgl_over;
} }
#ifdef EXCEPTION_INEXACT
} }
if (f->exp > SGL_MAX) #endif
goto sgl_over;
/* /*
* STORE EXPONENT: * STORE EXPONENT AND SIGN:
* *
* 1) clear leading bit of fraction * 1) clear leading bit of fraction
* 2) shift and store exponent * 2) shift and store exponent
*/ */
SGL->fract &= SGL_MASK; /* B23-B31 are 0 */ SGL->fract &= SGL_MASK; /* B23-B31 are 0 */
f->exp <<= SGL_EXPSHIFT; SGL->fract |=
SGL->fract |= ((long) f->exp << EXP_STORE); ((long) (f->exp << SGL_EXPSHIFT) << EXP_STORE);
} if (f->sign)
SGL->fract |= CARRYBIT;
/* /*
* STORE SIGN BIT * STORE MANTISSA
*/ */
if (f->sign) {
SGL = (SINGLE *) to; /* make sure */
SGL->fract |= CARRYBIT;
}
/*
* STORE MANTISSA
*/
if (size == sizeof(_double)) {
put4(DBL->_s.p1.fract, (char *) &DBL->_s.p1.fract);
put4(DBL->_s.p2, (char *) &DBL->_s.p2);
}
else
put4(SGL->fract, (char *) &SGL->fract); put4(SGL->fract, (char *) &SGL->fract);
}
} }

View file

@ -37,24 +37,22 @@ _double *from;
EXTEND *to; EXTEND *to;
int size; int size;
{ {
DOUBLE *f; register char *cpt1;
register char *cpt1,*cpt2;
unsigned long tmp; unsigned long tmp;
int leadbit = 0; int leadbit = 0;
f = (DOUBLE *) from; /* local cast conversion */ cpt1 = (char *) from;
if (f->_s.p1.fract == 0L) { if (((DOUBLE *) cpt1)->_s.p1.fract == 0L) {
if (size == sizeof(SINGLE)) { if (size == sizeof(SINGLE)) {
zero: zrf_ext(to); zero: zrf_ext(to);
return; return;
} }
else if (f->_s.p2 == 0L) else if (((DOUBLE *) cpt1)->_s.p2 == 0L)
goto zero; goto zero;
} }
/* there is a number to convert so lets get started */ /* there is a number to convert so lets get started */
/* first extract the exponent; its always in the first two bytes */ /* first extract the exponent; its always in the first two bytes */
cpt1 = (char *) from;
to->exp = uget2(cpt1); to->exp = uget2(cpt1);
to->sign = (to->exp & 0x8000); /* set sign bit */ to->sign = (to->exp & 0x8000); /* set sign bit */
to->exp ^= to->sign; to->exp ^= to->sign;