blob: ce23f5e9b790bef9f5c9aef69126c69ed2fe4ee4 [file] [log] [blame]
Robert Nystrom062cd602020-06-04 23:07:53 +00001// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
Robert Nystrom4bfb1962023-04-25 21:28:39 +00005// Integer literals that lose precision when represented as a JavaScript double
6// are compile errors in the web compilers.
Robert Nystrom062cd602020-06-04 23:07:53 +00007
8main() {
9 check(0x8000000000000000);
10
11 check(0x7FFF00001111F000);
12 check(0x7FFF00001111FC00);
13 check(0x7FFF00001111FE00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000014 // ^
15 // [web] The integer literal 0x7FFF00001111FE00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000016 check(0x7FFF00001111FF00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000017 // ^
18 // [web] The integer literal 0x7FFF00001111FF00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000019 check(0x7FFF00001111FFFF);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000020 // ^
21 // [web] The integer literal 0x7FFF00001111FFFF can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000022
23 check(0xFFFF00001111F000);
24 check(0xFFFF00001111F800);
25 check(0xFFFF00001111FC00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000026 // ^
27 // [web] The integer literal 0xFFFF00001111FC00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000028 check(0xFFFF00001111FE00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000029 // ^
30 // [web] The integer literal 0xFFFF00001111FE00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000031 check(0xFFFF00001111FF00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000032 // ^
33 // [web] The integer literal 0xFFFF00001111FF00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000034 check(0xFFFF00001111FFFF);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000035 // ^
36 // [web] The integer literal 0xFFFF00001111FFFF can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000037
38 // Test all runs of 53 and 54 bits.
39 check(0x000FFFFFFFFFFFFF);
40 check(0x001FFFFFFFFFFFFF);
41 check(0x003FFFFFFFFFFFFF);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000042 // ^
43 // [web] The integer literal 0x003FFFFFFFFFFFFF can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000044 check(0x003FFFFFFFFFFFFE);
45 check(0x007FFFFFFFFFFFFE);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000046 // ^
47 // [web] The integer literal 0x007FFFFFFFFFFFFE can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000048 check(0x007FFFFFFFFFFFFC);
49 check(0x00FFFFFFFFFFFFFC);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000050 // ^
51 // [web] The integer literal 0x00FFFFFFFFFFFFFC can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000052 check(0x00FFFFFFFFFFFFF8);
53 check(0x01FFFFFFFFFFFFF8);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000054 // ^
55 // [web] The integer literal 0x01FFFFFFFFFFFFF8 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000056 check(0x01FFFFFFFFFFFFF0);
57 check(0x03FFFFFFFFFFFFF0);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000058 // ^
59 // [web] The integer literal 0x03FFFFFFFFFFFFF0 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000060 check(0x03FFFFFFFFFFFFE0);
61 check(0x07FFFFFFFFFFFFE0);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000062 // ^
63 // [web] The integer literal 0x07FFFFFFFFFFFFE0 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000064 check(0x07FFFFFFFFFFFFC0);
65 check(0x0FFFFFFFFFFFFFC0);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000066 // ^
67 // [web] The integer literal 0x0FFFFFFFFFFFFFC0 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000068 check(0x0FFFFFFFFFFFFF80);
69 check(0x1FFFFFFFFFFFFF80);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000070 // ^
71 // [web] The integer literal 0x1FFFFFFFFFFFFF80 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000072 check(0x1FFFFFFFFFFFFF00);
73 check(0x3FFFFFFFFFFFFF00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000074 // ^
75 // [web] The integer literal 0x3FFFFFFFFFFFFF00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000076 check(0x3FFFFFFFFFFFFE00);
77 check(0x7FFFFFFFFFFFFE00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000078 // ^
79 // [web] The integer literal 0x7FFFFFFFFFFFFE00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000080 check(0x7FFFFFFFFFFFFC00);
81 check(0xFFFFFFFFFFFFFC00);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000082 // ^
83 // [web] The integer literal 0xFFFFFFFFFFFFFC00 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000084 check(0xFFFFFFFFFFFFF800);
85
86 // Too big, even on VM.
87 check(9223372036854775808);
88 // ^^^^^^^^^^^^^^^^^^^
89 // [analyzer] COMPILE_TIME_ERROR.INTEGER_LITERAL_OUT_OF_RANGE
90 // [cfe] The integer literal 9223372036854775808 can't be represented in 64 bits.
Robert Nystrom4bfb1962023-04-25 21:28:39 +000091 // [web] The integer literal 9223372036854775808 can't be represented in 64 bits.
Robert Nystrom062cd602020-06-04 23:07:53 +000092 check(9223372036854775807);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000093 // ^
94 // [web] The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +000095 check(9223372036854775806);
Robert Nystrom4bfb1962023-04-25 21:28:39 +000096 // ^
97 // [web] The integer literal 9223372036854775806 can't be represented exactly in JavaScript.
98
Robert Nystrom062cd602020-06-04 23:07:53 +000099 // 9223372036854775808 - 512 is rounded.
100 check(9223372036854775296);
Robert Nystrom4bfb1962023-04-25 21:28:39 +0000101 // ^
102 // [web] The integer literal 9223372036854775296 can't be represented exactly in JavaScript.
103
Robert Nystrom062cd602020-06-04 23:07:53 +0000104 // 9223372036854775808 - 1024 is exact.
105 check(9223372036854774784);
106
107 check(-9223372036854775808);
108 check(-9223372036854775807);
Robert Nystrom4bfb1962023-04-25 21:28:39 +0000109 // ^
110 // [web] The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +0000111 check(-9223372036854775296);
Robert Nystrom4bfb1962023-04-25 21:28:39 +0000112 // ^
113 // [web] The integer literal 9223372036854775296 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +0000114 check(-9223372036854774784);
115
116 check(1000000000000000001);
Robert Nystrom4bfb1962023-04-25 21:28:39 +0000117 // ^
118 // [web] The integer literal 1000000000000000001 can't be represented exactly in JavaScript.
Robert Nystrom062cd602020-06-04 23:07:53 +0000119}
120
121check(int n) {}