1989-07-10 11:17:19 +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$ */
|
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
flt_add(e1,e2,e3)
|
|
|
|
register flt_arith *e1,*e2,*e3;
|
|
|
|
{
|
|
|
|
/* Add two extended numbers e1 and e2, and put the result
|
|
|
|
in e3
|
|
|
|
*/
|
1989-07-11 09:15:17 +00:00
|
|
|
flt_arith ce1, ce2;
|
1989-07-10 11:17:19 +00:00
|
|
|
int diff;
|
|
|
|
|
|
|
|
flt_status = 0;
|
|
|
|
if ((e2->m1 | e2->m2) == 0L) {
|
|
|
|
*e3 = *e1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((e1->m1 | e1->m2) == 0L) {
|
|
|
|
*e3 = *e2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ce2 = *e2;
|
1989-07-11 09:15:17 +00:00
|
|
|
ce1 = *e1;
|
|
|
|
e1 = &ce1;
|
|
|
|
e2 = &ce2;
|
1989-07-10 11:17:19 +00:00
|
|
|
|
|
|
|
/* adjust mantissas to equal power */
|
1989-07-11 09:15:17 +00:00
|
|
|
diff = e2->flt_exp - e1->flt_exp;
|
1989-07-10 11:17:19 +00:00
|
|
|
if (diff < 0) {
|
|
|
|
diff = -diff;
|
1989-07-11 09:15:17 +00:00
|
|
|
e2->flt_exp += diff;
|
|
|
|
flt_b64_sft(&(e2->flt_mantissa), diff);
|
1989-07-10 11:17:19 +00:00
|
|
|
}
|
|
|
|
else if (diff > 0) {
|
|
|
|
e1->flt_exp += diff;
|
1989-07-11 09:15:17 +00:00
|
|
|
flt_b64_sft(&(e1->flt_mantissa), diff);
|
1989-07-10 11:17:19 +00:00
|
|
|
}
|
1989-07-11 09:15:17 +00:00
|
|
|
if (e1->flt_sign != e2->flt_sign) {
|
|
|
|
/* e2 + e1 = e2 - (-e1) */
|
|
|
|
int tmp = ucmp(e1->m1, e2->m1);
|
|
|
|
int tmp2 = ucmp(e1->m2, e2->m2);
|
1989-07-10 11:17:19 +00:00
|
|
|
if (tmp > 0 || (tmp == 0 && tmp2 > 0)) {
|
1989-07-11 09:15:17 +00:00
|
|
|
/* abs(e1) > abs(e2) */
|
1989-07-10 11:17:19 +00:00
|
|
|
if (tmp2 < 0) {
|
|
|
|
e1->m1 -= 1; /* carry in */
|
|
|
|
}
|
1989-07-11 09:15:17 +00:00
|
|
|
e1->m1 -= e2->m1;
|
|
|
|
e1->m2 -= e2->m2;
|
1989-07-10 11:17:19 +00:00
|
|
|
*e3 = *e1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tmp2 > 0)
|
1989-07-11 09:15:17 +00:00
|
|
|
e2->m1 -= 1; /* carry in */
|
|
|
|
e2->m1 -= e1->m1;
|
|
|
|
e2->m2 -= e1->m2;
|
|
|
|
*e3 = *e2;
|
1989-07-10 11:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1989-07-11 09:15:17 +00:00
|
|
|
*e3 = *e2;
|
|
|
|
if (flt_b64_add(&e3->flt_mantissa,&e1->flt_mantissa)) {/* addition carry */
|
1989-10-16 17:56:36 +00:00
|
|
|
flt_b64_sft(&e3->flt_mantissa, 1);
|
1989-07-10 11:17:19 +00:00
|
|
|
e3->m1 |= 0x80000000L; /* set max bit */
|
|
|
|
e3->flt_exp++; /* increase the exponent */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flt_nrm(e3);
|
|
|
|
flt_chk(e3);
|
|
|
|
}
|
|
|
|
|
|
|
|
flt_sub(e1,e2,e3)
|
|
|
|
flt_arith *e1,*e2,*e3;
|
|
|
|
{
|
1989-07-11 09:15:17 +00:00
|
|
|
e2->flt_sign = ! e2->flt_sign;
|
|
|
|
flt_add(e1,e2,e3);
|
|
|
|
e2->flt_sign = ! e2->flt_sign;
|
1989-07-10 11:17:19 +00:00
|
|
|
}
|