| 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) { | 103 TEST_CASE(BigintUint64) { |
| 104 const uint64_t kMax = | 104 const uint64_t kMax = |
| 105 static_cast<uint64_t>(DART_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); | 105 static_cast<uint64_t>(DART_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); |
| 106 | 106 |
| 107 const Bigint& one = Bigint::Handle(BigintOperations::NewFromUInt64(1)); | 107 const Bigint& one = Bigint::Handle(BigintOperations::NewFromUint64(1)); |
| 108 EXPECT(BigintOperations::FitsIntoInt64(one)); | 108 EXPECT(BigintOperations::FitsIntoInt64(one)); |
| 109 EXPECT(BigintOperations::FitsIntoUInt64(one)); | 109 EXPECT(BigintOperations::FitsIntoUint64(one)); |
| 110 | 110 |
| 111 Bigint& big = Bigint::Handle(BigintOperations::NewFromUInt64(kMax)); | 111 Bigint& big = Bigint::Handle(BigintOperations::NewFromUint64(kMax)); |
| 112 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 112 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 113 EXPECT(BigintOperations::FitsIntoUInt64(big)); | 113 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 114 | 114 |
| 115 uint64_t back = BigintOperations::ToUInt64(big); | 115 uint64_t back = BigintOperations::ToUint64(big); |
| 116 EXPECT_EQ(kMax, back); | 116 EXPECT_EQ(kMax, back); |
| 117 | 117 |
| 118 big = BigintOperations::Add(big, one); | 118 big = BigintOperations::Add(big, one); |
| 119 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 119 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 120 EXPECT(!BigintOperations::FitsIntoUInt64(big)); | 120 EXPECT(!BigintOperations::FitsIntoUint64(big)); |
| 121 | 121 |
| 122 big = BigintOperations::Subtract(big, one); | 122 big = BigintOperations::Subtract(big, one); |
| 123 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 123 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 124 EXPECT(BigintOperations::FitsIntoUInt64(big)); | 124 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 125 | 125 |
| 126 big = BigintOperations::ShiftRight(big, 1); | 126 big = BigintOperations::ShiftRight(big, 1); |
| 127 EXPECT(BigintOperations::FitsIntoInt64(big)); | 127 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 128 EXPECT(BigintOperations::FitsIntoUInt64(big)); | 128 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 TEST_CASE(BigintDouble) { | 132 TEST_CASE(BigintDouble) { |
| 133 Smi& smi = Smi::Handle(Smi::New(5)); | 133 Smi& smi = Smi::Handle(Smi::New(5)); |
| 134 Bigint& bigint = Bigint::Handle(BigintOperations::NewFromSmi(smi)); | 134 Bigint& bigint = Bigint::Handle(BigintOperations::NewFromSmi(smi)); |
| 135 Double& dbl = Double::Handle(BigintOperations::ToDouble(bigint)); | 135 Double& dbl = Double::Handle(BigintOperations::ToDouble(bigint)); |
| 136 EXPECT_EQ(5.0, dbl.value()); | 136 EXPECT_EQ(5.0, dbl.value()); |
| 137 | 137 |
| 138 smi = Smi::New(0); | 138 smi = Smi::New(0); |
| (...skipping 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 "123456789012345678901234567890123456789012345678901234567890123456789012" | 2130 "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 2131 "345678901234567890123456789012345678901234567890123456789012345678901234" | 2131 "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 2132 "567890123456789012345678901234567890123456789012345678901234567890123456" | 2132 "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 2133 "789012345678901234567890123456789012345678901234567890123456789012345678" | 2133 "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 2134 "90123456789012345678901234567890", | 2134 "90123456789012345678901234567890", |
| 2135 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" | 2135 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" |
| 2136 "01234567890ABCDEE"); | 2136 "01234567890ABCDEE"); |
| 2137 } | 2137 } |
| 2138 | 2138 |
| 2139 } // namespace dart | 2139 } // namespace dart |
| OLD | NEW |