sub_ext.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/sub_ext.c,v 1.1.1.1 2005/04/21 14:56:11 beng Exp $ */
00007 
00008 /*
00009         SUBTRACT 2 EXTENDED FORMAT NUMBERS
00010 */
00011 
00012 #include "FP_types.h"
00013 
00014 void
00015 sub_ext(e1,e2)
00016 EXTEND  *e1,*e2;
00017 {
00018         if ((e2->m1 | e2->m2) == 0L) {
00019                 return;
00020         }
00021         if ((e1->m1 | e1->m2) == 0L) {
00022                 *e1 = *e2;
00023                 e1->sign = e2->sign ? 0 : 1;
00024                 return;
00025         }
00026         sft_ext(e1, e2);
00027         if (e1->sign != e2->sign) {
00028                 /* e1 - e2 = e1 + (-e2) */
00029                 if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
00030                         b64_rsft(&e1->mantissa);      /* shift mantissa one bit RIGHT */
00031                         e1->m1 |= 0x80000000L;  /* set max bit  */
00032                         e1->exp++;              /* increase the exponent */
00033                 }
00034         }
00035         else if (e2->m1 > e1->m1 ||
00036                  (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
00037                 /*      abs(e2) > abs(e1) */
00038                 if (e1->m2 > e2->m2) {
00039                         e2->m1 -= 1;    /* carry in */
00040                 }
00041                 e2->m1 -= e1->m1;
00042                 e2->m2 -= e1->m2;
00043                 *e1 = *e2;
00044                 e1->sign = e2->sign ? 0 : 1;
00045         }
00046         else {
00047                 if (e2->m2 > e1->m2)
00048                         e1->m1 -= 1;    /* carry in */
00049                 e1->m1 -= e2->m1;
00050                 e1->m2 -= e2->m2;
00051         }
00052         nrm_ext(e1);
00053 }

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