forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub_ext.fc
More file actions
executable file
·53 lines (49 loc) · 1.14 KB
/
Copy pathsub_ext.fc
File metadata and controls
executable file
·53 lines (49 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
/*
SUBTRACT 2 EXTENDED FORMAT NUMBERS
*/
#include "FP_types.h"
void
sub_ext(e1,e2)
EXTEND *e1,*e2;
{
if ((e2->m1 | e2->m2) == 0L) {
return;
}
if ((e1->m1 | e1->m2) == 0L) {
*e1 = *e2;
e1->sign = e2->sign ? 0 : 1;
return;
}
sft_ext(e1, e2);
if (e1->sign != e2->sign) {
/* e1 - e2 = e1 + (-e2) */
if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
e1->m1 |= 0x80000000L; /* set max bit */
e1->exp++; /* increase the exponent */
}
}
else if (e2->m1 > e1->m1 ||
(e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
/* abs(e2) > abs(e1) */
if (e1->m2 > e2->m2) {
e2->m1 -= 1; /* carry in */
}
e2->m1 -= e1->m1;
e2->m2 -= e1->m2;
*e1 = *e2;
e1->sign = e2->sign ? 0 : 1;
}
else {
if (e2->m2 > e1->m2)
e1->m1 -= 1; /* carry in */
e1->m1 -= e2->m1;
e1->m2 -= e2->m2;
}
nrm_ext(e1);
}