From 6b9f8c56f06532bca8a0518f7bec06b210074b37 Mon Sep 17 00:00:00 2001
From: Chris Hanson <org/chris-hanson/cph>
Date: Fri, 2 Sep 1988 04:13:50 +0000
Subject: [PATCH] Change `/' operation to return an exact integer result when
 the arguments are both exact integers, and the second argument divides the
 first.  Otherwise a flonum is returned.

---
 v7/src/microcode/generic.c | 27 ++++++++++-----------------
 v7/src/microcode/version.h |  4 ++--
 v8/src/microcode/version.h |  4 ++--
 3 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/v7/src/microcode/generic.c b/v7/src/microcode/generic.c
index 5240b122f..d747f5a16 100644
--- a/v7/src/microcode/generic.c
+++ b/v7/src/microcode/generic.c
@@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising,
 promotional, or sales literature without prior written consent from
 MIT in each case. */
 
-/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/generic.c,v 9.28 1988/08/16 17:49:29 markf Exp $ */
+/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/generic.c,v 9.29 1988/09/02 04:13:14 cph Rel $ */
 
 #include "scheme.h"
 #include "prims.h"
@@ -746,8 +746,9 @@ DEFINE_PRIMITIVE ("&*", Prim_multiply, 2, 2, 0)
      : (basic_multiply (Arg1, Arg2)));
 }
 
-static Pointer basic_divide(Arg1, Arg2)
-fast Pointer Arg1, Arg2;
+static Pointer
+basic_divide(Arg1, Arg2)
+     fast Pointer Arg1, Arg2;
 {
   switch (Type_Code(Arg1))
   { case TC_FIXNUM:
@@ -758,8 +759,10 @@ fast Pointer Arg1, Arg2;
 	    Sign_Extend(Arg1, A);
 	    Sign_Extend(Arg2, B);
 	    if (B==0) Primitive_Error(ERR_ARG_2_BAD_RANGE);
+	    if ((A % B) == 0)
+	      return (C_Integer_To_Scheme_Integer ((long) (A / B)));
             Result = (double) A / (double) B;
-	    Reduced_Flonum_Result(Result);
+	    Flonum_Result (Result);
           }
 	 case TC_BIG_FLONUM:
 	  { fast long A;
@@ -768,11 +771,6 @@ fast Pointer Arg1, Arg2;
 	    Primitive_Error(ERR_ARG_2_BAD_RANGE);
 	    Reduced_Flonum_Result(((double) A) / Get_Float(Arg2));
           }
-
-/* Prim_Divide continues on the next page */
-
-/* Prim_Divide, continued */
-
 	 case TC_BIG_FIXNUM:
 	  { Pointer Big_Arg1, Result, B;
 	    long A;
@@ -787,7 +785,7 @@ fast Pointer Arg1, Arg2;
 	    Sign_Extend(Arg1, A);
 	    { B = Big_To_Float(Arg2);
 	      if (Type_Code(B) == TC_BIG_FLONUM)
-	      { Reduced_Flonum_Result(A / Get_Float(B));
+	      { Flonum_Result(A / Get_Float(B));
 	      }
 	      Primitive_Error(ERR_ARG_2_FAILED_COERCION);
 	    }
@@ -832,11 +830,6 @@ fast Pointer Arg1, Arg2;
        }
        /*NOTREACHED*/
      }
-
-/* Prim_Divide continues on the next page */
-
-/* Prim_Divide, continued */
-
     case TC_BIG_FIXNUM:
      { switch (Type_Code(Arg2))
        { case TC_FIXNUM:
@@ -853,7 +846,7 @@ fast Pointer Arg1, Arg2;
 	    if (Type_Code(A) == TC_BIG_FLONUM)
 	    { long B;
 	      Sign_Extend(Arg2, B);
-	      Reduced_Flonum_Result(Get_Float(A) / ((double) B));
+	      Flonum_Result(Get_Float(A) / ((double) B));
 	    }
 	    Primitive_Error(ERR_ARG_1_FAILED_COERCION);
 	  }
@@ -889,7 +882,7 @@ fast Pointer Arg1, Arg2;
 	      if (Type_Code(B) == TC_BIG_FLONUM)
 	      { if (Get_Float(B) == 0)
 		  Primitive_Error(ERR_ARG_2_BAD_RANGE);
-   	        { Reduced_Flonum_Result(Get_Float(A) / Get_Float(B));
+   	        { Flonum_Result(Get_Float(A) / Get_Float(B));
 	        }
 	      }
 	      Primitive_Error(ERR_ARG_2_FAILED_COERCION);
diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h
index 1735f12a6..61801f23a 100644
--- a/v7/src/microcode/version.h
+++ b/v7/src/microcode/version.h
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 10.50 1988/08/16 18:10:16 markf Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 10.51 1988/09/02 04:13:50 cph Exp $
 
 Copyright (c) 1988 Massachusetts Institute of Technology
 
@@ -46,7 +46,7 @@ MIT in each case. */
 #define VERSION		10
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION	50
+#define SUBVERSION	51
 #endif
 
 #ifndef UCODE_TABLES_FILENAME
diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h
index 6b64c8f29..fe3876912 100644
--- a/v8/src/microcode/version.h
+++ b/v8/src/microcode/version.h
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 10.50 1988/08/16 18:10:16 markf Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 10.51 1988/09/02 04:13:50 cph Exp $
 
 Copyright (c) 1988 Massachusetts Institute of Technology
 
@@ -46,7 +46,7 @@ MIT in each case. */
 #define VERSION		10
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION	50
+#define SUBVERSION	51
 #endif
 
 #ifndef UCODE_TABLES_FILENAME
-- 
2.25.1