-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Decide if we want to generate DivisionByZeroException errors #26
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
Comments
This comment was originally written by [email protected] This is standard IEE 754 behavior: 1/0 = +Infinity, -1/0 = -Infinity, Infinity/Infinity = NaN. Dart isn't doing anything differently here than either Java or JavaScript. |
This comment was originally written by [email protected] (IEE ==> IEEE) |
This comment was originally written by [email protected] You mean just Javascript. Even though the following does produce Infinity and NaN: <html> It is invalid in Java, e.g.: public class Test { results in: $ java Test Still, Dart is a new language. Couldn't it aspire to get math right instead of being just another Javascript? Thanks! |
This comment was originally written by [email protected] Your Java example is dividing ints, not (IEEE 754) floats or doubles. Please replace 1 with 1.0 and 0 with 0.0 and give your code another try. |
This comment was originally written by [email protected] IEEE 754 is what hardware implements -- so adopting a different set of semantics for floating-point numbers means relying on software to do the heavy lifting, and puts code at a big disadvantage versus code that is designed to take advantage of what the floating-point hardware can do. I thing there is a separate issue of how dividing ints should behave in Dart -- note that the / operator produces a num, not an int, even when dividing two ints. For example, 1/2 = 0.5, like JavaScript, not 0 as in Java. There is a ~/ operator that truncates to int. Currently, (1 ~/ 0) also evaluates to Infinity -- this seems like it would be worth taking up with the spec folks. |
This comment was originally written by [email protected] Yes, for Float and Double, but fails again with BigDecimal: import java.math.BigDecimal; public class Test { Produces: $ java Test But it looks like Ruby 1.8.7 still does what you are saying even with BigDecimal: $ irb
Oh, well. It's a shame that we still settle for that. :) |
This comment was originally written by [email protected] You can close this if you want. Sorry to bother about it. |
This comment was originally written by [email protected] Oops, just saw your other comment. Yes, feel free to take up with the spec folks about ints being treated as floating points. Glad I could be of limited assistance. |
DartC (the compiler from Dart to JavaScript) is not spec-compliant with regards to numbers. We compile dart numbers to JavaScript numbers (thus losing the distinction between ints and doubles). |
This comment was originally written by [email protected] Added Area-Language, Triaged labels. |
The spec was carefully thought out and it describes the intended semantics of Dart. We make allowances for dartC, and maybe it is unreasonable to do the right thing and still be performant. But AFIK, this isn't a spec issue unless we want to enshrine special dispensation for dartC in the spec. Removed Area-Language label. |
This comment was originally written by [email protected] To me, it seems that JS is correct here. 1/0 is infinity. infinity / infinity is undefined, a.k.a. NaN. |
This comment was originally written by [email protected] As Florian said, the original target for the java-based dartc was to compile dart numbers to JS numbers. The only thing that we can do here is to decide whether it is worth checking for division by zero in the current dartc or not -- I changed the description accordingly. Changed the title to: "dartc does not generate DivisionByZeroException errors". |
This comment was originally written by [email protected] Unassigned from area=compiler. This bug is no longer valid for dartc, but I believe is still a general dart to Javsscript translation issue. If not, please close. Removed Area-Compiler label. |
Added Area-Dart2JS, Triaged labels. |
Changed the title to: "Make sure dart2js generates DivisionByZeroException errors". |
Update summary to reflect that we haven't decided yet. Changed the title to: "Decide if we want to generate DivisionByZeroException errors". |
Added this to the Later milestone. |
Removed this from the Later milestone. |
This issue was originally filed by [email protected]
Dart should not report a number divided by zero as infinity. And if infinity is allowed, math using infinity should be correct.
What steps will reproduce the problem?
main() {
print(1 / 0);
print((1 / 0) / (1 / 0));
}
What is the expected output? What do you see instead?
It should report:
NaN
NaN
Instead it reports:
Infinity
NaN
What version of the product are you using? On what operating system?
Using the following on Oct 10, 2011 15:50 EDT
http://www.dartlang.org/docs/getting-started/
Please provide any additional information below.
The text was updated successfully, but these errors were encountered: