-
Notifications
You must be signed in to change notification settings - Fork 213
Let decimal literals with exponents greater or equal to the number of decimal places have static type int #909
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
I think you are quoting old (pre Dart 2) specification. Current specification says the following in section 16.5:
|
Oops. In any case, can we treat decimal integer literals with positive exponents as ints? Being able to express a constant as |
@robertbastian I think if #2 is implemented it could be better for readability of integer literals. |
Yes, but I think |
|
@robertbastian it would be a breaking change to treat @leafpetersen @lrhn @eernstg - Leaf/Lasse/Erik any opinion on that?
This value does not really fit into 64-bit signed integer (10^23 > 8^23 = 2^69) - so it is unclear why it would be an integer. |
Isn't there already logic to treat
Isn't the size of |
There was strong support for allowing literals like The point is that We could consider literals like So it looks like we could do it. But it would definitely need to rely on the context type, because it would be seriously breaking to just say that every occurrence of |
Could someone reopen this bug then? |
This is a duplicate of #26053. It is breaking and it is a potentially confusing change. Other languages consistently make 1e7 a double. There is no good reason why 1.1e7 can't be an integer too, but I'd be even more worried about explaining that. What are the edge cases? Is 1e20 an integer and 1e21 a double? Also when compiled to JavaScript? |
Why is it breaking? The proposal is to make Currently if you write |
True, it's not breaking if only applied in an |
I think only doing this in an expectsInt(1e7); // OK. to: var x = 1e7;
expectsInt(x); // Error! We have this same problem with int-to-double, where hoisting a normal decimal integer literal out can change it from a double to an int. But we have good evidence that users have the right intuition about how that behaves, and there is a lot of prior art in other languages that inform that intuition. I don't think a similar intuition exists for scientific notation. Given how rarely this feature is used, I don't think adding special case inference rules would carry their weight. |
Given that both @lrhn and @munificent are not in support for this feature should this be closed as not planned? |
I would not object to closing it as not planned. |
[Edit, eernstg: The discussion below amounts to a proposal that some numeric literals which are currently denoting
double
values could be given the typeint
and evaluate correspondingly, as a kind of mirror image of the way we can make0
a value of typedouble
, based on the context. For instance,int i = 1e9;
would mean the same thing asint i = 1000000000;
]The literal
10e6
has static typedouble
. This contradicts the language spec, which (in chapter 15.3 Numbers) states:So by that, the static type of
10e6
should beint
, because there's no decimal point (implementation bug).However, the specification has a bug as well. According to it, the static type of
10e-6
is alsoint
. The spec should be updated to something likeThe text was updated successfully, but these errors were encountered: