source: trunk/minix/lib/float/add_ext.c@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.4 KB
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/add_ext.c,v 1.1.1.1 2005/04/21 14:56:10 beng Exp $ */
7
8/*
9 ADD TWO EXTENDED FORMAT NUMBERS
10*/
11
12#include "FP_types.h"
13
14void
15add_ext(e1,e2)
16register 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 return;
24 }
25 sft_ext(e1, e2); /* adjust mantissas to equal powers */
26 if (e1->sign != e2->sign) {
27 /* e1 + e2 = e1 - (-e2) */
28 if (e2->m1 > e1->m1 ||
29 (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
30 /* abs(e2) > abs(e1) */
31 EXTEND x;
32
33 x = *e1;
34 *e1 = *e2;
35 if (x.m2 > e1->m2) {
36 e1->m1 -= 1; /* carry in */
37 }
38 e1->m1 -= x.m1;
39 e1->m2 -= x.m2;
40 }
41 else {
42 if (e2->m2 > e1->m2)
43 e1->m1 -= 1; /* carry in */
44 e1->m1 -= e2->m1;
45 e1->m2 -= e2->m2;
46 }
47 }
48 else {
49 if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
50 b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
51 e1->m1 |= 0x80000000L; /* set max bit */
52 e1->exp++; /* increase the exponent */
53 }
54 }
55 nrm_ext(e1);
56}
Note: See TracBrowser for help on using the repository browser.