49
49
% - Make `async` *not* a reserved word inside async functions.
50
50
% - Added 'Class Member Conflicts', simplifying and adjusting rules about
51
51
% member declaration conflicts beyond "`n` declared twice in one scope".
52
+ % - Specify that integer literals are limited to signed 64-bit values,
53
+ % and that the `int` class is intended as signed 64-bit integer, but
54
+ % that platforms may differ.
52
55
%
53
56
% 1.15
54
57
% - Change how language specification describes control flow.
@@ -3279,7 +3282,7 @@ \subsection{Numbers}
3279
3282
\LMLabel {numbers}
3280
3283
3281
3284
\LMHash {}
3282
- A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size , or a decimal double.
3285
+ A {\em numeric literal} is either a decimal or hexadecimal numeral representing an integer value , or a decimal double representation .
3283
3286
3284
3287
\begin {grammar }
3285
3288
{\bf numericLiteral:}NUMBER;
@@ -3290,55 +3293,79 @@ \subsection{Numbers}
3290
3293
{`\escapegrammar .}' DIGIT+ EXPONENT?
3291
3294
.
3292
3295
3293
- {\bf EXPONENT:}(`e' $ |$ `E') (' +' $ |$ `-` )? DIGIT+
3296
+ {\bf EXPONENT:}(`e' $ |$ `E') (` +' $ |$ `-'' )? DIGIT+
3294
3297
.
3295
3298
3296
3299
{\bf HEX\_ NUMBER:}`0x' HEX\_ DIGIT+;
3297
3300
`0X' HEX\_ DIGIT+
3298
3301
.
3299
3302
3300
- {\bf HEX\_ DIGIT:}`a'{\escapegrammar ..}' f';
3301
- `A'{\escapegrammar ..}' F';
3303
+ {\bf HEX\_ DIGIT:}`a'{\escapegrammar ..}` f';
3304
+ `A'{\escapegrammar ..}` F';
3302
3305
DIGIT
3303
3306
.
3304
3307
\end {grammar }
3305
3308
3306
3309
\LMHash {}
3307
- If a numeric literal begins with the prefix `0x' or `0X',
3308
- it denotes the integer represented by the hexadecimal numeral
3310
+ A numeric literal starting with `0x' or `0X'
3311
+ is a {\em hexadecimal integer literal}.
3312
+ It has the numeric integer value of the hexadecimal numeral
3309
3313
following `0x' (respectively `0X').
3310
- Otherwise, if the numeric literal contains only decimal digits,
3311
- it denotes an integer represented as a decimal numeral.
3312
- In either case the literal evaluates to an instance of the class \code {int}
3313
- with the integer value represented by that numeral.
3314
- Otherwise, the numeric literal contains either a decimal point or an exponent part
3315
- and it evaluates to a an instance of the `double` class
3316
- representing a 64 bit double precision floating point number
3317
- as specified by the IEEE 754 standard.
3318
3314
3319
3315
\LMHash {}
3320
- In principle, the range of integers supported by a Dart implementations is unlimited.
3321
- In practice, it is limited by available memory.
3322
- Implementations may also be limited by other considerations.
3316
+ A numeric literal that contains only decimal digits is a {\em decimal integer literal}.
3317
+ It has the numeric integer value of the decimal numeral.
3318
+
3319
+ \LMHash {}
3320
+ An {\em integer literal} is either a hexadecimal integer literal or a decimal integer literal.
3321
+ The static type of an integer literal is \code {int}.
3322
+
3323
+ \LMHash {}
3324
+ A numeric literal that is not an integer literal is a {\em double literal}.
3325
+ \commentary {A double literal always contains either a decimal point or an exponent part.}
3326
+ The static type of a double literal is \code {double}.
3327
+
3328
+ \LMHash {}
3329
+ A hexadecimal integer literal with numeric value $ i$ is a compile-time
3330
+ error if $ i \ge {} 2 ^{64}$ , unless it is prefixed by a unary minus operator,
3331
+ in which case it is a compile-time error if $ i \gt {} 2 ^{63}$ .
3332
+ If the \code {int} class is implemented as signed 64-bit two's complement integers,
3333
+ $ i \ge {} 2 ^63 $ , and the literal is not prefixed by a unary minus operator, then
3334
+ the literal evaluates to an instance of the \code {int} class representing the integer value $ i - 2 ^64 $ .
3335
+ Otherwise the literal evaluates to an instance of the \code {int} class representing
3336
+ the integer value $ i$ ,
3337
+ and it is a compile-time error if the integer $ i$ cannot be represented exactly
3338
+ by an instance of \code {int}.
3339
+
3340
+ \LMHash {}
3341
+ A decimal integer literal with numeric value $ i$ is a compile-time error
3342
+ if $ i \ge {} 2 ^{63}$ , unless $ i$ is prefixed by a unary minus operator,
3343
+ in which case it is only a compile-time error if $ i \gt {} 2 ^{63}$ .
3344
+ Otherwise the literal evaluates to an instance of the \code {int} class representing
3345
+ the integer value $ i$ .
3346
+ It is a compile-time error if the value $ i$ cannot be represented exactly
3347
+ by an instance of \code {int}.
3348
+
3349
+ \LMHash {}
3350
+ A double literal evaluates to a an instance of the \code {double} class
3351
+ representing a 64 bit double precision floating point number
3352
+ as specified by the IEEE 754 standard.
3323
3353
3324
3354
\commentary {
3325
- For example, implementations may choose to limit the range to facilitate efficient compilation to Javascript.
3326
- These limitations should be relaxed as soon as technologically feasible.
3355
+ Integers in Dart are designed to be implemented as
3356
+ 64-bit two's complement integer representations.
3357
+ In practice, implementations may be limited by other considerations.
3358
+ For example, Dart compiled to JavaScript may use the JavaScript number type,
3359
+ equivalent to Dart \code {double}, to represent integers, and if so,
3360
+ integer literals with more than 53 bits of precision cannot be represented
3361
+ exactly.
3327
3362
}
3328
3363
3329
3364
\LMHash {}
3330
3365
It is a compile-time error for a class to extend, mix in or implement \code {int}.
3331
3366
It is a compile-time error for a class to extend, mix in or implement \code {double}.
3332
3367
It is a compile-time error for any class other than \code {int} and \code {double} to extend, mix in or implement \code {num}.
3333
3368
3334
- \LMHash {}
3335
- An {\em integer literal} is either a hexadecimal integer literal or a decimal integer literal.
3336
- The static type of an integer literal is \code {int}.
3337
-
3338
- \LMHash {}
3339
- A {\em literal double} is a numeric literal that is not an integer literal.
3340
- The static type of a literal double is \code {double}.
3341
-
3342
3369
3343
3370
\subsection {Booleans }
3344
3371
\LMLabel {booleans}
@@ -6544,7 +6571,20 @@ \subsection{Unary Expressions}
6544
6571
% The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPER{}.-()}.
6545
6572
6546
6573
\LMHash {}
6547
- An expression of the form \code {$ op$ $ e$ } is equivalent to the method invocation \code {$ e.op()$ }.
6574
+ If $ e$ is an expression is of the form \code {-$ l$ }
6575
+ where $ l$ is an integer literal (\ref {numbers }) with numerical integer value $ i$ ,
6576
+ then it is a compile-time error if $ i \gt {} 2 ^{63}$ .
6577
+ Otherwise, when $ 0 \le {} i \le {} 2 ^{63}$ , the static type of $ e$ is \code {int}
6578
+ and $ e$ evaluates to an instance of the class \code {int}
6579
+ representing the integer value $ -i$ ,
6580
+ and it is a compile-time error if the integer $ -i$ cannot be represented exactly
6581
+ by an instance of \code {int}.
6582
+ \rationale {This treats \code {-$ l$ } where $ l$ is an integer literal as an atomic signed numeral.
6583
+ It does not {\em evaluate} $ l$ as an individual expression because \code {-9223372036854775808}
6584
+ should represent a valid \code {int} even if \code {9223372036854775808} does not.}
6585
+
6586
+ \LMHash {}
6587
+ Any other expression of the form \code {$ op$ $ e$ } is equivalent to the method invocation \code {$ e.op()$ }.
6548
6588
An expression of the form \code {$ op$ \SUPER {}} is equivalent to the method invocation (\ref {superInvocation }) \code {\SUPER {}.$ op()$ }.
6549
6589
6550
6590
0 commit comments