summary refs log tree commit diff stats
path: root/lib/pure/math.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/math.nim')
-rw-r--r--lib/pure/math.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim
index 05c2cf57c..9bd594549 100644
--- a/lib/pure/math.nim
+++ b/lib/pure/math.nim
@@ -117,10 +117,11 @@ proc sum*[T](x: openArray[T]): T {.noSideEffect.} =
 template toFloat(f: float): float = f
 
 proc mean*[T](x: openArray[T]): float {.noSideEffect.} =
-  ## computes the mean of the elements in `x`. 
+  ## computes the mean of the elements in `x`, which are first converted to floats.
   ## If `x` is empty, NaN is returned.
   ## ``toFloat(x: T): float`` must be defined.
-  result = toFloat(sum(x)) / toFloat(len(x))
+  for i in items(x): result = result + toFloat(i)
+  result = result / toFloat(len(x))
 
 proc variance*[T](x: openArray[T]): float {.noSideEffect.} =
   ## computes the variance of the elements in `x`.