Fix stupid bug in division that caused quotient to be off by one in
authorChris Hanson <org/chris-hanson/cph>
Fri, 12 Jan 1990 23:37:17 +0000 (23:37 +0000)
committerChris Hanson <org/chris-hanson/cph>
Fri, 12 Jan 1990 23:37:17 +0000 (23:37 +0000)
rare cases.

v7/src/microcode/bignum.c
v7/src/microcode/version.h
v8/src/microcode/version.h

index 793d86683f75ea454cea1da77ba7e343040137bf..07234d848c85d6e913ca60a75875778bcdf83dd8 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bignum.c,v 9.28 1989/09/20 23:05:57 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bignum.c,v 9.29 1990/01/12 23:36:36 cph Exp $
 
 Copyright (c) 1989 Massachusetts Institute of Technology
 
@@ -1091,14 +1091,21 @@ bignum_divide_unsigned_normalized (u, v, q)
   while (u_scan_limit < u_scan)
     {
       uj = (*--u_scan);
-      /* comparand =
-          (((((uj * BIGNUM_RADIX) + uj1) % v1) * BIGNUM_RADIX) + uj2);
-        guess = (((uj * BIGNUM_RADIX) + uj1) / v1); */
-      cl = (u_scan[-2]);
-      ch = (bignum_digit_divide (uj, (u_scan[-1]), v1, (&gm)));
-      guess = gm;
-      if (guess > (BIGNUM_RADIX - 1))
-       guess = (BIGNUM_RADIX - 1);
+      if (uj != v1)
+       {
+         /* comparand =
+            (((((uj * BIGNUM_RADIX) + uj1) % v1) * BIGNUM_RADIX) + uj2);
+            guess = (((uj * BIGNUM_RADIX) + uj1) / v1); */
+         cl = (u_scan[-2]);
+         ch = (bignum_digit_divide (uj, (u_scan[-1]), v1, (&gm)));
+         guess = gm;
+       }
+      else
+       {
+         cl = (u_scan[-2]);
+         ch = ((u_scan[-1]) + v1);
+         guess = (BIGNUM_RADIX - 1);
+       }
       while (1)
        {
          /* product = (guess * v2); */
@@ -1323,11 +1330,17 @@ bignum_destructive_unnormalization (bignum, shift_right)
 #define BDD_STEP(qn, j)                                                        \
 {                                                                      \
   uj = (u[j]);                                                         \
-  uj_uj1 = (HD_CONS (uj, (u[j + 1])));                                 \
-  guess = (uj_uj1 / v1);                                               \
-  comparand = (HD_CONS ((uj_uj1 % v1), (u[j + 2])));                   \
-  if (guess > (BIGNUM_RADIX_ROOT - 1))                                 \
-    guess = (BIGNUM_RADIX_ROOT - 1);                                   \
+  if (uj != v1)                                                                \
+    {                                                                  \
+      uj_uj1 = (HD_CONS (uj, (u[j + 1])));                             \
+      guess = (uj_uj1 / v1);                                           \
+      comparand = (HD_CONS ((uj_uj1 % v1), (u[j + 2])));               \
+    }                                                                  \
+  else                                                                 \
+    {                                                                  \
+      guess = (BIGNUM_RADIX_ROOT - 1);                                 \
+      comparand = (HD_CONS (((u[j + 1]) + v1), (u[j + 2])));           \
+    }                                                                  \
   while ((guess * v2) > comparand)                                     \
     {                                                                  \
       guess -= 1;                                                      \
index 15cf473d2843a206f2a6f87117f6a9882c8c9412..b03bc1731b14c33a88f50de6b593a9596d9e733f 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.17 1990/01/12 15:20:27 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.18 1990/01/12 23:37:17 cph Exp $
 
 Copyright (c) 1988, 1989, 1990 Massachusetts Institute of Technology
 
@@ -46,7 +46,7 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     17
+#define SUBVERSION     18
 #endif
 
 #ifndef UCODE_TABLES_FILENAME
index c2c42fd7e5f9e7ac79aac1a356cf46066e8160df..43fd25edac49eec0b65fbc7feab200edb3ed0639 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.17 1990/01/12 15:20:27 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.18 1990/01/12 23:37:17 cph Exp $
 
 Copyright (c) 1988, 1989, 1990 Massachusetts Institute of Technology
 
@@ -46,7 +46,7 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     17
+#define SUBVERSION     18
 #endif
 
 #ifndef UCODE_TABLES_FILENAME