Open zloirock opened 11 months ago
Number.fromString('00101010', 2)
in the readme is a valid example, however, '00101010'
is not a valid output for Number#toString
.
What about exponential notation, like Number.fromString('1e+128', 10)
(also a valid output for Number#toString
)? Here is nothing about it.
NaN and Infinity are both numbers.
They are number
by type, but are not numbers in math. They are not valid values in the spec draft. NaN
case in the readme is not clear, Infinity
is just missed.
JS doesn't have math, so that's irrelevant. JS has IEEE 754, in which NaN and Infinity are both number values.
If the spec draft considers them invalid, then the spec draft is incorrect, but for a stage 1 proposal not yet seeking advancement, the spec draft is also irrelevant.
Not exactly. This proposal operates mathematical number values
, for the ES spec they both are not mathematical values
.
In stage 1, this proposal is just a problem to solve. In order to solve it, we'd have to fully support JS number values, including those.
The intention as stated in the readme is
method which acts as the inverse of {BigInt,Number}.prototype.toString(radix = 10). It accepts only strings that can be produced by {BigInt,Number}.prototype.toString(radix = 10), and throws an exception for any other input.
Thus, only things that can be the output of toString would be accepted, and implied is that everything that Number toString can output must also be accepted. The spec details aren't worth thinking about until the proposal is ready for stage 2.
It's the reason why I raised this issue, however too much in the description of the problem and solution contradicts this. Let's wait for an explanation from the proposal authors / champions -)
I see some inconsistency in the readme and the spec draft, let's clarify some edge cases.
NaN
- it's a valid value for thenumber
type, a valid output forNumber#toString
, but it's not a number - should it be parsed?Infinity
- almost the same.-0
is a valid number, but not a valid output forNumber#toString
, should it throw?Should something like
Number.fromString('20000000000001', 16)
throw an error? It's a valid mathematical number, but it can't be represented in thenumber
type /Number#toString
.