extend.c

Go to the documentation of this file.
00001 /*
00002   (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
00003   See the copyright notice in the ACK home directory, in the file "Copyright".
00004 */
00005 
00006 /* $Header: /opt/proj/minix/cvsroot/src/lib/float/extend.c,v 1.1.1.1 2005/04/21 14:56:10 beng Exp $ */
00007 
00008 /*
00009         CONVERTS FLOATING POINT TO EXTENDED FORMAT
00010 
00011         Two sizes of FLOATING Point are known:
00012                 SINGLE and DOUBLE
00013 */
00014 /********************************************************/
00015 /*
00016         It is not required to normalize in extended
00017         format, but it has been chosen to do so.
00018         Extended Format is as follows (at exit):
00019 
00020 ->sign  S000 0000 | 0000 0000           <SIGN>
00021 ->exp   0EEE EEEE | EEEE EEEE           <EXPONENT>
00022 ->m1    LFFF FFFF | FFFF FFFF           <L.Fraction>
00023         FFFF FFFF | FFFF FFFF           <Fraction>
00024 ->m2    FFFF FFFF | FFFF FFFF           <Fraction>
00025         FFFF F000 | 0000 0000           <Fraction>
00026 */
00027 /********************************************************/
00028 
00029 #include "FP_bias.h"
00030 #include "FP_shift.h"
00031 #include "FP_types.h"
00032 #include "get_put.h"
00033 /********************************************************/
00034 
00035 void
00036 extend(from,to,size)
00037 unsigned long   *from;
00038 EXTEND  *to;
00039 int     size;
00040 {
00041         register char *cpt1;
00042         unsigned long   tmp;
00043         int     leadbit = 0;
00044 
00045         cpt1 = (char *) from;
00046 
00047 #if FL_MSL_AT_LOW_ADDRESS
00048 #if FL_MSW_AT_LOW_ADDRESS
00049         to->exp = uget2(cpt1);
00050 #else
00051         to->exp = uget2(cpt1+2);
00052 #endif
00053 #else
00054 #if FL_MSW_AT_LOW_ADDRESS
00055         to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 4 : 0));
00056 #else
00057         to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 6 : 2));
00058 #endif
00059 #endif
00060         to->sign = (to->exp & 0x8000);  /* set sign bit */
00061         to->exp ^= to->sign;
00062         if (size == sizeof(DOUBLE))
00063                 to->exp >>= DBL_EXPSHIFT;
00064         else
00065                 to->exp >>= SGL_EXPSHIFT;
00066         if (to->exp > 0)
00067                 leadbit++;      /* will set Lead bit later      */
00068         else to->exp++;
00069 
00070         if (size == sizeof(DOUBLE))     {
00071 #if FL_MSL_AT_LOW_ADDRESS
00072                 to->m1 = get4(cpt1);
00073                 cpt1 += 4;
00074                 tmp = get4(cpt1);
00075 #else
00076                 tmp = get4(cpt1);
00077                 cpt1 += 4;
00078                 to->m1 = get4(cpt1);
00079 #endif
00080                 if (to->exp == 1 && to->m1 == 0 && tmp == 0) {
00081                         to->exp = 0;
00082                         to->sign = 0;
00083                         to->m1 = 0;
00084                         to->m2 = 0;
00085                         return;
00086                 }
00087                 to->m1 <<= DBL_M1LEFT;          /* shift        */
00088                 to->exp -= DBL_BIAS;            /* remove bias  */
00089                 to->m1 |= (tmp>>DBL_RPACK);     /* plus 10 == 32        */
00090                 to->m2 = (tmp<<DBL_LPACK);      /* plus 22 == 32        */
00091         }
00092         else    {       /* size == sizeof(SINGLE)               */
00093                 to->m1 = get4(cpt1);
00094                 to->m1  <<= SGL_M1LEFT; /* shift        */
00095                 if (to->exp == 1 && to->m1 == 0) {
00096                         to->exp = 0;
00097                         to->sign = 0;
00098                         to->m1 = 0;
00099                         to->m2 = 0;
00100                         return;
00101                 }
00102                 to->exp -= SGL_BIAS;            /* remove bias  */
00103                 to->m2 = 0L;
00104         }
00105 
00106         to->m1 |= NORMBIT;                              /* set bit L    */
00107         if (leadbit == 0) {             /* set or clear Leading Bit     */
00108                 to->m1 &= ~NORMBIT;                     /* clear bit L  */
00109                 nrm_ext(to);                            /* and normalize */
00110         }
00111 }

Generated on Fri Apr 14 22:57:26 2006 for minix by  doxygen 1.4.6