Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

2 participants

Moritz Lenz Steffen Jaeckel
Moritz Lenz

it used to return b, now it return 0.

Steffen Jaeckel sjaeckel merged commit 1bd1320 into from May 11, 2012
Steffen Jaeckel sjaeckel closed this May 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 08, 2012
Moritz Lenz 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 4 deletions. Show diff stats Hide diff stats

  1. 8  bn_mp_mod.c
8  bn_mp_mod.c
@@ -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);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.