Re: Math.sign vs ±0

Claude Pache claude.pache at gmail.com
Wed Oct 30 01:15:17 PDT 2013


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



More information about the es-discuss mailing list