-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add binary integer literals #581
Comments
Removed Type-Defect label. |
Probably should be treated in the context of a general radix indicator. Added this to the Later milestone. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
+1 C++14 is scheduled to have binary literals as well. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3472.pdf |
any news on this 8 years on? |
No news, sorry. We've been focused on higher-value features like extension methods and non-nullable types. I do hope that we get to smaller quality of life features like this at some point, but we've got some more foundational stuff to do first. |
This would be super useful when dealing with hardware modelling in Dart, for example with ROHD |
If we introduce binary literals, I'd very much like to also get digit separators (#2). It's the same for other large number literals with repeated digits, but for binary ones, the length grows much faster and there is more repetition since there's only two digits to choose from. |
This feature with #2 would be very helpful when working with binary data blobs (binary files and network protocols) |
No plans currently. We've been focused on much higher priority language features. |
I have a mostly complete prototype here: https://dart-review.googlesource.com/c/sdk/+/378104 Would the language team accept this if I sent it out for review, with binary integer literals supported behind a language experiment? |
Personally I'd like it. We may want a little design round, just to be safe, since this issue predates ... well, integers as they currently exist. One thing I can see that is relevant, "now" that integers are fixed size, is whether we allow a 64-bit unsiged binary literal, like we do for hex literals. (I'd say "yes", Another is the parsing experience. I'd let scanning include invalid decimal digits, and then report it as an error, rather than stop at the first one. That way Could/should we allow the mantissa of a double to be binary? |
Although I have wanted binary literals forever, I think I prefer the general radix version, e.g., For binary literals, the general |
(If you think the prefix and the numbers run together, you can always do |
We talked about this today. There is a general consensus that a way to express binary literals would be very useful. There is some sense (not universally held) that octal would also be worth supporting. There is a general consensus that an arbitrary radix form doesn't pull its weight. General radix numbers add a great deal of complexity and testing requirements, and it seems likely that if we postpone binary literals in favor of arbitrary radix numbers we would simply never ship either. Given that almost all of the possibly radix choices are unlikely to ever be used in practice, this seems like a bad tradeoff. Given this, we propose to:
cc @srawlins @dart-lang/language-team |
This issue was originally filed by ladicek@gmail.com
When working with bits and bytes, having binary integer literals comes handy, as a lot of languages acknowledged (Python, Ruby, Java, even GCC has them as an extension). I believe that the reasoning behind adding binary literals to Java 7, as per http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000929.html, is equally valid to Dart, and therefore I propose to add binary literals in the same form ("0b100000" as an equivalent of "0x20"). I think that implementation is no concern (I did it in the VM and it was pretty straightforward, as I describe in http://ladicek.github.com/2012/04/29/hacking-the-vm-adding-binary-integer-literals.html).
The text was updated successfully, but these errors were encountered: