Line | |
---|
1 | /*
|
---|
2 | (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
---|
3 | See the copyright notice in the ACK home directory, in the file "Copyright".
|
---|
4 | */
|
---|
5 |
|
---|
6 | /* $Header: /cvsup/minix/src/lib/float/sub_ext.c,v 1.1.1.1 2005/04/21 14:56:11 beng Exp $ */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | SUBTRACT 2 EXTENDED FORMAT NUMBERS
|
---|
10 | */
|
---|
11 |
|
---|
12 | #include "FP_types.h"
|
---|
13 |
|
---|
14 | void
|
---|
15 | sub_ext(e1,e2)
|
---|
16 | EXTEND *e1,*e2;
|
---|
17 | {
|
---|
18 | if ((e2->m1 | e2->m2) == 0L) {
|
---|
19 | return;
|
---|
20 | }
|
---|
21 | if ((e1->m1 | e1->m2) == 0L) {
|
---|
22 | *e1 = *e2;
|
---|
23 | e1->sign = e2->sign ? 0 : 1;
|
---|
24 | return;
|
---|
25 | }
|
---|
26 | sft_ext(e1, e2);
|
---|
27 | if (e1->sign != e2->sign) {
|
---|
28 | /* e1 - e2 = e1 + (-e2) */
|
---|
29 | if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
|
---|
30 | b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
|
---|
31 | e1->m1 |= 0x80000000L; /* set max bit */
|
---|
32 | e1->exp++; /* increase the exponent */
|
---|
33 | }
|
---|
34 | }
|
---|
35 | else if (e2->m1 > e1->m1 ||
|
---|
36 | (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
|
---|
37 | /* abs(e2) > abs(e1) */
|
---|
38 | if (e1->m2 > e2->m2) {
|
---|
39 | e2->m1 -= 1; /* carry in */
|
---|
40 | }
|
---|
41 | e2->m1 -= e1->m1;
|
---|
42 | e2->m2 -= e1->m2;
|
---|
43 | *e1 = *e2;
|
---|
44 | e1->sign = e2->sign ? 0 : 1;
|
---|
45 | }
|
---|
46 | else {
|
---|
47 | if (e2->m2 > e1->m2)
|
---|
48 | e1->m1 -= 1; /* carry in */
|
---|
49 | e1->m1 -= e2->m1;
|
---|
50 | e1->m2 -= e2->m2;
|
---|
51 | }
|
---|
52 | nrm_ext(e1);
|
---|
53 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.