| 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 #include "vm/assert.h" | 5 #include "vm/assert.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/object_store.h" | 8 #include "vm/object_store.h" |
| 9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 10 | 10 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 big = BigintOperations::NewFromInt64(kMaxValue64); | 93 big = BigintOperations::NewFromInt64(kMaxValue64); |
| 94 EXPECT(BigintOperations::FitsIntoInt64(big)); | 94 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 95 back = BigintOperations::ToInt64(big); | 95 back = BigintOperations::ToInt64(big); |
| 96 EXPECT_EQ(kMaxValue64, back); | 96 EXPECT_EQ(kMaxValue64, back); |
| 97 | 97 |
| 98 big = BigintOperations::Add(big, one); | 98 big = BigintOperations::Add(big, one); |
| 99 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 99 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 TEST_CASE(BigintUInt64) { |
| 104 const uint64_t kMax = |
| 105 static_cast<uint64_t>(DART_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); |
| 106 |
| 107 const Bigint& one = Bigint::Handle(BigintOperations::NewFromUInt64(1)); |
| 108 EXPECT(BigintOperations::FitsIntoInt64(one)); |
| 109 EXPECT(BigintOperations::FitsIntoUInt64(one)); |
| 110 |
| 111 Bigint& big = Bigint::Handle(BigintOperations::NewFromUInt64(kMax)); |
| 112 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 113 EXPECT(BigintOperations::FitsIntoUInt64(big)); |
| 114 |
| 115 uint64_t back = BigintOperations::ToUInt64(big); |
| 116 EXPECT_EQ(kMax, back); |
| 117 |
| 118 big = BigintOperations::Add(big, one); |
| 119 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 120 EXPECT(!BigintOperations::FitsIntoUInt64(big)); |
| 121 |
| 122 big = BigintOperations::Subtract(big, one); |
| 123 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 124 EXPECT(BigintOperations::FitsIntoUInt64(big)); |
| 125 |
| 126 big = BigintOperations::ShiftRight(big, 1); |
| 127 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 128 EXPECT(BigintOperations::FitsIntoUInt64(big)); |
| 129 } |
| 130 |
| 131 |
| 103 TEST_CASE(BigintDouble) { | 132 TEST_CASE(BigintDouble) { |
| 104 Smi& smi = Smi::Handle(Smi::New(5)); | 133 Smi& smi = Smi::Handle(Smi::New(5)); |
| 105 Bigint& bigint = Bigint::Handle(BigintOperations::NewFromSmi(smi)); | 134 Bigint& bigint = Bigint::Handle(BigintOperations::NewFromSmi(smi)); |
| 106 Double& dbl = Double::Handle(BigintOperations::ToDouble(bigint)); | 135 Double& dbl = Double::Handle(BigintOperations::ToDouble(bigint)); |
| 107 EXPECT_EQ(5.0, dbl.value()); | 136 EXPECT_EQ(5.0, dbl.value()); |
| 108 | 137 |
| 109 smi = Smi::New(0); | 138 smi = Smi::New(0); |
| 110 bigint = BigintOperations::NewFromSmi(smi); | 139 bigint = BigintOperations::NewFromSmi(smi); |
| 111 dbl = BigintOperations::ToDouble(bigint); | 140 dbl = BigintOperations::ToDouble(bigint); |
| 112 EXPECT_EQ(0.0, dbl.value()); | 141 EXPECT_EQ(0.0, dbl.value()); |
| (...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 "123456789012345678901234567890123456789012345678901234567890123456789012" | 2130 "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 2102 "345678901234567890123456789012345678901234567890123456789012345678901234" | 2131 "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 2103 "567890123456789012345678901234567890123456789012345678901234567890123456" | 2132 "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 2104 "789012345678901234567890123456789012345678901234567890123456789012345678" | 2133 "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 2105 "90123456789012345678901234567890", | 2134 "90123456789012345678901234567890", |
| 2106 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" | 2135 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" |
| 2107 "01234567890ABCDEE"); | 2136 "01234567890ABCDEE"); |
| 2108 } | 2137 } |
| 2109 | 2138 |
| 2110 } // namespace dart | 2139 } // namespace dart |
| OLD | NEW |