Feedback on hypot and hypot2

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Aug 14 02:14:58 PDT 2012


I think these things are really easy to implement and fast enough in
current JS engines, e.g.

function cube() {
  return cube.reduce.call(arguments, cube.iterator, 0);
}

cube.reduce = [].reduce;

cube.iterator = function (p, c) {
  return p + Math.pow(c, 3);
};

alert(cube(2, 3)); // 35

br

On Tue, Aug 14, 2012 at 9:26 AM, Herby Vojčík <herby at mailbox.sk> wrote:

> Hi,
>
> what about adding square and cube functions which accept any number of
> arguments and return sum of squares/cubes? For one arg, they would just
> return square/cube as expected, for more they will sum them (for none
> return 0 of course).
>
> Herby
>
> Allen Wirfs-Brock wrote:
>
>> check out the current ES66 spec. draft. Based upon discussions at the
>> March TC39 meeting hypot2 was eliminated and an optional third argument
>> as added to hypot.
>>
>> Note that the new function names such as hypot are generally selected to
>> match the names from widely used c libraries:
>> https://docs.google.com/**spreadsheet/ccc?key=**
>> 0Ak51JfLL8QLYdDBVcFZaMXhlY2d2R**nM0TDVxLWlua3c&hl=en#gid=0<https://docs.google.com/spreadsheet/ccc?key=0Ak51JfLL8QLYdDBVcFZaMXhlY2d2RnM0TDVxLWlua3c&hl=en#gid=0>
>> <https://docs.google.com/**spreadsheet/ccc?key=**
>> 0Ak51JfLL8QLYdDBVcFZaMXhlY2d2R**nM0TDVxLWlua3c&hl=en#gid=0<https://docs.google.com/spreadsheet/ccc?key=0Ak51JfLL8QLYdDBVcFZaMXhlY2d2RnM0TDVxLWlua3c&hl=en#gid=0>
>> >
>>
>>
>> Allen
>>
>> On Aug 13, 2012, at 2:16 AM, David Bruant wrote:
>>
>>  Hi,
>>>
>>> I'd like to provide some feedback on the more math functions proposal
>>> [1] (and the most recent PDF at the top of the page)
>>> The hypot and hypot2 functions accept 2 or 3 arguments, but I don't
>>> see a reason why they wouldn't accept an unbounded number of
>>> arguments. Although the physical world can be accurately enough
>>> described in 3 dimensions, math folks sometimes think in abstract
>>> N-dimension spaces and compute euclidian distances in these spaces.
>>> JS Engines are still free to heavily optimize the common case of 2 or
>>> 3 arguments.
>>>
>>> I'd like to talk about naming as well. "hypot" (for "Hypotenuse") is
>>> an accurate name for the 2 dimension case, but much less for 3
>>> dimensions as far as I know (the English wikipedia page [2] doesn't
>>> mention the 3D case either) and even less for N-dimension.
>>> I think it would make sense to rename it. Maybe "euclidianDistance"
>>> (too long?), "distance" [3] (accurate mathematically, but may sound
>>> vague in the broader context of JavaScript), "eucl" (too cryptic?),
>>> other?
>>>
>>> David
>>>
>>> [1] http://wiki.ecmascript.org/**doku.php?id=harmony:more_math_**
>>> functions<http://wiki.ecmascript.org/doku.php?id=harmony:more_math_functions>
>>> [2] http://en.wikipedia.org/wiki/**Hypothenuse<http://en.wikipedia.org/wiki/Hypothenuse>
>>> [3] http://en.wikipedia.org/wiki/**Distance#Geometry<http://en.wikipedia.org/wiki/Distance#Geometry>
>>>
>>>
>>> ______________________________**_________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org**>
>>> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>>>
>>>
>>
>> ------------------------------**------------------------------**
>> ------------
>>
>>
>> ______________________________**_________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>>
> ______________________________**_________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120814/5b1deeef/attachment-0001.html>


More information about the es-discuss mailing list