Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from May 11, 2012
Jump to file or symbol
Failed to load files and symbols.
+4 −4
Split
View
@@ -15,7 +15,7 @@
* 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
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;
}
- if (t.sign != b->sign) {
- res = mp_add (b, &t, c);
- } else {
+ if (mp_iszero(&t) || t.sign == b->sign) {
res = MP_OKAY;
mp_exch (&t, c);
+ } else {
+ res = mp_add (b, &t, c);
}
mp_clear (&t);