Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Std.parseInt() does not parse negative hex numbers on neko/cpp target #10545

Closed
zagortenej opened this issue Jan 7, 2022 · 2 comments
Closed

Comments

@zagortenej
Copy link
Contributor

zagortenej commented Jan 7, 2022

https://api.haxe.org/Std.html#parseInt says:
"x may also start with a - to denote a negative value."

I'm not sure if this refers to decimal format only or it applies to hex too, so I'm not sure if this is a bug or just the documentation being a bit vague.

The reason why I have doubts is because this code:

trace(Std.parseInt("-0xa0"));

produces these results on following targets:

eval: -160
hashlink: -160
js: -160
java: -160
python: -160
neko: 0
cpp 0

I'm running unit tests on eval target, and from time to time on neko, and thought (based on the API docs) -0xa0 is a valid value, but it looks like neko and cpp disagree. Maybe it's the case with some of the other targets (flash, c#, php, etc.) these are the only ones I tried.

@zagortenej
Copy link
Contributor Author

zagortenej commented Jan 7, 2022

Also:

Std.parseInt("+123");

results in:

eval: 123
hashlink: null
js: 123
java: 123
python: 123
neko: 123
cpp 123

but I think this might not be considered a bug because the documentation does not mention + character as a valid one.

@Simn
Copy link
Member

Simn commented Jan 7, 2022

Could you open a pull request that adds the failing cases (also from #10544) as a unit test? That way I can fix it directly on that branch. I'll probably also deal with the problems from #10480 while I'm there.

Simn added a commit that referenced this issue Jan 19, 2022
* Add test cases for issues #10544 & #10545

* [eval] ignore tabs in parseFloat

* ignore neko

* [lua] Std.parseFloat: ignore any leading whitespace chars

Co-authored-by: Simon Krajewski <simon@haxe.org>
Co-authored-by: Aleksandr Kuzmenko <alex@stablex.ru>
@Simn Simn closed this as completed Jan 19, 2022
tobil4sk added a commit to tobil4sk/neko that referenced this issue Apr 2, 2022
All whitespace, along with + and - signs are allowed with hexadecimal
notation, to match other haxe targets.

See HaxeFoundation/haxe#10544
and HaxeFoundation/haxe#10545
Simn pushed a commit to HaxeFoundation/neko that referenced this issue Apr 11, 2022
* Fix builtin_int to handle space, +, and - with hex

All whitespace, along with + and - signs are allowed with hexadecimal
notation, to match other haxe targets.

See HaxeFoundation/haxe#10544
and HaxeFoundation/haxe#10545

* Allow trailing text after hex in builtin_int()

HaxeFoundation/haxe#7028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants