by lsiebert · 10y ago · 0 comments
[1] - https://en.wikipedia.org/wiki/Kahan_summation_algorithm
import fractions
print str(fractions.Fraction.from_float(0.3333).limit_denominator(10))
Almost anything that compiles to JS would be better than by-hand JS; I'd love to use ClojureScript with re-frame at work...[0] http://www.thejach.com/pseudo-public/webgl_coursera/assignme...
The tradeoff is speed, especially for dynamically typed languages. Having to check your operand types in JS before doing work is a performance killer.
The problem with a naive average like this is that if you're averaging a bunch of big numbers there is a very high chance of overflow when you're summing, so even if all the numbers fit in 32 or 53 bits your calculation will be off.
If you're not averaging thousands of large numbers, why are you even using a package instead of nums.reduce((a,b)=>a+b) / nums.length anyway?