Mark S. Miller (2013-07-12T20:48:51.000Z)
On Fri, Jul 12, 2013 at 11:00 AM, Tab Atkins Jr. <jackalmage at gmail.com>wrote:

> On Fri, Jul 12, 2013 at 10:48 AM, Allen Wirfs-Brock
> <allen at wirfs-brock.com> wrote:
> > On Jul 12, 2013, at 10:27 AM, Tab Atkins Jr. wrote:
> >> On Fri, Jul 12, 2013 at 10:19 AM, Mark S. Miller <erights at google.com>
> wrote:
> >>> No. Even if toInteger meant "no fractional component", I would still
> expect
> >>> it only to return true if there is some specific mathematical integer
> that
> >>> the JS number can be said to exactly represent. For the same reason, I
> think
> >>> isInteger(-0) should be true and isInteger(NaN) should be false.
> >>
> >> Agreed.  isInteger() has one job, and it's kinda worthless if it can't
> >> even do that.  How it should be:
> >>
> >> Number.isInteger(-0) == true
> >> Number.isInteger(NaN) == false
> >> Number.isInteger(Infinity) == false
> >>
> >> And, because of what we discussed in the recent thread...
> >>
> >> Number.isInteger(Math.pow(2,53)-1) == true
> >> Number.isInteger(Math.pow(2,53)) == false
> >
> > In other words you want to define Number.isInteger to return true only
> if it's argument is an integer number in the range -(2^53-1)..2^53-1
> >
> > That's a useful test and a plausible definition of Number.isInteger but
> it will also probably be surprising to programmers who are familiar with
> the esoterics of IEEE floats.
>
> On the other hand, people (like me) who just want to be able to tell
> when something is a freaking integer will be better served by these
> semantics.  ^_^
>

I fully agree. It will also help some programmers avoid the mistake I made
-- of including 2**53 in their own home-rolled test.



>
> > If we went that direction what should Number.toInteger do for values
> outside that range?
>

For consistency, it should wrap mod 2**53 of course.




Just kidding. I have no coherent opinion yet of what it should do. What are
the use cases we imagine toInteger may be useful for?



>
> The internal operation just returns 0 for things that aren't integers.
>  I'd be okay with that, I suppose.  (I use a similar function in some
> of my own code, and return false from the operation when the number
> cant' be converted, but that's because I use it as a combination
> tester and converter.  We have an explicit tester, so I'm fine with
> the converter hiding details of its conversion.)
>
> ~TJ
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130712/ccc323ec/attachment-0001.html>
domenic at domenicdenicola.com (2013-07-16T00:32:34.553Z)
On Fri, Jul 12, 2013 at 11:00 AM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:

> On the other hand, people (like me) who just want to be able to tell
> when something is a freaking integer will be better served by these
> semantics.  ^_^

I fully agree. It will also help some programmers avoid the mistake I made -- of including 2^53 in their own home-rolled test.

>> If we went that direction what should `Number.toInteger` do for values outside that range?

For consistency, it should wrap mod 2^53 of course.




Just kidding. I have no coherent opinion yet of what it should do. What are
the use cases we imagine `toInteger` may be useful for?