# publiclibtom/libtommath

### Subversion checkout URL

You can clone with HTTPS or Subversion.

# Fix mp_mod(a, b, c) if b < 0 and a = n * b, n integer#4

Merged
merged 1 commit into from almost 2 years ago
 +4 4

### 2 participants

it used to return b, now it return 0.

 moritz `Fix mp_mod(a, b, c) if b < 0 and a = n * b, n integer` `it used to return b, now it return 0.` `265651b`
merged commit `1bd1320` into from May 11, 2012
closed this May 11, 2012

Showing 1 unique commit by 1 author.

Jan 08, 2012
`Fix mp_mod(a, b, c) if b < 0 and a = n * b, n integer`
`it used to return b, now it return 0.`
`265651b`
 `@@ -15,7 +15,7 @@` 15 15 ` * Tom St Denis, tomstdenis@gmail.com, http://libtom.org` 16 16 ` */` 17 17 ` ` 18 `-/* c = a mod b, 0 <= c < b */` 18 `+/* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */` 19 19 ` int` 20 20 ` mp_mod (mp_int * a, mp_int * b, mp_int * c)` 21 21 ` {` `@@ -31,11 +31,11 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c)` 31 31 ` return res;` 32 32 ` }` 33 33 ` ` 34 `- if (t.sign != b->sign) {` 35 `- res = mp_add (b, &t, c);` 36 `- } else {` 34 `+ if (mp_iszero(&t) || t.sign == b->sign) {` 37 35 ` res = MP_OKAY;` 38 36 ` mp_exch (&t, c);` 37 `+ } else {` 38 `+ res = mp_add (b, &t, c);` 39 39 ` }` 40 40 ` ` 41 41 ` mp_clear (&t);`