Skip to content

Commit 82ed8f1

Browse files
committed
minor fixes
1 parent 1375004 commit 82ed8f1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

1-js/02-first-steps/05-types/article.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,20 @@ We'll see more about working with numbers in the chapter <info:number>.
6868
6969
## BigInt [#bigint-type]
7070
71-
In JavaScript, the "number" type cannot safely represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives. Technically "number" type can store larger integers (up to <code>1.7976931348623157 * 10<sup>308</sup></code>), but outside of the safe integer range <code>±(2<sup>53</sup>-1)</code> a lot of integer values can't be represented using this data type: some of them are "missed" due to the limitation caused by their internal binary representation. For example, all the odd integers greater than <code>(2<sup>53</sup>-1)</code> are "missed" in the "number" type.
71+
In JavaScript, the "number" type cannot safely represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives.
7272

73-
For most purposes <code>±(2<sup>53</sup>-1)</code> range is quite enough, but sometimes we need the entire range of really big integers without missing any of them, e.g. for cryptography or microsecond-precision timestamps.
73+
To be really precise, the "number" type can store larger integers (up to <code>1.7976931348623157 * 10<sup>308</sup></code>), but outside of the safe integer range <code>±(2<sup>53</sup>-1)</code> there'll be a precision error, because not all digits fit into the fixed 64-bit storage. So an "approximate" value may be stored.
74+
75+
For example, these two numbers (right above the safe range) are the same:
76+
77+
```js
78+
console.log(9007199254740991 + 1); // 9007199254740992
79+
console.log(9007199254740991 + 2); // 9007199254740992
80+
```
81+
82+
So to say, all odd integers greater than <code>(2<sup>53</sup>-1)</code> can't be stored at all in the "number" type.
83+
84+
For most purposes <code>±(2<sup>53</sup>-1)</code> range is quite enough, but sometimes we need the entire range of really big integers, e.g. for cryptography or microsecond-precision timestamps.
7485

7586
`BigInt` type was recently added to the language to represent integers of arbitrary length.
7687

0 commit comments

Comments
 (0)