]> pd.if.org Git - zpackage/blob - tomsfastmath/src/addsub/fp_add.c
commit files needed for zpm-fetchurl
[zpackage] / tomsfastmath / src / addsub / fp_add.c
1 /* TomsFastMath, a fast ISO C bignum library.
2  * 
3  * This project is meant to fill in where LibTomMath
4  * falls short.  That is speed ;-)
5  *
6  * This project is public domain and free for all purposes.
7  * 
8  * Tom St Denis, tomstdenis@gmail.com
9  */
10 #include <tfm_private.h>
11
12 void fp_add(fp_int *a, fp_int *b, fp_int *c)
13 {
14   int     sa, sb;
15
16   /* get sign of both inputs */
17   sa = a->sign;
18   sb = b->sign;
19
20   /* handle two cases, not four */
21   if (sa == sb) {
22     /* both positive or both negative */
23     /* add their magnitudes, copy the sign */
24     c->sign = sa;
25     s_fp_add (a, b, c);
26   } else {
27     /* one positive, the other negative */
28     /* subtract the one with the greater magnitude from */
29     /* the one of the lesser magnitude.  The result gets */
30     /* the sign of the one with the greater magnitude. */
31     if (fp_cmp_mag (a, b) == FP_LT) {
32       c->sign = sb;
33       s_fp_sub (b, a, c);
34     } else {
35       c->sign = sa;
36       s_fp_sub (a, b, c);
37     }
38   }
39 }
40
41 /* $Source$ */
42 /* $Revision$ */
43 /* $Date$ */