ack/mach/proto/fp/extend.c

107 lines
2.5 KiB
C
Raw Normal View History

1988-04-07 11:40:46 +00:00
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
1988-04-07 10:57:49 +00:00
/*
CONVERTS FLOATING POINT TO EXTENDED FORMAT
Two sizes of FLOATING Point are known:
SINGLE and DOUBLE
*/
/********************************************************/
/*
It is not required to normalize in extended
format, but it has been chosen to do so.
Extended Format is as follows (at exit):
->sign S000 0000 | 0000 0000 <SIGN>
->exp 0EEE EEEE | EEEE EEEE <EXPONENT>
->m1 LFFF FFFF | FFFF FFFF <L.Fraction>
FFFF FFFF | FFFF FFFF <Fraction>
->m2 FFFF FFFF | FFFF FFFF <Fraction>
FFFF F000 | 0000 0000 <Fraction>
*/
/********************************************************/
#include "FP_bias.h"
#include "FP_shift.h"
#include "FP_types.h"
#include "get_put.h"
/********************************************************/
extend(from,to,size)
_double *from;
EXTEND *to;
int size;
{
1988-08-04 18:10:34 +00:00
register char *cpt1;
1988-04-07 10:57:49 +00:00
unsigned long tmp;
int leadbit = 0;
1988-08-04 18:10:34 +00:00
cpt1 = (char *) from;
1989-08-15 09:04:49 +00:00
if (((DOUBLE *) cpt1)->_s.p1.fract == 0L ||
((DOUBLE *) cpt1)->_s.p1.fract == 0x80000000) {
1988-04-07 10:57:49 +00:00
if (size == sizeof(SINGLE)) {
zero: zrf_ext(to);
return;
1988-04-07 10:57:49 +00:00
}
1988-08-04 18:10:34 +00:00
else if (((DOUBLE *) cpt1)->_s.p2 == 0L)
1988-04-07 10:57:49 +00:00
goto zero;
}
/* there is a number to convert so lets get started */
1989-10-25 17:15:37 +00:00
#if FL_MSL_AT_LOW_ADDRESS
#if FL_MSW_AT_LOW_ADDRESS
1988-04-07 10:57:49 +00:00
to->exp = uget2(cpt1);
1989-10-25 17:15:37 +00:00
#else
to->exp = uget2(cpt1+2);
#endif
#else
#if FL_MSW_AT_LOW_ADDRESS
1989-11-09 17:01:29 +00:00
to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 4 : 0));
1989-10-25 17:15:37 +00:00
#else
1989-11-09 17:01:29 +00:00
to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 6 : 2));
1989-10-25 17:15:37 +00:00
#endif
#endif
1988-04-07 10:57:49 +00:00
to->sign = (to->exp & 0x8000); /* set sign bit */
to->exp ^= to->sign;
if (size == sizeof(DOUBLE))
to->exp >>= DBL_EXPSHIFT;
else
to->exp >>= SGL_EXPSHIFT;
if (to->exp > 0)
leadbit++; /* will set Lead bit later */
else to->exp++;
1988-04-07 10:57:49 +00:00
if (size == sizeof(DOUBLE)) {
1989-10-25 17:15:37 +00:00
#if FL_MSL_AT_LOW_ADDRESS
to->m1 = get4(cpt1);
1988-04-07 10:57:49 +00:00
cpt1 += 4;
tmp = get4(cpt1);
1989-10-25 17:15:37 +00:00
#else
tmp = get4(cpt1);
cpt1 += 4;
to->m1 = get4(cpt1);
#endif
to->m1 <<= DBL_M1LEFT; /* shift */
to->exp -= DBL_BIAS; /* remove bias */
1988-04-07 10:57:49 +00:00
to->m1 |= (tmp>>DBL_RPACK); /* plus 10 == 32 */
to->m2 = (tmp<<DBL_LPACK); /* plus 22 == 32 */
}
else { /* size == sizeof(SINGLE) */
1989-10-25 17:15:37 +00:00
to->m1 = get4(cpt1);
1988-04-07 10:57:49 +00:00
to->m1 <<= SGL_M1LEFT; /* shift */
to->exp -= SGL_BIAS; /* remove bias */
to->m2 = 0L;
}
to->m1 |= NORMBIT; /* set bit L */
1989-07-25 14:21:09 +00:00
if (leadbit == 0) { /* set or clear Leading Bit */
1988-04-07 10:57:49 +00:00
to->m1 &= ~NORMBIT; /* clear bit L */
1989-07-25 14:21:09 +00:00
nrm_ext(to); /* and normalize */
}
1988-04-07 10:57:49 +00:00
}