-
Notifications
You must be signed in to change notification settings - Fork 58
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
haxe.Int64 Numeric Literal Suffix #92
Conversation
I'm in favor of this. Could you create a suffix table for all relevant numeric types as a kind of "if we add type X, we'll use suffix Y for it"? That way we can be sure to not run into surprises down the line. |
I think usually 64-bit numbers are
We might also consider suffixes for floats ( |
To add a different voice, suffixes and the 'long' / 'short' terminology are pet peeve of mine in languages – I feel like to know what they mean by looking at them I need to go to the language manual and find a suffix table :/ For example as Aurel300 mentioned, I can't tell how many bytes in final v = 100:I8;
final v = 100:I16;
final v = 100:I32;
final v = 100:I64;
final v = 100:F32;
final v = 100:F64; |
I agree |
If we go with a single letter suffix something like the following might work for the usual integer sizes b/B for a s/S for a i/I for a l/L for a We could also specify that adding a Thinking about it, it might be better to not use single letter to avoid this ambiguity (and means the suffixes have more meaning to eventual haxe types / not rely on c naming legacy). final v = 100i8;
final v = 100i16;
final v = 100i32;
final v = 100i64;
final v = 100f32;
final v = 100f64; edit: beat by Aurel for the more qualified suffixes suggestion. |
Yes, this indeed looks better in every way. |
What about case sensitivity? |
Suffix has been changed to i64, also includes a table of other potential suffixes, and mentions case sensitivity on the suffix letter.
I've updated the proposal to use the I don't feel strongly one way or another about case sensitivity of the suffixes, so for now I've mentioned in the detailed design section that the suffix should be case sensitive for simplicity. |
I wonder if we can do away with suffixes in favor of implicit typing – If the following worked (where long literals are implicitly typed as Int64) then I'm not convinced they'd be necessary // 8589934592 = 2 ^ 33
var x: Int64 = 8589934592; // ✓
var x: Int32 = 8589934592; // ✗ compiler error: literal is too long to be represented as Int32. Use cast to force and truncate
var x = 8589934592; // long int literal automatically typed as Int64
var x: UInt64 = 8589934592; // compiler knows we expect UInt64 here so we can type the literal as UInt64
var x: UInt32 = 8589934592; // we type the literal as UInt32 and discover it's too long and warn user |
I definitely agree that implicit typing could be used / improved here as well. Currently integer literals too large to fit in 32 bits become a float which probably makes sense from a historical point of view (guessing that was before But I don't think that sort of typing invalidates suffixes. I tend to not add type annotations where possible so being able to write code such as var x = 8589934592i16;
var x = 8589934592u64; feels much more natural to me and would stylistically align to what I tend to write. |
Imo Int64 is not good for regular use case because it's considered a class on some targets, which precludes it from being assigned to vars (very frustratingly making me split my bitflags into two enum abstracts). It's good to have a suffix but Int64 needs fixing |
This proposal has been accepted, see https://haxe.org/blog/evolution-meeting-2021/ for details. |
Would allow appending an integer literal with
i64
to create ahaxe.Int64
.Rendered version