]> pd.if.org Git - zpackage/blob - tomsfastmath/src/mul/fp_mul_2d.c
commit files needed for zpm-fetchurl
[zpackage] / tomsfastmath / src / mul / fp_mul_2d.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 /* c = a * 2**d */
13 void fp_mul_2d(fp_int *a, int b, fp_int *c)
14 {
15    fp_digit carry, carrytmp, shift;
16    int x;
17
18    /* copy it */
19    fp_copy(a, c);
20
21    /* handle whole digits */
22    if (b >= DIGIT_BIT) {
23       fp_lshd(c, b/DIGIT_BIT);
24    }
25    b %= DIGIT_BIT;
26
27    /* shift the digits */
28    if (b != 0) {
29       carry = 0;   
30       shift = DIGIT_BIT - b;
31       for (x = 0; x < c->used; x++) {
32           carrytmp = c->dp[x] >> shift;
33           c->dp[x] = (c->dp[x] << b) + carry;
34           carry = carrytmp;
35       }
36       /* store last carry if room */
37       if (carry && x < FP_SIZE) {
38          c->dp[c->used++] = carry;
39       }
40    }
41    fp_clamp(c);
42 }
43
44
45 /* $Source$ */
46 /* $Revision$ */
47 /* $Date$ */