improved #min and #max
authorClaus Gittinger <cg@exept.de>
Wed, 31 Jul 2002 10:39:13 +0200
changeset 6671 31fcea1083b6
parent 6670 7792348f31e7
child 6672 c5a5a9f9f4f5
improved #min and #max
Interval.st
--- a/Interval.st	Thu Jul 25 18:06:38 2002 +0200
+++ b/Interval.st	Wed Jul 31 10:39:13 2002 +0200
@@ -353,8 +353,52 @@
     ^ stop - start // step + 1
 ! !
 
+!Interval methodsFor:'testing'!
+
+max
+    "return the maximum value in the receiver collection,
+     redefined, since this can be easily computed.
+     Raises an error, if the receiver is empty."
+
+    step == 1 ifTrue:[stop >= start ifTrue:[^ stop]].
+    step < 0 ifTrue:[stop <= start ifTrue:[^ start]].
+    ^ super max
+
+    "
+     (0 to:15) max           
+     (0 to:15 by:2) max      
+     (0 to:15 by:8) max      
+     (15 to:0) max           -> error
+     (15 to:0 by:4) max      -> error      
+     (-1 to:-15 by:-1) max    
+     (-1 to:-15 by:-4) max    
+     (-1 to:15 by:-1) max    -> error  
+    "
+!
+
+min
+    "return the minimum value in the receiver collection,
+     redefined, since this can be easily computed.
+     Raises an error, if the receiver is empty."
+
+    step == -1 ifTrue:[stop <= start ifTrue:[^ stop]].
+    step > 0 ifTrue:[stop >= start ifTrue:[^ start]].
+    ^ super min
+
+    "
+     (0 to:15) min           
+     (0 to:15 by:2) min      
+     (0 to:15 by:8) min      
+     (15 to:0) min          -> error
+     (15 to:0 by:4) min     -> error     
+     (-1 to:-15 by:-1) min    
+     (-1 to:-15 by:-4) min    
+     (-1 to:15 by:-1) min   -> error   
+    "
+! !
+
 !Interval class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.30 2002-05-07 12:07:20 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.31 2002-07-31 08:39:13 cg Exp $'
 ! !