[1] - https://en.wikipedia.org/wiki/Kahan_summation_algorithm
The tradeoff is speed, especially for dynamically typed languages. Having to check your operand types in JS before doing work is a performance killer.
Don't fall into the 'C is the devil' trap, any tool can be misused.
There might be a few legitimate use cases for C, but I've seen people pick it for the wrong reason so often (and using C because "it would be performant" is entirely invalid IME).
Of course, static analysis is always used in combination with proper coding style... but that is just the normal (professional) C development environment.
> Of course, static analysis is always used in combination with proper coding style... but that is just the normal (professional) C development environment.
>> Straight-up C is not at all suitable for safety-critical software. C plus various bolt-on tools for static analysis and the like can be usable, but is always going to be less effective (IMO) than a unified language where every tool is working according to the same rules.
Pretty sure you've just restated GP's point in your second paragraph.
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 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?