| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Testing Bigints with and without intrinsics. | 5 // Testing Bigints with and without intrinsics. |
| 6 // VMOptions= | 6 // VMOptions= |
| 7 // VMOptions=--no_intrinsify | 7 // VMOptions=--no_intrinsify |
| 8 // VMOptions=--optimization_counter_threshold=10 --no-background_compilation | 8 // VMOptions=--optimization_counter_threshold=10 --no-background_compilation |
| 9 | 9 |
| 10 library big_integer_test; | 10 library big_integer_test; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 testBigintAdd() { | 27 testBigintAdd() { |
| 28 // Bigint and Smi. | 28 // Bigint and Smi. |
| 29 var a = 12345678901234567890; | 29 var a = 12345678901234567890; |
| 30 var b = 2; | 30 var b = 2; |
| 31 Expect.equals(12345678901234567892, a + b); | 31 Expect.equals(12345678901234567892, a + b); |
| 32 Expect.equals(12345678901234567892, b + a); | 32 Expect.equals(12345678901234567892, b + a); |
| 33 // Bigint and Bigint. | 33 // Bigint and Bigint. |
| 34 a = 10000000000000000001; | 34 a = 10000000000000000001; |
| 35 Expect.equals(20000000000000000002, a + a); | 35 Expect.equals(20000000000000000002, a + a); |
| 36 // Bigint and double. | 36 // Bigint and double. |
| 37 a = 100000000000000000000.0; | |
| 38 b = 200000000000000000000; | 37 b = 200000000000000000000; |
| 39 Expect.isTrue((a + b) is double); | 38 var c = 100000000000000000000.0; |
| 40 Expect.equals(300000000000000000000.0, a + b); | 39 Expect.isTrue((c + b) is double); |
| 41 Expect.isTrue((b + a) is double); | 40 Expect.equals(300000000000000000000.0, b + c); |
| 42 Expect.equals(300000000000000000000.0, b + a); | 41 Expect.isTrue((b + c) is double); |
| 42 Expect.equals(300000000000000000000.0, c + b); |
| 43 } | 43 } |
| 44 | 44 |
| 45 testBigintSub() { | 45 testBigintSub() { |
| 46 // Bigint and Smi. | 46 // Bigint and Smi. |
| 47 var a = 12345678901234567890; | 47 var a = 12345678901234567890; |
| 48 var b = 2; | 48 var b = 2; |
| 49 Expect.equals(12345678901234567888, a - b); | 49 Expect.equals(12345678901234567888, a - b); |
| 50 Expect.equals(-12345678901234567888, b - a); | 50 Expect.equals(-12345678901234567888, b - a); |
| 51 // Bigint and Bigint. | 51 // Bigint and Bigint. |
| 52 a = 10000000000000000001; | 52 a = 10000000000000000001; |
| 53 Expect.equals(20000000000000000002, a + a); | 53 Expect.equals(20000000000000000002, a + a); |
| 54 // Bigint and double. | 54 // Bigint and double. |
| 55 a = 100000000000000000000.0; | |
| 56 b = 200000000000000000000; | 55 b = 200000000000000000000; |
| 57 Expect.isTrue((a + b) is double); | 56 var c = 100000000000000000000.0; |
| 58 Expect.equals(-100000000000000000000.0, a - b); | 57 Expect.isTrue((c + b) is double); |
| 59 Expect.isTrue((b + a) is double); | 58 Expect.equals(-100000000000000000000.0, c - b); |
| 60 Expect.equals(100000000000000000000.0, b - a); | 59 Expect.isTrue((b + c) is double); |
| 60 Expect.equals(100000000000000000000.0, b - c); |
| 61 Expect.equals(-1, 0xF00000000 - 0xF00000001); | 61 Expect.equals(-1, 0xF00000000 - 0xF00000001); |
| 62 } | 62 } |
| 63 | 63 |
| 64 testBigintMul() { | 64 testBigintMul() { |
| 65 // Bigint and Smi. | 65 // Bigint and Smi. |
| 66 var a = 12345678901234567890; | 66 var a = 12345678901234567890; |
| 67 var b = 10; | 67 var b = 10; |
| 68 Expect.equals(123456789012345678900, a * b); | 68 Expect.equals(123456789012345678900, a * b); |
| 69 Expect.equals(123456789012345678900, b * a); | 69 Expect.equals(123456789012345678900, b * a); |
| 70 // Bigint and Bigint. | 70 // Bigint and Bigint. |
| 71 a = 12345678901234567890; | 71 a = 12345678901234567890; |
| 72 b = 10000000000000000; | 72 b = 10000000000000000; |
| 73 Expect.equals(123456789012345678900000000000000000, a * b); | 73 Expect.equals(123456789012345678900000000000000000, a * b); |
| 74 // Bigint and double. | 74 // Bigint and double. |
| 75 a = 2.0; | |
| 76 b = 200000000000000000000; | 75 b = 200000000000000000000; |
| 77 Expect.isTrue((a * b) is double); | 76 var c = 2.0; |
| 78 Expect.equals(400000000000000000000.0, a * b); | 77 Expect.isTrue((c * b) is double); |
| 79 Expect.isTrue((b * a) is double); | 78 Expect.equals(400000000000000000000.0, c * b); |
| 80 Expect.equals(400000000000000000000.0, b * a); | 79 Expect.isTrue((b * c) is double); |
| 80 Expect.equals(400000000000000000000.0, b * c); |
| 81 } | 81 } |
| 82 | 82 |
| 83 testBigintTruncDiv() { | 83 testBigintTruncDiv() { |
| 84 var a = 12345678901234567890; | 84 var a = 12345678901234567890; |
| 85 var b = 10; | 85 var b = 10; |
| 86 // Bigint and Smi. | 86 // Bigint and Smi. |
| 87 Expect.equals(1234567890123456789, a ~/ b); | 87 Expect.equals(1234567890123456789, a ~/ b); |
| 88 Expect.equals(0, b ~/ a); | 88 Expect.equals(0, b ~/ a); |
| 89 Expect.equals(123456789, 123456789012345678 ~/ 1000000000); | 89 Expect.equals(123456789, 123456789012345678 ~/ 1000000000); |
| 90 // Bigint and Bigint. | 90 // Bigint and Bigint. |
| 91 a = 12345678901234567890; | 91 a = 12345678901234567890; |
| 92 b = 10000000000000000; | 92 b = 10000000000000000; |
| 93 Expect.equals(1234, a ~/ b); | 93 Expect.equals(1234, a ~/ b); |
| 94 // Bigint and double. | 94 // Bigint and double. |
| 95 a = 100000000000000000000.0; | |
| 96 b = 200000000000000000000; | 95 b = 200000000000000000000; |
| 97 Expect.equals(0, a ~/ b); | 96 var c = 100000000000000000000.0; |
| 98 Expect.equals(2, b ~/ a); | 97 Expect.equals(0, c ~/ b); |
| 98 Expect.equals(2, b ~/ c); |
| 99 } | 99 } |
| 100 | 100 |
| 101 testBigintDiv() { | 101 testBigintDiv() { |
| 102 // Bigint and Smi. | 102 // Bigint and Smi. |
| 103 Expect.equals(1234567890123456789.1, 12345678901234567891 / 10); | 103 Expect.equals(1234567890123456789.1, 12345678901234567891 / 10); |
| 104 Expect.equals(0.000000001234, 1234 / 1000000000000); | 104 Expect.equals(0.000000001234, 1234 / 1000000000000); |
| 105 Expect.equals(12345678901234000000.0, 123456789012340000000 / 10); | 105 Expect.equals(12345678901234000000.0, 123456789012340000000 / 10); |
| 106 // Bigint and Bigint. | 106 // Bigint and Bigint. |
| 107 var a = 12345670000000000000; | 107 var a = 12345670000000000000; |
| 108 var b = 10000000000000000; | 108 var b = 10000000000000000; |
| 109 Expect.equals(1234.567, a / b); | 109 Expect.equals(1234.567, a / b); |
| 110 // Bigint and double. | 110 // Bigint and double. |
| 111 a = 400000000000000000000.0; | |
| 112 b = 200000000000000000000; | 111 b = 200000000000000000000; |
| 113 Expect.equals(2.0, a / b); | 112 var c = 400000000000000000000.0; |
| 114 Expect.equals(0.5, b / a); | 113 Expect.equals(2.0, c / b); |
| 114 Expect.equals(0.5, b / c); |
| 115 } | 115 } |
| 116 | 116 |
| 117 testBigintModulo() { | 117 testBigintModulo() { |
| 118 // Bigint and Smi. | 118 // Bigint and Smi. |
| 119 var a = 1000000000005; | 119 var a = 1000000000005; |
| 120 var b = 10; | 120 var b = 10; |
| 121 Expect.equals(5, a % b); | 121 Expect.equals(5, a % b); |
| 122 Expect.equals(10, b % a); | 122 Expect.equals(10, b % a); |
| 123 // Bigint & Bigint | 123 // Bigint & Bigint |
| 124 a = 10000000000000000001; | 124 a = 10000000000000000001; |
| 125 b = 10000000000000000000; | 125 b = 10000000000000000000; |
| 126 Expect.equals(1, a % b); | 126 Expect.equals(1, a % b); |
| 127 Expect.equals(10000000000000000000, b % a); | 127 Expect.equals(10000000000000000000, b % a); |
| 128 // Bigint & double. | 128 // Bigint & double. |
| 129 a = 10000000100000000.0; | |
| 130 b = 10000000000000000; | 129 b = 10000000000000000; |
| 131 Expect.equals(100000000.0, a % b); | 130 var c = 10000000100000000.0; |
| 132 Expect.equals(10000000000000000.0, b % a); | 131 Expect.equals(100000000.0, c % b); |
| 132 Expect.equals(10000000000000000.0, b % c); |
| 133 // Transitioning from Mint to Bigint. | 133 // Transitioning from Mint to Bigint. |
| 134 var iStart = 4611686018427387900; | 134 var iStart = 4611686018427387900; |
| 135 var prevX = -23 % iStart; | 135 var prevX = -23 % iStart; |
| 136 for (int i = iStart + 1; i < iStart + 10; i++) { | 136 for (int i = iStart + 1; i < iStart + 10; i++) { |
| 137 var x = -23 % i; | 137 var x = -23 % i; |
| 138 Expect.equals(1, x - prevX); | 138 Expect.equals(1, x - prevX); |
| 139 Expect.isTrue(x > 0); | 139 Expect.isTrue(x > 0); |
| 140 prevX = x; | 140 prevX = x; |
| 141 } | 141 } |
| 142 } | 142 } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 testBigintNegate(); // //# negate: ok | 435 testBigintNegate(); // //# negate: ok |
| 436 testShiftAmount(); // //# shift: ok | 436 testShiftAmount(); // //# shift: ok |
| 437 Expect.equals(12345678901234567890, (12345678901234567890).abs()); | 437 Expect.equals(12345678901234567890, (12345678901234567890).abs()); |
| 438 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); | 438 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); |
| 439 var a = 10000000000000000000; | 439 var a = 10000000000000000000; |
| 440 var b = 10000000000000000001; | 440 var b = 10000000000000000001; |
| 441 Expect.equals(false, a.hashCode == b.hashCode); | 441 Expect.equals(false, a.hashCode == b.hashCode); |
| 442 Expect.equals(true, a.hashCode == (b - 1).hashCode); | 442 Expect.equals(true, a.hashCode == (b - 1).hashCode); |
| 443 } | 443 } |
| 444 } | 444 } |
| OLD | NEW |