Merge pull request #4 from moritz/negative-mod
Fix mp_mod(a, b, c) if b < 0 and a = n * b, n integer
This commit is contained in:
commit
1bd1320b19
@ -15,7 +15,7 @@
|
|||||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* c = a mod b, 0 <= c < b */
|
/* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */
|
||||||
int
|
int
|
||||||
mp_mod (mp_int * a, mp_int * b, mp_int * c)
|
mp_mod (mp_int * a, mp_int * b, mp_int * c)
|
||||||
{
|
{
|
||||||
@ -31,11 +31,11 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.sign != b->sign) {
|
if (mp_iszero(&t) || t.sign == b->sign) {
|
||||||
res = mp_add (b, &t, c);
|
|
||||||
} else {
|
|
||||||
res = MP_OKAY;
|
res = MP_OKAY;
|
||||||
mp_exch (&t, c);
|
mp_exch (&t, c);
|
||||||
|
} else {
|
||||||
|
res = mp_add (b, &t, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_clear (&t);
|
mp_clear (&t);
|
||||||
|
Loading…
Reference in New Issue
Block a user