1 #include "tommath_private.h"
2 #ifdef BN_MP_ADD_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4  *
5  * LibTomMath is a library that provides multiple-precision
6  * integer arithmetic as well as number theoretic functionality.
7  *
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.
11  *
12  * SPDX-License-Identifier: Unlicense
13  */
14 
15 /* high level addition (handles signs) */
NS_IMPL_ISUPPORTS_INHERITED0(FrozenImage,ImageWrapper)16 int mp_add(const mp_int *a, const mp_int *b, mp_int *c)
17 {
18    int     sa, sb, res;
19 
20    /* get sign of both inputs */
21    sa = a->sign;
22    sb = b->sign;
23 
24    /* handle two cases, not four */
25    if (sa == sb) {
26       /* both positive or both negative */
27       /* add their magnitudes, copy the sign */
28       c->sign = sa;
29       res = s_mp_add(a, b, c);
30    } else {
31       /* one positive, the other negative */
32       /* subtract the one with the greater magnitude from */
33       /* the one of the lesser magnitude.  The result gets */
34       /* the sign of the one with the greater magnitude. */
35       if (mp_cmp_mag(a, b) == MP_LT) {
36          c->sign = sb;
37          res = s_mp_sub(b, a, c);
38       } else {
39          c->sign = sa;
40          res = s_mp_sub(a, b, c);
41       }
42    }
43    return res;
44 }
45 
46 #endif
47 
48 /* ref:         $Format:%D$ */
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)49 /* git commit:  $Format:%H$ */
50 /* commit time: $Format:%ai$ */
51