summary refs log tree commit diff stats
path: root/lib/pure/math.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2010-12-13 07:58:35 +0100
committerAraq <rumpf_a@web.de>2010-12-13 07:58:35 +0100
commit63ac32e6de018b5e175efb6f61675bfe36394973 (patch)
tree5e95795798ccdadecdbfaa8340d7382eae8ee9be /lib/pure/math.nim
parente7fe8edab39884f59d685d2608f8bd944cad27e6 (diff)
downloadNim-63ac32e6de018b5e175efb6f61675bfe36394973.tar.gz
bugfix: multiple yield statements and loop body vars
Diffstat (limited to 'lib/pure/math.nim')
-rwxr-xr-xlib/pure/math.nim14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim
index 8e3dd4bdb..d347006b7 100755
--- a/lib/pure/math.nim
+++ b/lib/pure/math.nim
@@ -226,21 +226,27 @@ proc push*(s: var TRunningStat, x: float) =
   inc(s.n)
   # See Knuth TAOCP vol 2, 3rd edition, page 232
   if s.n == 1:
+    s.min = x
+    s.max = x
     s.oldM = x
     s.mean = x
     s.oldS = 0.0
   else:
+    if s.min > x: s.min = x
+    if s.max < x: s.max = x
     s.mean = s.oldM + (x - s.oldM)/toFloat(s.n)
     s.newS = s.oldS + (x - s.oldM)*(x - s.mean)
 
     # set up for next iteration:
     s.oldM = s.mean
     s.oldS = s.newS
-  
   s.sum = s.sum + x
-  if s.min > x: s.min = x
-  if s.max < x: s.max = x
-
+  
+proc push*(s: var TRunningStat, x: int) = 
+  ## pushes a value `x` for processing. `x` is simply converted to ``float``
+  ## and the other push operation is called.
+  push(s, toFloat(x))
+  
 proc variance*(s: TRunningStat): float = 
   ## computes the current variance of `s`
   if s.n > 1: result = s.newS / (toFloat(s.n - 1))