SmallInteger.st
branchjv
changeset 18027 3621469cc5e8
parent 18026 fa8a879502cb
parent 14795 21ddbafc7a30
child 18045 c0c600e0d3b3
--- a/SmallInteger.st	Thu Feb 07 09:53:25 2013 +0100
+++ b/SmallInteger.st	Tue Mar 05 18:10:13 2013 +0000
@@ -548,10 +548,11 @@
     "return the integer part of the quotient of the receivers value
      and the arguments value. The result is truncated toward negative infinity
      and negative, if the operands signs differ.
-     Be careful with negative results: 9 // 4 = 2,
-     while -9 // 4 = -3.
+     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
+     Especially surprising:     
+        -1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
      The following is always true:
-	(receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver
+        (receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver
      See #quo: which returns -2 in the latter."
 
 %{  /* NOCONTEXT */
@@ -569,59 +570,59 @@
     INT dividend, divisor, rslt;
 
     if (__isSmallInteger(aNumber)) {
-	divisor = __intVal(aNumber);
-	if (divisor != 0) {
-	    dividend = __intVal(self);
-	    rslt = dividend / divisor;
-	    /*
-	     * Optimized to speed up positive result
-	     */
-	    if (rslt <= 0) {
-		if (rslt == 0) {
-		    if ((dividend ^ divisor) < 0) {
-			/*
-			 * result (negative) has been truncated toward 0.
-			 * Return -1, because we truncate toward negative inf.
-			 */
-			 rslt = -1;
-		    }
-		} else {
-		    /*
-		     * If result (negative) has been truncated toward 0,
-		     * subtract 1, because we truncate toward negative inf.
-		     */
-		    if (divisor > 0) {
-			if (rslt * divisor > dividend) {
-			    rslt--;
-			}
-		    } else {
-			if (rslt * divisor < dividend) {
-			    rslt--;
-			}
-		    }
-		}
-	    }
-	    RETURN ( __mkSmallInteger(rslt) );
-	}
+        divisor = __intVal(aNumber);
+        if (divisor != 0) {
+            dividend = __intVal(self);
+            rslt = dividend / divisor;
+            /*
+             * Optimized to speed up positive result
+             */
+            if (rslt <= 0) {
+                if (rslt == 0) {
+                    if ((dividend ^ divisor) < 0) {
+                        /*
+                         * result (negative) has been truncated toward 0.
+                         * Return -1, because we truncate toward negative inf.
+                         */
+                         rslt = -1;
+                    }
+                } else {
+                    /*
+                     * If result (negative) has been truncated toward 0,
+                     * subtract 1, because we truncate toward negative inf.
+                     */
+                    if (divisor > 0) {
+                        if (rslt * divisor > dividend) {
+                            rslt--;
+                        }
+                    } else {
+                        if (rslt * divisor < dividend) {
+                            rslt--;
+                        }
+                    }
+                }
+            }
+            RETURN ( __mkSmallInteger(rslt) );
+        }
     } else {
-	if (__isFraction(aNumber)) {
-	    OBJ t;
-	    INT num, den;
-
-	    t = __FractionInstPtr(aNumber)->f_numerator;
-	    if (__isSmallInteger(t)) {
-		num = __intVal(t);
-		t = __FractionInstPtr(aNumber)->f_denominator;
-		if (__isSmallInteger(t)) {
-		    den = __intVal(t);
-		    RETURN ( __mkSmallInteger(__intVal(self) * den / num ));
-		}
-	    }
-	}
+        if (__isFraction(aNumber)) {
+            OBJ t;
+            INT num, den;
+
+            t = __FractionInstPtr(aNumber)->f_numerator;
+            if (__isSmallInteger(t)) {
+                num = __intVal(t);
+                t = __FractionInstPtr(aNumber)->f_denominator;
+                if (__isSmallInteger(t)) {
+                    den = __intVal(t);
+                    RETURN ( __mkSmallInteger(__intVal(self) * den / num ));
+                }
+            }
+        }
     }
 %}.
     (aNumber = 0) ifTrue:[
-	^ ZeroDivide raiseRequestWith:thisContext.
+        ^ ZeroDivide raiseRequestWith:thisContext.
     ].
     ^ aNumber integerQuotientFromInteger:self
 
@@ -4163,10 +4164,10 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.201 2013-02-05 16:01:31 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.202 2013-02-22 09:23:20 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.201 2013-02-05 16:01:31 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.202 2013-02-22 09:23:20 cg Exp $'
 ! !