Align tonumber with current Luau number syntax#160
Align tonumber with current Luau number syntax#160gaymeowing wants to merge 2 commits intoluau-lang:masterfrom
Conversation
|
imo the backwards compatibility loss isnt worth the change here |
|
what backwards compatibility will be lost here? |
|
today, a string passing tonumber means that every character is an ascii digit - this breaks that guarantee |
I haven't found any code that this would break, and majority of the cases where I've seen people ensuring a string is valid ASCII uses the string library to do so and not Also I don't think hexadecimal strings are made up of solely digits? As this is valid today: print(tonumber("0xFFFF")) --> 65535 |
|
that code is not valid today - you have to pass a second argument to tonumber to make it parse hexadecimal. just because you cant find code that would break doesnt mean that a case this simple doesnt exist somewhere |
|
the idea that breaking changes only matter if they affect significant customers is a bad one |
this is definitely not true. to number for example supports "nan", "inf", "1e3", "nan(...)", "1.4". ascii digits are only 0-9, and tonumber already supports scientific notation and numbers not normally represented through mere digits. |
|
okay sure, its still breaking backwards compatibility without adding significant value - use gsub first if you really want this. as is frequently the case, the solution to your problem is not more language features, but is instead writing more code |
|
what backwards compat is it breaking? |
|
tonumber also supports hexadecimal, without specifying base, like lynn posted right now already. aligning it would only make sense. |
what do you mean i ran that with the luau cli |
makes the motivation section focus more so on `tonumber`'s current odd behavior
|
It is pretty common in programming languages to have literals in the source code and runtime number parsing differences.
|
Rendered