Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 1 | // 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 Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 5 | // Integer literals that lose precision when represented as a JavaScript double |
| 6 | // are compile errors in the web compilers. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 7 | |
| 8 | main() { |
| 9 | check(0x8000000000000000); |
| 10 | |
| 11 | check(0x7FFF00001111F000); |
| 12 | check(0x7FFF00001111FC00); |
| 13 | check(0x7FFF00001111FE00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 14 | // ^ |
| 15 | // [web] The integer literal 0x7FFF00001111FE00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 16 | check(0x7FFF00001111FF00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 17 | // ^ |
| 18 | // [web] The integer literal 0x7FFF00001111FF00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 19 | check(0x7FFF00001111FFFF); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 20 | // ^ |
| 21 | // [web] The integer literal 0x7FFF00001111FFFF can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 22 | |
| 23 | check(0xFFFF00001111F000); |
| 24 | check(0xFFFF00001111F800); |
| 25 | check(0xFFFF00001111FC00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 26 | // ^ |
| 27 | // [web] The integer literal 0xFFFF00001111FC00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 28 | check(0xFFFF00001111FE00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 29 | // ^ |
| 30 | // [web] The integer literal 0xFFFF00001111FE00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 31 | check(0xFFFF00001111FF00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 32 | // ^ |
| 33 | // [web] The integer literal 0xFFFF00001111FF00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 34 | check(0xFFFF00001111FFFF); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 35 | // ^ |
| 36 | // [web] The integer literal 0xFFFF00001111FFFF can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 37 | |
| 38 | // Test all runs of 53 and 54 bits. |
| 39 | check(0x000FFFFFFFFFFFFF); |
| 40 | check(0x001FFFFFFFFFFFFF); |
| 41 | check(0x003FFFFFFFFFFFFF); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 42 | // ^ |
| 43 | // [web] The integer literal 0x003FFFFFFFFFFFFF can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 44 | check(0x003FFFFFFFFFFFFE); |
| 45 | check(0x007FFFFFFFFFFFFE); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 46 | // ^ |
| 47 | // [web] The integer literal 0x007FFFFFFFFFFFFE can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 48 | check(0x007FFFFFFFFFFFFC); |
| 49 | check(0x00FFFFFFFFFFFFFC); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 50 | // ^ |
| 51 | // [web] The integer literal 0x00FFFFFFFFFFFFFC can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 52 | check(0x00FFFFFFFFFFFFF8); |
| 53 | check(0x01FFFFFFFFFFFFF8); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 54 | // ^ |
| 55 | // [web] The integer literal 0x01FFFFFFFFFFFFF8 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 56 | check(0x01FFFFFFFFFFFFF0); |
| 57 | check(0x03FFFFFFFFFFFFF0); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 58 | // ^ |
| 59 | // [web] The integer literal 0x03FFFFFFFFFFFFF0 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 60 | check(0x03FFFFFFFFFFFFE0); |
| 61 | check(0x07FFFFFFFFFFFFE0); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 62 | // ^ |
| 63 | // [web] The integer literal 0x07FFFFFFFFFFFFE0 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 64 | check(0x07FFFFFFFFFFFFC0); |
| 65 | check(0x0FFFFFFFFFFFFFC0); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 66 | // ^ |
| 67 | // [web] The integer literal 0x0FFFFFFFFFFFFFC0 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 68 | check(0x0FFFFFFFFFFFFF80); |
| 69 | check(0x1FFFFFFFFFFFFF80); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 70 | // ^ |
| 71 | // [web] The integer literal 0x1FFFFFFFFFFFFF80 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 72 | check(0x1FFFFFFFFFFFFF00); |
| 73 | check(0x3FFFFFFFFFFFFF00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 74 | // ^ |
| 75 | // [web] The integer literal 0x3FFFFFFFFFFFFF00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 76 | check(0x3FFFFFFFFFFFFE00); |
| 77 | check(0x7FFFFFFFFFFFFE00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 78 | // ^ |
| 79 | // [web] The integer literal 0x7FFFFFFFFFFFFE00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 80 | check(0x7FFFFFFFFFFFFC00); |
| 81 | check(0xFFFFFFFFFFFFFC00); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 82 | // ^ |
| 83 | // [web] The integer literal 0xFFFFFFFFFFFFFC00 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 84 | 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 Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 91 | // [web] The integer literal 9223372036854775808 can't be represented in 64 bits. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 92 | check(9223372036854775807); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 93 | // ^ |
| 94 | // [web] The integer literal 9223372036854775807 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 95 | check(9223372036854775806); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 96 | // ^ |
| 97 | // [web] The integer literal 9223372036854775806 can't be represented exactly in JavaScript. |
| 98 | |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 99 | // 9223372036854775808 - 512 is rounded. |
| 100 | check(9223372036854775296); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 101 | // ^ |
| 102 | // [web] The integer literal 9223372036854775296 can't be represented exactly in JavaScript. |
| 103 | |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 104 | // 9223372036854775808 - 1024 is exact. |
| 105 | check(9223372036854774784); |
| 106 | |
| 107 | check(-9223372036854775808); |
| 108 | check(-9223372036854775807); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 109 | // ^ |
| 110 | // [web] The integer literal 9223372036854775807 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 111 | check(-9223372036854775296); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 112 | // ^ |
| 113 | // [web] The integer literal 9223372036854775296 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 114 | check(-9223372036854774784); |
| 115 | |
| 116 | check(1000000000000000001); |
Robert Nystrom | 4bfb196 | 2023-04-25 21:28:39 +0000 | [diff] [blame] | 117 | // ^ |
| 118 | // [web] The integer literal 1000000000000000001 can't be represented exactly in JavaScript. |
Robert Nystrom | 062cd60 | 2020-06-04 23:07:53 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | check(int n) {} |