BigInt is finally here in ES2020
developer.mozilla.org
BigInt is finally here in ES2020
1–10 of 21 posts
Re: BigInt is finally here in ES2020
#2Sorry, why exactly can’t they also define the json.parse/stringify behavior of bigints? JSON was initially derived from JavaScript, so it seems a bit weird that a new ES standard can’t interoperate with json
Re: BigInt is finally here in ES2020
#3> Using JSON.stringify() with any BigInt value will raise a TypeError as BigInt values aren't serialized in JSON by default. However, you can implement your own toJSON method if needed Sorry, why exactly can’t they also define the json.parse/stringify behavior of bigints? JSON was initially derived from JavaScript, so it seems a bit weird that a new ES standard can’t interoperate with json
Re: BigInt is finally here in ES2020
#4Isn't this wrong? JavaScript's Number type can represent some integers vastly greater than this. [0] What's special about Number.MAX_SAFE_INTEGER, if I understand correctly, is that it's the smallest integer such that (Number.MAX_SAFE_INTEGER + 1) is not guaranteed to be represented faithfully by the Number type.
Given the topic, I don't think I'm being pedantic.
edit On second thought, I could well be mistaken. The definition of JavaScript's Number type might be such that no guarantees are made about which integers greater than Number.MAX_SAFE_INTEGER can be represented exactly.
edit 2 Nope, Number.MAX_VALUE is defined to be an integer. [0] Which is to say, the largest whole number that can be represented is Number.MAX_VALUE, not Number.MAX_SAFE_INTEGER. Of course, it's not the case that Number is guaranteed to be able to exactly represent all non-negative integers less than Number.MAX_VALUE, but that isn't the same thing. The article appears to get this wrong.
[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re: BigInt is finally here in ES2020
#5Re: BigInt is finally here in ES2020
#6> BigInt is a built-in object that provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant. Isn't this wrong? JavaScript's Number type can represent some integers vastly greater than this. [0] What's special about Number.MAX_SAFE_INTEGER, if I understand correctly, is…
Re: BigInt is finally here in ES2020
#7> BigInt is a built-in object that provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant. Isn't this wrong? JavaScript's Number type can represent some integers vastly greater than this. [0] What's special about Number.MAX_SAFE_INTEGER, if I understand correctly, is…
That 2^53 - 1 comes from the 64-Bit floating point representation JS uses for the normal number type.
(Number.MAX_SAFE_INTEGER + 1) === (Number.MAX_SAFE_INTEGER + 2)
> true
edit: yeah, just as you wrote in the reply to the other commentRe: BigInt is finally here in ES2020
#8> BigInt is a built-in object that provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant. Isn't this wrong? JavaScript's Number type can represent some integers vastly greater than this. [0] What's special about Number.MAX_SAFE_INTEGER, if I understand correctly, is…
I think you misread the sentence. It's not the largest value JS can represent, it's the largest value it can "reliably represent". After 2^53 - 1 you get incorrect results when dealing with integers, making the results not "reliable".
Every non-negative integer up to and including Number.MAX_SAFE_INTEGER can be represented exactly by the Number type, in any compliant JavaScript implementation. It's also true though that Number.MAX_VALUE is itself defined to be an integer. It's therefore not true to say that Number.MAX_SAFE_INTEGER is the greatest integer that can be exactly represented by JavaScript's Number type.
Instead, Number.MAX_SAFE_INTEGER is the greatest integer such that Number.MAX_SAFE_INTEGER can be represented precisely by the Number type, and all non-negative integers less than Number.MAX_SAFE_INTEGER can be represented exactly by the Number type. (See also my second edit to my earlier post.)
It seems incorrect then that the article states:
> 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant
There's discussion of the term safely represent on the MAX_SAFE_INTEGER page. [0]
[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re: BigInt is finally here in ES2020
#9> BigInt is a built-in object that provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant. Isn't this wrong? JavaScript's Number type can represent some integers vastly greater than this. [0] What's special about Number.MAX_SAFE_INTEGER, if I understand correctly, is…
The point is that not all integers over `Number.MAX_SAFE_INTEGER` can be represented. Some can, of course. That 2^53 - 1 comes from the 64-Bit floating point representation JS uses for the normal number type. (Number.MAX_SAFE_INTEGER + 1) === (Number.MAX_SAFE_INTEGER + 2) > true edit: yeah, just as you wrote in the reply to the other comment
Right. This contradicts the article.
> 2^53 - 1 comes from the 64-Bit floating point representation JS uses
Right.
Re: BigInt is finally here in ES2020
#10Earlier quoted context omitted.
The point is that not all integers over `Number.MAX_SAFE_INTEGER` can be represented. Some can, of course. That 2^53 - 1 comes from the 64-Bit floating point representation JS uses for the normal number type. (Number.MAX_SAFE_INTEGER + 1) === (Number.MAX_SAFE_INTEGER + 2) > true edit: yeah, just as you wrote in the reply to the other comment
> The point is that not all integers over `Number.MAX_SAFE_INTEGER` can be represented. Some can, of course. Right. This contradicts the article. > 2^53 - 1 comes from the 64-Bit floating point representation JS uses Right.