Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34734
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: sum array |
| Date | 2018-02-14 09:57 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <11978900.uLZWGnKmhe@PointedEars.de> (permalink) |
| References | <HM6dnRdhLcy-DJrHnZ2dnUU7-a3NnZ2d@westnet.com.au> |
Andrew Poulos wrote:
> To sum the integer elements in an array I'm using
>
> var sum = arr.reduce(function(a, b) {
> return a + b;
> });
>
> which is fine.
Actually, it is NOT.
> […]
> var arr = [,0, 1, -1, 3,, …];
This approach is (more or less) fine with *those* numbers and in general
with numbers that require little precision.
But as I learned recently, it is prone to “catastrophic cancellation”
in ECMAScript implementations, too, because they use IEEE-754 “double
precision” *floating-point* values for numbers by default.
Therefore, I have added implementations of the Kahan–Babuška, Kahan–Babuška–
Neumaier and pairwise summation algorithms to JSX:math/float.js yesterday,
and I am going to refactor the corresponding methods (e.g.
JSX:math/algebra.js#jsx.math.Vector.prototype.dot()) to use Kahan–Babuška–
Neumaier summation.
<https://en.wikipedia.org/wiki/Loss_of_significance>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sum array Andrew Poulos <ap_prog@hotmail.com> - 2017-11-12 11:09 +1100
Re: sum array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-12 01:20 +0000
Re: sum array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-02-14 09:57 +0100
Re: sum array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-02-15 12:12 -0800
csiph-web