Re: Math.sign vs ±0
K. Gadd
kg at luminance.org
Wed Oct 30 03:44:02 PDT 2013
Unfortunately Claude, ES Math.sign is not Signum; it has five outputs, not
three, like Oliver was asking about. Observe:
> Math.sign(1 / 0)
1
> Math.sign(-1 / 0)
-1
> Math.sign(-1 / 0 * 0)
NaN
> Math.sign(0 * -1)
-0
> Math.sign(0 * 1)
0
Signum as specified in your link produces three outputs: 0, -1, and 1.
On Wed, Oct 30, 2013 at 1:15 AM, Claude Pache <claude.pache at gmail.com>wrote:
>
> Le 30 oct. 2013 à 04:54, Oliver Hunt <oliver at apple.com> a écrit :
>
> > As currently specified Math.sign has 5 different return values and, as
> far as i can tell, does not solve the problem I thought it was trying to
> address. That is the difficulty in distinguishing positive and negative
> numbers without having to manually do the divide -> ±Infinity cruft.
> >
> > What is the rational for this behaviour?
> >
> > Current Math.sign is a new, and unexpectedly complex API that doesn’t
> solve the common use case.
> >
> > —Oliver
> >
>
> `Math.sign` is expected to represent the mathematical sign function, which
> has a precise definition, see [1], [2]. Please note that `+0` and `-0` are
> the same value as far as maths is concerned, and that value is neither
> positive nor negative. (Or both nonnegative and nonpositive, if you prefer.)
>
> More generally, ES treats mathematically equal values as equal for any
> well-defined mathematical operation: doing otherwise would be new and
> unexpectedly complex (if you allow me to borrow your words).
>
> —Claude
>
> [1] http://mathworld.wolfram.com/Sign.html
> [2] https://en.wikipedia.org/wiki/Signum_function
>
> _______________________________________________
> 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/20131030/a5748592/attachment.html>
More information about the es-discuss
mailing list