checkin from browser
authorClaus Gittinger <cg@exept.de>
Mon, 15 Feb 1999 11:47:34 +0100
changeset 3986 2ad4ebb5ebbb
parent 3985 087595c7629b
child 3987 b3a2a7377640
checkin from browser
Interval.st
--- a/Interval.st	Mon Feb 15 09:48:26 1999 +0100
+++ b/Interval.st	Mon Feb 15 11:47:34 1999 +0100
@@ -212,20 +212,45 @@
      Redefined since SeqColl accesses the receiver with at:, which is
      slow for intervals."
 
-    |aValue|
+    |aValue iter|
 
     aValue := start.
-    step < 0 ifTrue:[
-	[stop <= aValue] whileTrue:[
-	    aBlock value:aValue.
-	    aValue := aValue + step
-	]
+    aValue isInteger ifTrue:[
+        step < 0 ifTrue:[
+            [stop <= aValue] whileTrue:[
+                aBlock value:aValue.
+                aValue := aValue + step
+            ]
+        ] ifFalse:[
+            [stop >= aValue] whileTrue:[
+                aBlock value:aValue.
+                aValue := aValue + step
+            ]
+        ]
     ] ifFalse:[
-	[stop >= aValue] whileTrue:[
-	    aBlock value:aValue.
-	    aValue := aValue + step
-	]
+        "/ the code below avoids rounding errors
+        "/ to accumulate if floats are enumerated.
+        iter := 1.
+        step < 0 ifTrue:[
+            [stop <= aValue] whileTrue:[
+                aBlock value:aValue.
+                aValue := start + (iter * step).
+                iter := iter + 1.
+            ]
+        ] ifFalse:[
+            [stop >= aValue] whileTrue:[
+                aBlock value:aValue.
+                aValue := start + (iter * step).
+                iter := iter + 1.
+            ]
+        ]
     ]
+
+    "
+     1e7 to:1e7+1 by:0.25 do:[:v | Transcript showCR:v]
+     1.0 to:2.0 by:0.25 do:[:v | Transcript showCR:v]
+     2.0 to:1.0 by:-0.25 do:[:v | Transcript showCR:v]
+    "
 !
 
 select:aBlock
@@ -299,5 +324,5 @@
 !Interval class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.23 1996-12-16 22:36:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.24 1999-02-15 10:47:34 cg Exp $'
 ! !