From: Stefan Kaes Date: 2005-09-13T18:46:46+09:00 Subject: Re: possible bug? Stefan Kaes wrote: > Hi, > > I have a piece of code which I think should be working, but it doesn't. > > def standard_dev(a, mean) > Math.sqrt((a.inject(0.0){|v,r| r += (v-mean)*(v-mean) })/a.length) > end > > computes results that don't make sense and differ from the values > computed by this code: > > def standard_dev(a, mean) > r = 0.0 > a.each{|v| r += (v-mean)*(v-mean) } > Math.sqrt(r/a.length) > end > Oops. This should have been: > I think the two should be *identical*. Am I missing something? >