#TUNING by cg
authorClaus Gittinger <cg@exept.de>
Mon, 22 Jul 2019 14:50:52 +0200
changeset 5058 6f3b933cae66
parent 5057 cc72e91af490
child 5059 c39053b76d96
#TUNING by cg class: GeometricSeries added: #at:
GeometricSeries.st
--- a/GeometricSeries.st	Fri Jul 19 17:29:05 2019 +0200
+++ b/GeometricSeries.st	Mon Jul 22 14:50:52 2019 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2000 by eXept Software AG
               All Rights Reserved
@@ -74,6 +76,33 @@
 
 ! !
 
+!GeometricSeries methodsFor:'accessing'!
+
+at:index
+    "return (i.e. compute) the index'th element"
+
+    (index between:1 and:self size) ifTrue:[
+        ^ start * (factor raisedToInteger: (index - 1))
+    ].
+    ^ self subscriptBoundsError:index
+
+    "
+     (1 to:128 byFactor:2) do:[:v | Transcript showCR:v]
+     (1 to:128 byFactor:2) at:1.
+     (1 to:128 byFactor:2) at:2.
+     (1 to:128 byFactor:2) at:3.
+     (1 to:128 byFactor:2) last.
+
+     (16 to:1 byFactor:(1/2)) do:[:v | Transcript showCR:v]
+     (16 to:1 byFactor:(1/2)) at:1.
+     (16 to:1 byFactor:(1/2)) at:2.
+     (16 to:1 byFactor:(1/2)) at:3.
+     (16 to:1 byFactor:(1/2)) last.
+    "
+
+    "Created: / 22-07-2019 / 14:49:12 / Claus Gittinger"
+! !
+
 !GeometricSeries methodsFor:'enumerating'!
 
 do:aBlock