Add a toInteger property be to the Number constructor, for converting values to IEEE-754 double precision integers, exactly as ECMA-262’s ToInteger internal method. It could be implemented like this:

(function (global) {
    var floor = Math.floor,
        isFinite = global.isFinite;
    Object.defineProperty(Number, 'isInteger', {
        value: function isInteger(value) {
            return typeof value === 'number' && isFinite(value) && 
                   value > -9007199254740992 && value < 9007199254740992 &&
                   floor(value) === value;
        configurable: true,
        enumerable: false,
        writable: true

Douglas Crockford 2010/12/15 20:27Brendan Eich 2011/04/28 00:46

The blurb at the top describes Number.toInteger, not Number.isInteger. And it strikes me as a little weird to say that 9007199254740994 is not an integer. I can see why that cutoff was chosen, but I guess I don’t understand how users are supposed to use this function.

Jason Orendorff 2011/12/09 18:46

harmony/number.isinteger.txt · Last modified: 2011/12/09 18:51 by jorendorff
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki