๐ฐfloating-point
๐ง under construction
JS โฉ value โฉ primitive โฉ number โฉ floating-point
Floating-Point
Number.MAX_VALUE
โโโโโโโโโโโโโโโโโโโโ
โ Number.MAX_VALUE โ
โโโโโโโโโโโโโโโโโโโโ
2ยนโฐยฒยณ 2โนโทยน
โ โ
= 1.1111111111111111111111111111111111111111111111111111 * 2ยนโฐยฒยณ
โฐโโโโโโโโโโโโโโโโโโโโ 52-bit โโโโโโโโโโโโโโโโโโโโโโโฏ
= 1.7976931348623157e+308
โ 2ยนโฐยฒโด
NaN
// โญ๏ธ `NaN` is the ONLY ONE that doesn't equal to itself.
NaN === NaN, // falseโ๏ธ
NaN !== NaN, // trueโ๏ธ
isNaN('foo'), // trueโ๏ธ (โญ๏ธ DON'T use isNaN())
Number.isNaN('foo'), // false (โญ๏ธ use Number.isNaN() instead)
Number.isNaN(NaN), // true
2 / 'foo', // NaN
ยฑInfinity & ยฑ0
const {log} = console;
/*
โโโโโโโโโโโโโโโโโโโโ
โ Number.MAX_VALUE โ
โโโโโโโโโโโโโโโโโโโโ
2ยนโฐยฒยณ 2โนโทยน
โ โ
= 1.1111111111111111111111111111111111111111111111111111 * 2ยนโฐยฒยณ
โฐโโโโโโโโโโโโโโโโโโโโ 52-bit โโโโโโโโโโโโโโโโโโโโโโโฏ
= 1.7976931348623157e+308
โ 2ยนโฐยฒโด
*/
// ---------- log ----------
const M = Number.MAX_VALUE;
const D = Math.pow(2, 970); // 2โนโทโฐ
const d = Math.pow(2, 969); // 2โนโถโน
[
// -------- Infinity --------
1 / 0, // Infinity
-1 / 0, // -Infinity
Infinity === Number.POSITIVE_INFINITY, // true
-Infinity === Number.NEGATIVE_INFINITY, // true
3 + Infinity, // Infinity
3 / Infinity, // 0
-3 / Infinity, // -0
Infinity / Infinity, // NaN
// -------- Number.MAX_VALUE --------
M, // 1.7976931348623157e+308
// โญ๏ธ ๅช่ฆ M ็ๆๅพไธไฝ (2โนโทยน) ็ไธๅ = 2โนโทโฐ ๅฐฑ่ถณไปฅ่ฎ M ใ้ฒไฝใ่ฎๆ Infinity
M + D, // Infinity
// โญ๏ธ ๅๅฐ็่ฉฑ๏ผๅๆ่ขซ็ดๆฅใๆจๆฃใใ
M + d, // M
// -------- Number.MAX_SAFE_INTEGER --------
Number.MAX_SAFE_INTEGER, // 9007199254740991 = 2โตยณ - 1
Math.pow(2, 53) - 1, // 9007199254740991
].forEach(x => log(x));
Last updated
Was this helpful?