comparison tomsfastmath/src/addsub/fp_add.c @ 643:a362b62d38b2 dropbear-tfm

Add tomsfastmath from git rev bfa4582842bc3bab42e4be4aed5703437049502a with Makefile.in renamed
author Matt Johnston <matt@ucc.asn.au>
date Wed, 23 Nov 2011 18:10:20 +0700
parents
children
comparison
equal deleted inserted replaced
642:33fd2f3499d2 643:a362b62d38b2
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, [email protected]
9 */
10 #include <tfm.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$ */