-
-
Notifications
You must be signed in to change notification settings - Fork 665
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
Inconsistent integer division behaviors between different targets. #3741
Comments
I think we should leave integer division by 0 unspecified. |
Yeah, but couldn't neko throw an exception there as well? |
class Div
{
public static function main()
{
var i = 1;
var j = 0;
var k:Int = (function (f:Float):Int return Std.int(f))(i / j);
trace(k);
}
}
How about the different behaviors of |
class StdInt
{
public static function main()
{
trace(Std.int(1.0 / 0.0));
trace(Std.int(1 / 0));
}
}
|
Any operation on undefined yields undefined. |
Is |
Yes because |
How about |
|
Uhm actually I was mistaken. In Haxe, there is no integer division since the result of a division is always a Float. So it means that we shouldn't have an error here, only an unspecified result equal to Std.int(+INF). @waneck I guess that comes from an optimization of Std.int(A/B) |
Yes; Both C# and Java optimize Std.int(a/b) to use integer division. I don't really understand why we need to specify that it doesn't throw an exception - if Std.int(someValue / 0) is already unspecified and presents different values - depending on the target. |
Wasn't |
I guess we've forgotten about division by 0. It indeed throws an exception in this case. |
@waneck the main issue I can see is that will give different results:
Which IMHO is not a good thing. We could still use integer division but we have to check for 0 I guess. |
Let's just add Math.idiv and be done with it. |
Yeah, I guess |
Does every Haxe target need to behave like AVM2 or dynamic-typed platforms? Haxe is a statically-typed language. I think we could change operator |
Flash's operator |
We should still optimize Std.int for people that don't know about Math.idiv I think |
I think you have just shown that this can't be done. On Wed, Jan 14, 2015 at 4:51 AM, Nicolas Cannasse notifications@github.com
|
That's my understanding as well. |
Sorry if I was not clear. What I meant was to optimize Std.int but still check for 0. |
and in that case return the same result as would have Std.int(+INF) |
I would like to see some profile data before introducing an optimization On Wed, Jan 14, 2015 at 10:10 PM, Nicolas Cannasse <notifications@github.com
|
Yes that sounds like a potential pessimization more than anything else. |
@hughsando if there is no allocation then it's a micro optimization that is not worth it I think. If we need to allocate a float for GC boxing that's another story. |
The text was updated successfully, but these errors were encountered: