| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); | 71 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); |
| 72 big = BigintOperations::NewFromInt64(kValue64); | 72 big = BigintOperations::NewFromInt64(kValue64); |
| 73 big_test = BigintOperations::Multiply(big_test, big_test); | 73 big_test = BigintOperations::Multiply(big_test, big_test); |
| 74 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); | 74 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); |
| 75 big = BigintOperations::NewFromInt64(-kValue64); | 75 big = BigintOperations::NewFromInt64(-kValue64); |
| 76 big_test = BigintOperations::Subtract( | 76 big_test = BigintOperations::Subtract( |
| 77 Bigint::Handle(BigintOperations::NewFromInt64(0)), big_test); | 77 Bigint::Handle(BigintOperations::NewFromInt64(0)), big_test); |
| 78 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); | 78 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); |
| 79 | 79 |
| 80 const Bigint& one = Bigint::Handle(BigintOperations::NewFromInt64(1)); | 80 const Bigint& one = Bigint::Handle(BigintOperations::NewFromInt64(1)); |
| 81 const int64_t kMaxValue64 = | 81 big = BigintOperations::NewFromInt64(kMinInt64); |
| 82 static_cast<int64_t>(DART_2PART_UINT64_C(0x7FFFFFFF, FFFFFFFF)); | |
| 83 const int64_t kMinValue64 = | |
| 84 static_cast<int64_t>(DART_2PART_UINT64_C(0x80000000, 00000000)); | |
| 85 big = BigintOperations::NewFromInt64(kMinValue64); | |
| 86 EXPECT(BigintOperations::FitsIntoInt64(big)); | 82 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 87 int64_t back = BigintOperations::ToInt64(big); | 83 int64_t back = BigintOperations::ToInt64(big); |
| 88 EXPECT_EQ(kMinValue64, back); | 84 EXPECT_EQ(kMinInt64, back); |
| 89 | 85 |
| 90 big = BigintOperations::Subtract(big, one); | 86 big = BigintOperations::Subtract(big, one); |
| 91 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 87 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 92 | 88 |
| 93 big = BigintOperations::NewFromInt64(kMaxValue64); | 89 big = BigintOperations::NewFromInt64(kMaxInt64); |
| 94 EXPECT(BigintOperations::FitsIntoInt64(big)); | 90 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 95 back = BigintOperations::ToInt64(big); | 91 back = BigintOperations::ToInt64(big); |
| 96 EXPECT_EQ(kMaxValue64, back); | 92 EXPECT_EQ(kMaxInt64, back); |
| 97 | 93 |
| 98 big = BigintOperations::Add(big, one); | 94 big = BigintOperations::Add(big, one); |
| 99 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 95 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 100 } | 96 } |
| 101 | 97 |
| 102 | 98 |
| 103 TEST_CASE(BigintUint64) { | 99 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)); | 100 const Bigint& one = Bigint::Handle(BigintOperations::NewFromUint64(1)); |
| 108 EXPECT(BigintOperations::FitsIntoInt64(one)); | 101 EXPECT(BigintOperations::FitsIntoInt64(one)); |
| 109 EXPECT(BigintOperations::FitsIntoUint64(one)); | 102 EXPECT(BigintOperations::FitsIntoUint64(one)); |
| 110 | 103 |
| 111 Bigint& big = Bigint::Handle(BigintOperations::NewFromUint64(kMax)); | 104 Bigint& big = Bigint::Handle(BigintOperations::NewFromUint64(kMaxUint64)); |
| 112 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 105 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 113 EXPECT(BigintOperations::FitsIntoUint64(big)); | 106 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 114 | 107 |
| 115 uint64_t back = BigintOperations::ToUint64(big); | 108 uint64_t back = BigintOperations::ToUint64(big); |
| 116 EXPECT_EQ(kMax, back); | 109 EXPECT_EQ(kMaxUint64, back); |
| 117 | 110 |
| 118 big = BigintOperations::Add(big, one); | 111 big = BigintOperations::Add(big, one); |
| 119 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 112 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 120 EXPECT(!BigintOperations::FitsIntoUint64(big)); | 113 EXPECT(!BigintOperations::FitsIntoUint64(big)); |
| 121 | 114 |
| 122 big = BigintOperations::Subtract(big, one); | 115 big = BigintOperations::Subtract(big, one); |
| 123 EXPECT(!BigintOperations::FitsIntoInt64(big)); | 116 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 124 EXPECT(BigintOperations::FitsIntoUint64(big)); | 117 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 125 | 118 |
| 126 big = BigintOperations::ShiftRight(big, 1); | 119 big = BigintOperations::ShiftRight(big, 1); |
| (...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 "123456789012345678901234567890123456789012345678901234567890123456789012" | 2123 "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 2131 "345678901234567890123456789012345678901234567890123456789012345678901234" | 2124 "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 2132 "567890123456789012345678901234567890123456789012345678901234567890123456" | 2125 "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 2133 "789012345678901234567890123456789012345678901234567890123456789012345678" | 2126 "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 2134 "90123456789012345678901234567890", | 2127 "90123456789012345678901234567890", |
| 2135 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" | 2128 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" |
| 2136 "01234567890ABCDEE"); | 2129 "01234567890ABCDEE"); |
| 2137 } | 2130 } |
| 2138 | 2131 |
| 2139 } // namespace dart | 2132 } // namespace dart |
| OLD | NEW |