Additional Math functions
Sander Deryckere
sanderd17 at gmail.com
Sun Oct 4 08:27:09 UTC 2015
Note that the theoretical O(n) isn't always a good unit of measurement for
practical speed. Having to keep extra precision variables, or having extra
operations inside the loop will seriously slow down the computation, while
keeping it O(n).
I'd prefer that Math.sum(a, b, c) == a + b + c. In practical summations,
one will rarely sum numbers like 1, 1e18 and -1e18. When people really work
with numbers so precise that 1 on a scale between -1e18 and 1e18 isn't
equal to 0, then they probably shouldn't use native JS numbers and their
functions with that data.
A simple function like Math.sum needs to be simple to standardise, simple
to implement, and simple to understand for the users.
Just my opinion,
Sander
2015-10-03 2:18 GMT+02:00 Waldemar Horwat <waldemar at google.com>:
> On 10/02/2015 16:37, Alexander Jones wrote:
>
>> Interesting. I still feel that these algorithms should be given their
>> proper names in a math library, because I would feel quite troubled if
>> `Math.sum(a, b, c) !== a + b + c`. Maybe I'm alone in this view, though.
>> What do other languages do?
>>
>> On Friday, 2 October 2015, Waldemar Horwat <waldemar at google.com <mailto:
>> waldemar at google.com>> wrote:
>>
>> On 10/02/2015 13:30, Alexander Jones wrote:
>>
>> I really don't think I'd want a basic `Math.sum(a, b, c)` meaning
>> anything other than `a + b + c`, i.e. `(a + b) + c`. We should all just
>> come to terms with the fact that floating point addition is not associative.
>>
>> Or is there really some simple, O(n) algorithm to do a better
>> (more "careful") job?
>>
>>
>> Kahan summation is simple and O(n).
>>
>> There exist efficient algorithms to get the exact sum as well. See,
>> for example, http://www.ti3.tuhh.de/paper/rump/RuOgOi07I.pdf
>>
>> Waldemar
>>
>
> In the cases where the algorithms produce something other than the best
> practical results, giving them descriptive names would be useful. However,
> compound naming can then get out of hand if you also include functions such
> as average, standard deviation, etc., which include computing the sum as a
> subroutine.
>
>
> Waldemar
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151004/9a33cf5a/attachment-0001.html>
More information about the es-discuss
mailing list