You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This probably can't be fixed due to a breakage of incompatibility but I've noticed that the functions int and float behave subtly differently in strange ways:
The float parser appears to abort the second it sees a non [0-9] or "." character except e. I expect this is due to the handling of exponentiation. It'll also terminate upon hitting a second decimal point, e, or a "." occurring anywhere after an "e".
You probably shouldn't have arbitrary text in the strings you're trying to convert to numbers anyway, but I think this should at least be documented in case someone hits it. To me, the most dangerous one is the difference between int("1e3") and float("1e3") which is a difference that could theoretically occur even in seemingly well-formed parse strings.
The text was updated successfully, but these errors were encountered:
UserAB1236872
changed the title
String parsing behavior is inconsistent between float() and int()
String parsing behavior is inconsistent between float() and int() in gdscript
Apr 30, 2019
The int functions in general lead to really unexpected results - "dfkj4dkfjj5dkjf6dfkjdk" is not a number, so why does it result in 456? It should fail to convert. Now everywhere I need to convert a string to an int, I'm going to have to remember to check if every character is a numeric character before doing the conversion, instead of just doing the conversion and checking the result. Furthermore, this requires me to implement string parsing logic that should already be in the library - I can't even use string.is_valid_integer, because that checks if the string contains an integer, not is a valid integer, making its name just flat out misleading.
I think this issue should be re-opened. Clarifying how this works in the documentation is great, but it doesn't solve the issue. The methods should actually be changed to give sensible and consistent results.
This probably can't be fixed due to a breakage of incompatibility but I've noticed that the functions
int
andfloat
behave subtly differently in strange ways:Essentially, int seems to do a left-right parse ignoring any character except [0-9] and ".". After it hits the first "." it will terminate.
Compare this with float
The float parser appears to abort the second it sees a non [0-9] or "." character except
e
. I expect this is due to the handling of exponentiation. It'll also terminate upon hitting a second decimal point, e, or a "." occurring anywhere after an "e".You probably shouldn't have arbitrary text in the strings you're trying to convert to numbers anyway, but I think this should at least be documented in case someone hits it. To me, the most dangerous one is the difference between
int("1e3")
andfloat("1e3")
which is a difference that could theoretically occur even in seemingly well-formed parse strings.The text was updated successfully, but these errors were encountered: