Skip to content
New issue

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

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

Already on GitHub? # to your account

dart2js returns true for infinity is int #4984

Closed
DartBot opened this issue Sep 7, 2012 · 9 comments
Closed

dart2js returns true for infinity is int #4984

DartBot opened this issue Sep 7, 2012 · 9 comments
Labels
P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@DartBot
Copy link

DartBot commented Sep 7, 2012

This issue was originally filed by ngeoffray@google.com


See test language/infinity_test.dart. dart2js uses Math.floor(x) == x for making an int check, and infinity returns true to that operation.

@kasperl
Copy link

kasperl commented Oct 17, 2012

Removed this from the Later milestone.

@kasperl
Copy link

kasperl commented Oct 17, 2012

Added this to the M2 milestone.

@karlklose
Copy link
Contributor

This is also a problem for -0.0.

@peter-ahe-google
Copy link
Contributor

Removed this from the M2 milestone.
Added this to the Later milestone.

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed TriageForM5 label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@sigmundch sigmundch added P3 A lower priority bug or feature request and removed Priority-Medium labels Dec 10, 2015
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Feb 29, 2016
@rakudrama
Copy link
Member

We cannot easily fix that Infinity and -0.0 report as 'is int'.
It is really the same issue as #1533

In the VM, int 0 and double 0.0 give different results for negation (0 and -0.0).
This could be achieved by using the JavaScript expression -x for double and 0-x for int.
However, since 0 and 0.0 have the same representation in JavaScript, in a dynamic or num context we can't tell if the value is supposed to be double or int. For consistency we must choose one of the above. If we try to be inconsistent then the inconsistency will surface in unpredictable ways.
We chose that -0.0 is an int (and this value works in JavaScript indexing, bitops etc) rather than 'breaking' negation for doubles.

There is a similar problem with Infinity. What is the type of a+b when a and b are int?
We have a choice of saying that + is not closed on ints, meaning either (1) we model int + int as returning double (leading to many more type checks on operations like indexing), or (2) we check the result and throw on 'overflow' (but when do we check if the static type is num?), or (3) accepting Infinity as an int. Accepting Infinity is the most practical choice for generating fast idiomatic JavaScript.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

7 participants