-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
Floats being treated as Ints in interp mode #10918
Comments
Changing the array to contain @Simn I assume this was all to avoid the casts, keeping the runtime value typed as integer if possible? FWIW I also have to handle this annoyance a bit in |
The first question here is if int literals that are typed against For the more general case without literals, not quite sure. My usual approach here is to ask "What does Hashlink do?", because if I follow that I can always just blame Nicolas if it turns out to be a bad idea. |
For what it's worth, as a Haxe application developer, I think I would strongly expect that if a Int literal is stored in a Float typed variable, it behaves like a Float. I don't want to have to manually keep track of value lineage in addition to the types of the variables I'm using, especially if those values are defined at the top of a long code block or outside of the block entirely e.g. if I take the array from the example code and pass that into a function, are those values still 32 bit int typed? I think there's an argument for consistency with other languages as well, where if you assign an int into a float in C++, Java, C#, etc, the compiler takes care of retyping the value and other operations operate according to the type not the literal value itself. |
@Simn Hashlink C generates float literals:
Though, most other targets seem to have casts. Neko has the exact same issue #6256. Taking the example from the neko bug report also reveals that PHP and Lua have some minor issues here as well: var a:Float = 1430000000;
var b:Float = 1430000000.0;
var aa:Float = a * a;
var bb:Float = b * b;
trace('aa: $aa'); // aa: 2044900000000000000
trace('bb: $bb'); // bb: 2.0449E+18
trace('aa == bb: ${aa == bb}'); // aa == bb: false This old php issue seems to be somewhat relevant as well: #4260. |
Changing this at typer-level gives me these wonderful errors:
I suppose these overloads are now considered equal because there's no longer any cast inbetween. Not sure what to do with this, pushing back to later. |
Code
Command
haxe --main Test --interp
Haxe version: 4.2.5
Expected output
Actual output
Even when the array values are typed as floats, they still seem to be treated as ints and therefore are running into overflow issues.
The text was updated successfully, but these errors were encountered: