diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/math/rand/rand_test.go | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/math/rand/rand_test.go')
-rw-r--r-- | src/pkg/math/rand/rand_test.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/pkg/math/rand/rand_test.go b/src/pkg/math/rand/rand_test.go index bbd44e3f8..4d3abdb60 100644 --- a/src/pkg/math/rand/rand_test.go +++ b/src/pkg/math/rand/rand_test.go @@ -57,16 +57,13 @@ func (this *statsResults) checkSimilarDistribution(expected *statsResults) error func getStatsResults(samples []float64) *statsResults { res := new(statsResults) - var sum float64 - for i := range samples { - sum += samples[i] + var sum, squaresum float64 + for _, s := range samples { + sum += s + squaresum += s * s } res.mean = sum / float64(len(samples)) - var devsum float64 - for i := range samples { - devsum += math.Pow(samples[i]-res.mean, 2) - } - res.stddev = math.Sqrt(devsum / float64(len(samples))) + res.stddev = math.Sqrt(squaresum/float64(len(samples)) - res.mean*res.mean) return res } |