Last active
December 30, 2015 02:49
-
-
Save ethertank/7765694 to your computer and use it in GitHub Desktop.
使ったら死ぬ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(N, global) { | |
| // 不完全 | |
| // The value of Number.MAX_SAFE_INTEGER is 9007199254740991 (2e53-1) | |
| // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. | |
| // IE8 の Object.defineProperty は Dom オブジェクトでのみ有効で、動作も異なる | |
| if(!N.MAX_SAFE_INTEGER) { | |
| N.MAX_SAFE_INTEGER = 9007199254740991; | |
| Object.defineProperty && Object.defineProperty(N, "MAX_SAFE_INTEGER", { | |
| writable : false, | |
| enumerable : false, | |
| configurable : false | |
| }); | |
| } | |
| if(!N.MIN_SAFE_INTEGER) { | |
| N.MIN_SAFE_INTEGER = -9007199254740991; | |
| Object.defineProperty && Object.defineProperty(N, "MIN_SAFE_INTEGER", { | |
| writable : false, | |
| enumerable : false, | |
| configurable : false | |
| }); | |
| } | |
| // 不完全 | |
| // The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1 that is representable as a Number value, | |
| // which is approximately 2.2204460492503130808472633361816 x 10-16. | |
| // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. | |
| if(!N.EPSILON) { | |
| N.EPSILON = 2.220446049250313e-16; | |
| Object.defineProperty && Object.defineProperty(N, "EPSILON", { | |
| writable : false, | |
| enumerable : false, | |
| configurable : false | |
| }); | |
| } | |
| N.isNaN || (N.isNaN = function (n) { | |
| return typeof n === 'number' && isNaN(n); | |
| }); | |
| //If Type(number) is not Number, return false. | |
| //If number is NaN, +∞, or −∞, return false. Otherwise, return true. | |
| N.isFinite || (N.isFinite = function(n) { return typeof n === "number" && isFinite(n); }); | |
| // N.isSafeInteger || (N.isSafeInteger = function (n) { | |
| // return n.isFinite() || Math.abs(n) > 2e53-1 | |
| //}); | |
| // 要検証 | |
| // requier: Number.isFinite() | |
| N.isInteger || N.isInt || (N.isInteger = N.isInt = function(n) { | |
| return N.isFinite(n) && -9007199254740992 < n && n < 9007199254740992 && Math.floor(n) === n; | |
| }); | |
| N.isFloat || (N.isFloat = function (n) { | |
| return !Number.isInteger(n) | |
| }); | |
| })(Number, this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ECMAScript Specification Types | |
| // ReturnIfAbrupt | |
| // Abstract Operations | |
| // ToNumber ToInteger ToInt32 ToUint32 ToInt16 ToUint16 ToInt8 ToUint8 ToUint8Clamp | |
| /* | |
| function Type(v) { | |
| return | |
| } | |
| */ | |
| // Number.prototype | |
| // Number.prototype.clz () | |
| // Number.prototype.constructor | |
| // Number.prototype.toExponential (fractionDigits) | |
| // Number.prototype.toFixed (fractionDigits) | |
| // Number.prototype.toLocaleString(reserved1=undefined, reserved2=undefined) | |
| // Number.prototype.toPrecision (precision) | |
| // Number.prototype.toString ( [ radix ] ) | |
| // Number.prototype.valueOf ( ) | |
| // Number.MAX_VALUE | |
| // Number.MIN_VALUE | |
| // Number.NaN | |
| // Number.NEGATIVE_INFINITY | |
| // Number.POSITIVE_INFINITY | |
| // [ES6] | |
| // Number.isFinite | |
| // Number.isNaN | |
| // Number.EPSILON | |
| // Number.MAX_SAFE_INTEGER | |
| // Number.MIN_SAFE_INTEGER | |
| // global.Infinity | |
| // global.NaN | |
| // global.isFinite | |
| // grobal.isNaN | |
| var A = [ | |
| "", "うんこ", NaN, -Infinity, Infinity, 0.1, "0.1", "10", Number.MIN_VALUE, | |
| 10, 10e10, Number.MAX_VALUE, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER | |
| ]; | |
| function test (array) { | |
| var answers = []; | |
| for(var i = 0; i < array.length; i++){ | |
| answers.push(Number.isInteger(array[i])); | |
| } | |
| return answers; | |
| } | |
| console.log("isInteger: " + test(A, "isInteger") ); | |
| /* | |
| ネット上のお前ら: | |
| false false false false false false false false false true true true true true | |
| true true true true true true true true true false false false false false | |
| ふぉくすけちゃん: | |
| false false false false false false false false false true true true true true | |
| true true true true true true true true true false false false false false | |
| 現実世界のお前ら: | |
| false false false false false false false false false true true false true true | |
| true true true true true true true true true false false true false false | |
| */ | |
| /* | |
| Number.MAX_VALUE は整数である。 | |
| Number.MIN_VALUE は小数である。 | |
| 整数から小数を引いた値は小数である。 | |
| Number.MAX_VALUE - Number.MIN_VALUE が使用可能な小数の内でもっとも大きい値である。 | |
| と思ったが Number.MAX_VALUE === Number.MAX_VALUE - Number.MIN_VALUE // true | |
| このへんはまともに計算できないものっぽい | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment