3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality.
8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
12 * The library is free for all purposes without any express
15 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18 /* high level addition (handles signs) */
19 int mp_add (mp_int * a, mp_int * b, mp_int * c)
23 /* get sign of both inputs */
27 /* handle two cases, not four */
29 /* both positive or both negative */
30 /* add their magnitudes, copy the sign */
32 res = s_mp_add (a, b, c);
34 /* one positive, the other negative */
35 /* subtract the one with the greater magnitude from */
36 /* the one of the lesser magnitude. The result gets */
37 /* the sign of the one with the greater magnitude. */
38 if (mp_cmp_mag (a, b) == MP_LT) {
40 res = s_mp_sub (b, a, c);
43 res = s_mp_sub (a, b, c);
51 /* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
52 /* $Revision: 1.4 $ */
53 /* $Date: 2006/12/28 01:25:13 $ */