|
|
|
|
|
by MaxBarraclough
1943 days ago
|
|
When an integer can be reliably represented, that presumably means that JavaScript's definition of the Number type is such that it guarantees that a given integer can be represented exactly by the Number type. It doesn't mean you can safely do arbitrary integer arithmetic on it and get back another integer, also represented exactly. Trivially, there are no such values. 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... |
|
> When an integer can be reliably represented, that presumably
You are right that the wording is not precise, but now you're putting a lot of meaning into what you admit is an assumption.
> means that JavaScript's definition of the Number type is such that it guarantees that a given integer can be represented exactly by the Number type. It doesn't mean you can safely do arbitrary integer arithmetic
Who said arbitrary? The natural numbers are canonically represented by a successor function, denoted S(n). So we're talking about the highest natural that can be represented as such.