]> pd.if.org Git - zpackage/blob - tomsfastmath/src/addsub/s_fp_add.c
commit files needed for zpm-fetchurl
[zpackage] / tomsfastmath / src / addsub / s_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 /* unsigned addition */
13 void s_fp_add(fp_int *a, fp_int *b, fp_int *c)
14 {
15   int      x, y, oldused;
16   register fp_word  t;
17
18   y       = MAX(a->used, b->used);
19   oldused = MIN(c->used, FP_SIZE);
20   c->used = y;
21  
22   t = 0;
23   for (x = 0; x < y; x++) {
24       t         += ((fp_word)a->dp[x]) + ((fp_word)b->dp[x]);
25       c->dp[x]   = (fp_digit)t;
26       t        >>= DIGIT_BIT;
27   }
28   if (t != 0 && x < FP_SIZE) {
29      c->dp[c->used++] = (fp_digit)t;
30      ++x;
31   }
32
33   c->used = x;
34   for (; x < oldused; x++) {
35      c->dp[x] = 0;
36   }
37   fp_clamp(c);
38 }
39
40 /* $Source$ */
41 /* $Revision$ */
42 /* $Date$ */