12e5b6d6dSopenharmony_ci// Copyright 2010 the V8 project authors. All rights reserved.
22e5b6d6dSopenharmony_ci// Redistribution and use in source and binary forms, with or without
32e5b6d6dSopenharmony_ci// modification, are permitted provided that the following conditions are
42e5b6d6dSopenharmony_ci// met:
52e5b6d6dSopenharmony_ci//
62e5b6d6dSopenharmony_ci//     * Redistributions of source code must retain the above copyright
72e5b6d6dSopenharmony_ci//       notice, this list of conditions and the following disclaimer.
82e5b6d6dSopenharmony_ci//     * Redistributions in binary form must reproduce the above
92e5b6d6dSopenharmony_ci//       copyright notice, this list of conditions and the following
102e5b6d6dSopenharmony_ci//       disclaimer in the documentation and/or other materials provided
112e5b6d6dSopenharmony_ci//       with the distribution.
122e5b6d6dSopenharmony_ci//     * Neither the name of Google Inc. nor the names of its
132e5b6d6dSopenharmony_ci//       contributors may be used to endorse or promote products derived
142e5b6d6dSopenharmony_ci//       from this software without specific prior written permission.
152e5b6d6dSopenharmony_ci//
162e5b6d6dSopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172e5b6d6dSopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182e5b6d6dSopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192e5b6d6dSopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202e5b6d6dSopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212e5b6d6dSopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222e5b6d6dSopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232e5b6d6dSopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242e5b6d6dSopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252e5b6d6dSopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262e5b6d6dSopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272e5b6d6dSopenharmony_ci
282e5b6d6dSopenharmony_ci#include <stdlib.h>
292e5b6d6dSopenharmony_ci#include <string.h>
302e5b6d6dSopenharmony_ci
312e5b6d6dSopenharmony_ci
322e5b6d6dSopenharmony_ci#include "double-conversion/bignum.h"
332e5b6d6dSopenharmony_ci#include "cctest.h"
342e5b6d6dSopenharmony_ci#include "double-conversion/utils.h"
352e5b6d6dSopenharmony_ci
362e5b6d6dSopenharmony_ciusing namespace double_conversion;
372e5b6d6dSopenharmony_ci
382e5b6d6dSopenharmony_ci
392e5b6d6dSopenharmony_cistatic const int kBufferSize = 1024;
402e5b6d6dSopenharmony_ci
412e5b6d6dSopenharmony_cistatic void AssignHexString(Bignum* bignum, const char* str) {
422e5b6d6dSopenharmony_ci  int len = static_cast<int>(strlen(str));
432e5b6d6dSopenharmony_ci  bignum->AssignHexString(Vector<const char>(str, len));
442e5b6d6dSopenharmony_ci}
452e5b6d6dSopenharmony_ci
462e5b6d6dSopenharmony_ci
472e5b6d6dSopenharmony_cistatic void AssignDecimalString(Bignum* bignum, const char* str) {
482e5b6d6dSopenharmony_ci  int len = static_cast<int>(strlen(str));
492e5b6d6dSopenharmony_ci  bignum->AssignDecimalString(Vector<const char>(str, len));
502e5b6d6dSopenharmony_ci}
512e5b6d6dSopenharmony_ci
522e5b6d6dSopenharmony_ci
532e5b6d6dSopenharmony_ciTEST(Assign) {
542e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
552e5b6d6dSopenharmony_ci  Bignum bignum;
562e5b6d6dSopenharmony_ci  Bignum bignum2;
572e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0);
582e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
592e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
602e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xA);
612e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
622e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
632e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x20);
642e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
652e5b6d6dSopenharmony_ci  CHECK_EQ("20", buffer);
662e5b6d6dSopenharmony_ci
672e5b6d6dSopenharmony_ci
682e5b6d6dSopenharmony_ci  bignum.AssignUInt64(0);
692e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
702e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
712e5b6d6dSopenharmony_ci  bignum.AssignUInt64(0xA);
722e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
732e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
742e5b6d6dSopenharmony_ci  bignum.AssignUInt64(0x20);
752e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
762e5b6d6dSopenharmony_ci  CHECK_EQ("20", buffer);
772e5b6d6dSopenharmony_ci  bignum.AssignUInt64(0x100);
782e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
792e5b6d6dSopenharmony_ci  CHECK_EQ("100", buffer);
802e5b6d6dSopenharmony_ci
812e5b6d6dSopenharmony_ci  // The first real test, since this will not fit into one bigit.
822e5b6d6dSopenharmony_ci  bignum.AssignUInt64(0x12345678);
832e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
842e5b6d6dSopenharmony_ci  CHECK_EQ("12345678", buffer);
852e5b6d6dSopenharmony_ci
862e5b6d6dSopenharmony_ci  uint64_t big = DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF);
872e5b6d6dSopenharmony_ci  bignum.AssignUInt64(big);
882e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
892e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFFFF", buffer);
902e5b6d6dSopenharmony_ci
912e5b6d6dSopenharmony_ci  big = DOUBLE_CONVERSION_UINT64_2PART_C(0x12345678, 9ABCDEF0);
922e5b6d6dSopenharmony_ci  bignum.AssignUInt64(big);
932e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
942e5b6d6dSopenharmony_ci  CHECK_EQ("123456789ABCDEF0", buffer);
952e5b6d6dSopenharmony_ci
962e5b6d6dSopenharmony_ci  bignum2.AssignBignum(bignum);
972e5b6d6dSopenharmony_ci  CHECK(bignum2.ToHexString(buffer, kBufferSize));
982e5b6d6dSopenharmony_ci  CHECK_EQ("123456789ABCDEF0", buffer);
992e5b6d6dSopenharmony_ci
1002e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "0");
1012e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1022e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
1032e5b6d6dSopenharmony_ci
1042e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1");
1052e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1062e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
1072e5b6d6dSopenharmony_ci
1082e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234567890");
1092e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1102e5b6d6dSopenharmony_ci  CHECK_EQ("499602D2", buffer);
1112e5b6d6dSopenharmony_ci
1122e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
1132e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1142e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
1152e5b6d6dSopenharmony_ci
1162e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "123456789ABCDEF0");
1172e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1182e5b6d6dSopenharmony_ci  CHECK_EQ("123456789ABCDEF0", buffer);
1192e5b6d6dSopenharmony_ci}
1202e5b6d6dSopenharmony_ci
1212e5b6d6dSopenharmony_ci
1222e5b6d6dSopenharmony_ciTEST(ShiftLeft) {
1232e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
1242e5b6d6dSopenharmony_ci  Bignum bignum;
1252e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
1262e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
1272e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1282e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
1292e5b6d6dSopenharmony_ci
1302e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1312e5b6d6dSopenharmony_ci  bignum.ShiftLeft(1);
1322e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1332e5b6d6dSopenharmony_ci  CHECK_EQ("2", buffer);
1342e5b6d6dSopenharmony_ci
1352e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1362e5b6d6dSopenharmony_ci  bignum.ShiftLeft(4);
1372e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1382e5b6d6dSopenharmony_ci  CHECK_EQ("10", buffer);
1392e5b6d6dSopenharmony_ci
1402e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1412e5b6d6dSopenharmony_ci  bignum.ShiftLeft(32);
1422e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1432e5b6d6dSopenharmony_ci  CHECK_EQ("100000000", buffer);
1442e5b6d6dSopenharmony_ci
1452e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1462e5b6d6dSopenharmony_ci  bignum.ShiftLeft(64);
1472e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1482e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000", buffer);
1492e5b6d6dSopenharmony_ci
1502e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "123456789ABCDEF");
1512e5b6d6dSopenharmony_ci  bignum.ShiftLeft(64);
1522e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1532e5b6d6dSopenharmony_ci  CHECK_EQ("123456789ABCDEF0000000000000000", buffer);
1542e5b6d6dSopenharmony_ci  bignum.ShiftLeft(1);
1552e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1562e5b6d6dSopenharmony_ci  CHECK_EQ("2468ACF13579BDE0000000000000000", buffer);
1572e5b6d6dSopenharmony_ci}
1582e5b6d6dSopenharmony_ci
1592e5b6d6dSopenharmony_ci
1602e5b6d6dSopenharmony_ciTEST(AddUInt64) {
1612e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
1622e5b6d6dSopenharmony_ci  Bignum bignum;
1632e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
1642e5b6d6dSopenharmony_ci  bignum.AddUInt64(0xA);
1652e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1662e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
1672e5b6d6dSopenharmony_ci
1682e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1692e5b6d6dSopenharmony_ci  bignum.AddUInt64(0xA);
1702e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1712e5b6d6dSopenharmony_ci  CHECK_EQ("B", buffer);
1722e5b6d6dSopenharmony_ci
1732e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1742e5b6d6dSopenharmony_ci  bignum.AddUInt64(0x100);
1752e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1762e5b6d6dSopenharmony_ci  CHECK_EQ("101", buffer);
1772e5b6d6dSopenharmony_ci
1782e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
1792e5b6d6dSopenharmony_ci  bignum.AddUInt64(0xFFFF);
1802e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1812e5b6d6dSopenharmony_ci  CHECK_EQ("10000", buffer);
1822e5b6d6dSopenharmony_ci
1832e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
1842e5b6d6dSopenharmony_ci  bignum.AddUInt64(0x1);
1852e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1862e5b6d6dSopenharmony_ci  CHECK_EQ("10000000", buffer);
1872e5b6d6dSopenharmony_ci
1882e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000000");
1892e5b6d6dSopenharmony_ci  bignum.AddUInt64(0xFFFF);
1902e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1912e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000000000000000000000000000000000FFFF", buffer);
1922e5b6d6dSopenharmony_ci
1932e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
1942e5b6d6dSopenharmony_ci  bignum.AddUInt64(0x1);
1952e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
1962e5b6d6dSopenharmony_ci  CHECK_EQ("100000000000000000000000000000000000000000000", buffer);
1972e5b6d6dSopenharmony_ci
1982e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
1992e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
2002e5b6d6dSopenharmony_ci  bignum.AddUInt64(1);
2012e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2022e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000001", buffer);
2032e5b6d6dSopenharmony_ci
2042e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
2052e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
2062e5b6d6dSopenharmony_ci  bignum.AddUInt64(0xFFFF);
2072e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2082e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000000000000000FFFF", buffer);
2092e5b6d6dSopenharmony_ci
2102e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
2112e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xA, 00000000));
2122e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2132e5b6d6dSopenharmony_ci  CHECK_EQ("A00000000", buffer);
2142e5b6d6dSopenharmony_ci
2152e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
2162e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xA, 00000000));
2172e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2182e5b6d6dSopenharmony_ci  CHECK_EQ("A00000001", buffer);
2192e5b6d6dSopenharmony_ci
2202e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
2212e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0x100, 00000000));
2222e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2232e5b6d6dSopenharmony_ci  CHECK_EQ("10000000001", buffer);
2242e5b6d6dSopenharmony_ci
2252e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
2262e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFF, 00000000));
2272e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2282e5b6d6dSopenharmony_ci  CHECK_EQ("FFFF00000001", buffer);
2292e5b6d6dSopenharmony_ci
2302e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
2312e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0x1, 00000000));
2322e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2332e5b6d6dSopenharmony_ci  CHECK_EQ("10FFFFFFF", buffer);
2342e5b6d6dSopenharmony_ci
2352e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000000");
2362e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFF, 00000000));
2372e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2382e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000000000FFFF00000000", buffer);
2392e5b6d6dSopenharmony_ci
2402e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
2412e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0x1, 00000000));
2422e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2432e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000000000000000000000000000000FFFFFFFF", buffer);
2442e5b6d6dSopenharmony_ci
2452e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
2462e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
2472e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0x1, 00000000));
2482e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2492e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000100000000", buffer);
2502e5b6d6dSopenharmony_ci
2512e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
2522e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
2532e5b6d6dSopenharmony_ci  bignum.AddUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFF, 00000000));
2542e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2552e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000FFFF00000000", buffer);
2562e5b6d6dSopenharmony_ci}
2572e5b6d6dSopenharmony_ci
2582e5b6d6dSopenharmony_ci
2592e5b6d6dSopenharmony_ciTEST(AddBignum) {
2602e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
2612e5b6d6dSopenharmony_ci  Bignum bignum;
2622e5b6d6dSopenharmony_ci  Bignum other;
2632e5b6d6dSopenharmony_ci
2642e5b6d6dSopenharmony_ci  AssignHexString(&other, "1");
2652e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
2662e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2672e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2682e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
2692e5b6d6dSopenharmony_ci
2702e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
2712e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2722e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2732e5b6d6dSopenharmony_ci  CHECK_EQ("2", buffer);
2742e5b6d6dSopenharmony_ci
2752e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
2762e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2772e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2782e5b6d6dSopenharmony_ci  CHECK_EQ("10000000", buffer);
2792e5b6d6dSopenharmony_ci
2802e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFF");
2812e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2822e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2832e5b6d6dSopenharmony_ci  CHECK_EQ("100000000000000", buffer);
2842e5b6d6dSopenharmony_ci
2852e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000000");
2862e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2872e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2882e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000000000000000000001", buffer);
2892e5b6d6dSopenharmony_ci
2902e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
2912e5b6d6dSopenharmony_ci
2922e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
2932e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2942e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
2952e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000001", buffer);
2962e5b6d6dSopenharmony_ci
2972e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
2982e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
2992e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3002e5b6d6dSopenharmony_ci  CHECK_EQ("100000FFFFFFF", buffer);
3012e5b6d6dSopenharmony_ci
3022e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000000");
3032e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3042e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3052e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000000001000000000000", buffer);
3062e5b6d6dSopenharmony_ci
3072e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
3082e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3092e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3102e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000000000000000000000000FFFFFFFFFFFF", buffer);
3112e5b6d6dSopenharmony_ci
3122e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
3132e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
3142e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3152e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3162e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000001000000000000", buffer);
3172e5b6d6dSopenharmony_ci
3182e5b6d6dSopenharmony_ci  other.ShiftLeft(64);
3192e5b6d6dSopenharmony_ci  CHECK(other.ToHexString(buffer, kBufferSize));
3202e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000000", buffer);
3212e5b6d6dSopenharmony_ci
3222e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
3232e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3242e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
3252e5b6d6dSopenharmony_ci
3262e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3272e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3282e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000001", buffer);
3292e5b6d6dSopenharmony_ci
3302e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
3312e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3322e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3332e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000000000000000FFFFFFF", buffer);
3342e5b6d6dSopenharmony_ci
3352e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000000");
3362e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3372e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3382e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000010000000000000000000000000000", buffer);
3392e5b6d6dSopenharmony_ci
3402e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
3412e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3422e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3432e5b6d6dSopenharmony_ci  CHECK_EQ("100000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF", buffer);
3442e5b6d6dSopenharmony_ci
3452e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
3462e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
3472e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
3482e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3492e5b6d6dSopenharmony_ci  CHECK_EQ("10010000000000000000000000000", buffer);
3502e5b6d6dSopenharmony_ci}
3512e5b6d6dSopenharmony_ci
3522e5b6d6dSopenharmony_ci
3532e5b6d6dSopenharmony_ciTEST(SubtractBignum) {
3542e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
3552e5b6d6dSopenharmony_ci  Bignum bignum;
3562e5b6d6dSopenharmony_ci  Bignum other;
3572e5b6d6dSopenharmony_ci
3582e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1");
3592e5b6d6dSopenharmony_ci  AssignHexString(&other, "0");
3602e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3612e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3622e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
3632e5b6d6dSopenharmony_ci
3642e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "2");
3652e5b6d6dSopenharmony_ci  AssignHexString(&other, "0");
3662e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3672e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3682e5b6d6dSopenharmony_ci  CHECK_EQ("2", buffer);
3692e5b6d6dSopenharmony_ci
3702e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000");
3712e5b6d6dSopenharmony_ci  AssignHexString(&other, "1");
3722e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3732e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3742e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFF", buffer);
3752e5b6d6dSopenharmony_ci
3762e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "100000000000000");
3772e5b6d6dSopenharmony_ci  AssignHexString(&other, "1");
3782e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3792e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3802e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFF", buffer);
3812e5b6d6dSopenharmony_ci
3822e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000001");
3832e5b6d6dSopenharmony_ci  AssignHexString(&other, "1");
3842e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3852e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3862e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000000000000000000000", buffer);
3872e5b6d6dSopenharmony_ci
3882e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1000000000001");
3892e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
3902e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3912e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3922e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
3932e5b6d6dSopenharmony_ci
3942e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "100000FFFFFFF");
3952e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
3962e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
3972e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
3982e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFF", buffer);
3992e5b6d6dSopenharmony_ci
4002e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000001000000000000");
4012e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
4022e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4032e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4042e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000000000000000000000", buffer);
4052e5b6d6dSopenharmony_ci
4062e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1000000000000000000000000000000FFFFFFFFFFFF");
4072e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
4082e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4092e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4102e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", buffer);
4112e5b6d6dSopenharmony_ci
4122e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
4132e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
4142e5b6d6dSopenharmony_ci  // "10 0000 0000 0000 0000 0000 0000"
4152e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
4162e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4172e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4182e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFF000000000000", buffer);
4192e5b6d6dSopenharmony_ci
4202e5b6d6dSopenharmony_ci  AssignHexString(&other, "1000000000000");
4212e5b6d6dSopenharmony_ci  other.ShiftLeft(48);
4222e5b6d6dSopenharmony_ci  // other == "1000000000000000000000000"
4232e5b6d6dSopenharmony_ci
4242e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
4252e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
4262e5b6d6dSopenharmony_ci  // bignum == "10000000000000000000000000"
4272e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4282e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4292e5b6d6dSopenharmony_ci  CHECK_EQ("F000000000000000000000000", buffer);
4302e5b6d6dSopenharmony_ci
4312e5b6d6dSopenharmony_ci  other.AssignUInt16(0x1);
4322e5b6d6dSopenharmony_ci  other.ShiftLeft(35);
4332e5b6d6dSopenharmony_ci  // other == "800000000"
4342e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
4352e5b6d6dSopenharmony_ci  bignum.ShiftLeft(60);
4362e5b6d6dSopenharmony_ci  // bignum = FFFFFFF000000000000000
4372e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4382e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4392e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFEFFFFFF800000000", buffer);
4402e5b6d6dSopenharmony_ci
4412e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000000000000000000000000000000000000000");
4422e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4432e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4442e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF800000000", buffer);
4452e5b6d6dSopenharmony_ci
4462e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
4472e5b6d6dSopenharmony_ci  bignum.SubtractBignum(other);
4482e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4492e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFF", buffer);
4502e5b6d6dSopenharmony_ci}
4512e5b6d6dSopenharmony_ci
4522e5b6d6dSopenharmony_ci
4532e5b6d6dSopenharmony_ciTEST(MultiplyUInt32) {
4542e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
4552e5b6d6dSopenharmony_ci  Bignum bignum;
4562e5b6d6dSopenharmony_ci
4572e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
4582e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x25);
4592e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4602e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
4612e5b6d6dSopenharmony_ci
4622e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "2");
4632e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x5);
4642e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4652e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
4662e5b6d6dSopenharmony_ci
4672e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000");
4682e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x9);
4692e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4702e5b6d6dSopenharmony_ci  CHECK_EQ("90000000", buffer);
4712e5b6d6dSopenharmony_ci
4722e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "100000000000000");
4732e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFF);
4742e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4752e5b6d6dSopenharmony_ci  CHECK_EQ("FFFF00000000000000", buffer);
4762e5b6d6dSopenharmony_ci
4772e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "100000000000000");
4782e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFFFFFF);
4792e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4802e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFF00000000000000", buffer);
4812e5b6d6dSopenharmony_ci
4822e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1234567ABCD");
4832e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFF);
4842e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4852e5b6d6dSopenharmony_ci  CHECK_EQ("12333335552433", buffer);
4862e5b6d6dSopenharmony_ci
4872e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1234567ABCD");
4882e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFFFFF);
4892e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4902e5b6d6dSopenharmony_ci  CHECK_EQ("12345679998A985433", buffer);
4912e5b6d6dSopenharmony_ci
4922e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
4932e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x2);
4942e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
4952e5b6d6dSopenharmony_ci  CHECK_EQ("1FFFFFFFFFFFFFFFE", buffer);
4962e5b6d6dSopenharmony_ci
4972e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
4982e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x4);
4992e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5002e5b6d6dSopenharmony_ci  CHECK_EQ("3FFFFFFFFFFFFFFFC", buffer);
5012e5b6d6dSopenharmony_ci
5022e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
5032e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xF);
5042e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5052e5b6d6dSopenharmony_ci  CHECK_EQ("EFFFFFFFFFFFFFFF1", buffer);
5062e5b6d6dSopenharmony_ci
5072e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
5082e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFFFF);
5092e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5102e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFEFFFFFFFFFF000001", buffer);
5112e5b6d6dSopenharmony_ci
5122e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
5132e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
5142e5b6d6dSopenharmony_ci  // "10 0000 0000 0000 0000 0000 0000"
5152e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(2);
5162e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5172e5b6d6dSopenharmony_ci  CHECK_EQ("20000000000000000000000000", buffer);
5182e5b6d6dSopenharmony_ci
5192e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
5202e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
5212e5b6d6dSopenharmony_ci  // "10 0000 0000 0000 0000 0000 0000"
5222e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xF);
5232e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5242e5b6d6dSopenharmony_ci  CHECK_EQ("F0000000000000000000000000", buffer);
5252e5b6d6dSopenharmony_ci
5262e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xFFFF);
5272e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
5282e5b6d6dSopenharmony_ci  // "FFFF0 0000 0000 0000 0000 0000 0000"
5292e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFF);
5302e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5312e5b6d6dSopenharmony_ci  CHECK_EQ("FFFE00010000000000000000000000000", buffer);
5322e5b6d6dSopenharmony_ci
5332e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xFFFF);
5342e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
5352e5b6d6dSopenharmony_ci  // "FFFF0 0000 0000 0000 0000 0000 0000"
5362e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFFFFFF);
5372e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5382e5b6d6dSopenharmony_ci  CHECK_EQ("FFFEFFFF00010000000000000000000000000", buffer);
5392e5b6d6dSopenharmony_ci
5402e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xFFFF);
5412e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
5422e5b6d6dSopenharmony_ci  // "FFFF0 0000 0000 0000 0000 0000 0000"
5432e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0xFFFFFFFF);
5442e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5452e5b6d6dSopenharmony_ci  CHECK_EQ("FFFEFFFF00010000000000000000000000000", buffer);
5462e5b6d6dSopenharmony_ci
5472e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "15611230384529777");
5482e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(10000000);
5492e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5502e5b6d6dSopenharmony_ci  CHECK_EQ("210EDD6D4CDD2580EE80", buffer);
5512e5b6d6dSopenharmony_ci}
5522e5b6d6dSopenharmony_ci
5532e5b6d6dSopenharmony_ci
5542e5b6d6dSopenharmony_ciTEST(MultiplyUInt64) {
5552e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
5562e5b6d6dSopenharmony_ci  Bignum bignum;
5572e5b6d6dSopenharmony_ci
5582e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "0");
5592e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0x25);
5602e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5612e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
5622e5b6d6dSopenharmony_ci
5632e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "2");
5642e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0x5);
5652e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5662e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
5672e5b6d6dSopenharmony_ci
5682e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "10000000");
5692e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0x9);
5702e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5712e5b6d6dSopenharmony_ci  CHECK_EQ("90000000", buffer);
5722e5b6d6dSopenharmony_ci
5732e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "100000000000000");
5742e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0xFFFF);
5752e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5762e5b6d6dSopenharmony_ci  CHECK_EQ("FFFF00000000000000", buffer);
5772e5b6d6dSopenharmony_ci
5782e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "100000000000000");
5792e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF));
5802e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5812e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFFFF00000000000000", buffer);
5822e5b6d6dSopenharmony_ci
5832e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1234567ABCD");
5842e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0xFFF);
5852e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5862e5b6d6dSopenharmony_ci  CHECK_EQ("12333335552433", buffer);
5872e5b6d6dSopenharmony_ci
5882e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "1234567ABCD");
5892e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFF, FFFFFFFF));
5902e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5912e5b6d6dSopenharmony_ci  CHECK_EQ("1234567ABCBDCBA985433", buffer);
5922e5b6d6dSopenharmony_ci
5932e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
5942e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0x2);
5952e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
5962e5b6d6dSopenharmony_ci  CHECK_EQ("1FFFFFFFFFFFFFFFE", buffer);
5972e5b6d6dSopenharmony_ci
5982e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
5992e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0x4);
6002e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6012e5b6d6dSopenharmony_ci  CHECK_EQ("3FFFFFFFFFFFFFFFC", buffer);
6022e5b6d6dSopenharmony_ci
6032e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
6042e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0xF);
6052e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6062e5b6d6dSopenharmony_ci  CHECK_EQ("EFFFFFFFFFFFFFFF1", buffer);
6072e5b6d6dSopenharmony_ci
6082e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFFFF");
6092e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF));
6102e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6112e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFFFE0000000000000001", buffer);
6122e5b6d6dSopenharmony_ci
6132e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
6142e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
6152e5b6d6dSopenharmony_ci  // "10 0000 0000 0000 0000 0000 0000"
6162e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(2);
6172e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6182e5b6d6dSopenharmony_ci  CHECK_EQ("20000000000000000000000000", buffer);
6192e5b6d6dSopenharmony_ci
6202e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0x1);
6212e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
6222e5b6d6dSopenharmony_ci  // "10 0000 0000 0000 0000 0000 0000"
6232e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0xF);
6242e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6252e5b6d6dSopenharmony_ci  CHECK_EQ("F0000000000000000000000000", buffer);
6262e5b6d6dSopenharmony_ci
6272e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xFFFF);
6282e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
6292e5b6d6dSopenharmony_ci  // "FFFF0 0000 0000 0000 0000 0000 0000"
6302e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0xFFFF);
6312e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6322e5b6d6dSopenharmony_ci  CHECK_EQ("FFFE00010000000000000000000000000", buffer);
6332e5b6d6dSopenharmony_ci
6342e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xFFFF);
6352e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
6362e5b6d6dSopenharmony_ci  // "FFFF0 0000 0000 0000 0000 0000 0000"
6372e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(0xFFFFFFFF);
6382e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6392e5b6d6dSopenharmony_ci  CHECK_EQ("FFFEFFFF00010000000000000000000000000", buffer);
6402e5b6d6dSopenharmony_ci
6412e5b6d6dSopenharmony_ci  bignum.AssignUInt16(0xFFFF);
6422e5b6d6dSopenharmony_ci  bignum.ShiftLeft(100);
6432e5b6d6dSopenharmony_ci  // "FFFF0 0000 0000 0000 0000 0000 0000"
6442e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF));
6452e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6462e5b6d6dSopenharmony_ci  CHECK_EQ("FFFEFFFFFFFFFFFF00010000000000000000000000000", buffer);
6472e5b6d6dSopenharmony_ci
6482e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "15611230384529777");
6492e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt64(DOUBLE_CONVERSION_UINT64_2PART_C(0x8ac72304, 89e80000));
6502e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6512e5b6d6dSopenharmony_ci  CHECK_EQ("1E10EE4B11D15A7F3DE7F3C7680000", buffer);
6522e5b6d6dSopenharmony_ci}
6532e5b6d6dSopenharmony_ci
6542e5b6d6dSopenharmony_ci
6552e5b6d6dSopenharmony_ciTEST(MultiplyPowerOfTen) {
6562e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
6572e5b6d6dSopenharmony_ci  Bignum bignum;
6582e5b6d6dSopenharmony_ci
6592e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6602e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(1);
6612e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6622e5b6d6dSopenharmony_ci  CHECK_EQ("3034", buffer);
6632e5b6d6dSopenharmony_ci
6642e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6652e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(2);
6662e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6672e5b6d6dSopenharmony_ci  CHECK_EQ("1E208", buffer);
6682e5b6d6dSopenharmony_ci
6692e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6702e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(3);
6712e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6722e5b6d6dSopenharmony_ci  CHECK_EQ("12D450", buffer);
6732e5b6d6dSopenharmony_ci
6742e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6752e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(4);
6762e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6772e5b6d6dSopenharmony_ci  CHECK_EQ("BC4B20", buffer);
6782e5b6d6dSopenharmony_ci
6792e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6802e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(5);
6812e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6822e5b6d6dSopenharmony_ci  CHECK_EQ("75AEF40", buffer);
6832e5b6d6dSopenharmony_ci
6842e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6852e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(6);
6862e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6872e5b6d6dSopenharmony_ci  CHECK_EQ("498D5880", buffer);
6882e5b6d6dSopenharmony_ci
6892e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6902e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(7);
6912e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6922e5b6d6dSopenharmony_ci  CHECK_EQ("2DF857500", buffer);
6932e5b6d6dSopenharmony_ci
6942e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
6952e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(8);
6962e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
6972e5b6d6dSopenharmony_ci  CHECK_EQ("1CBB369200", buffer);
6982e5b6d6dSopenharmony_ci
6992e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7002e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(9);
7012e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7022e5b6d6dSopenharmony_ci  CHECK_EQ("11F5021B400", buffer);
7032e5b6d6dSopenharmony_ci
7042e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7052e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(10);
7062e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7072e5b6d6dSopenharmony_ci  CHECK_EQ("B3921510800", buffer);
7082e5b6d6dSopenharmony_ci
7092e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7102e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(11);
7112e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7122e5b6d6dSopenharmony_ci  CHECK_EQ("703B4D2A5000", buffer);
7132e5b6d6dSopenharmony_ci
7142e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7152e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(12);
7162e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7172e5b6d6dSopenharmony_ci  CHECK_EQ("4625103A72000", buffer);
7182e5b6d6dSopenharmony_ci
7192e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7202e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(13);
7212e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7222e5b6d6dSopenharmony_ci  CHECK_EQ("2BD72A24874000", buffer);
7232e5b6d6dSopenharmony_ci
7242e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7252e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(14);
7262e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7272e5b6d6dSopenharmony_ci  CHECK_EQ("1B667A56D488000", buffer);
7282e5b6d6dSopenharmony_ci
7292e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7302e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(15);
7312e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7322e5b6d6dSopenharmony_ci  CHECK_EQ("11200C7644D50000", buffer);
7332e5b6d6dSopenharmony_ci
7342e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7352e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(16);
7362e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7372e5b6d6dSopenharmony_ci  CHECK_EQ("AB407C9EB0520000", buffer);
7382e5b6d6dSopenharmony_ci
7392e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7402e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(17);
7412e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7422e5b6d6dSopenharmony_ci  CHECK_EQ("6B084DE32E3340000", buffer);
7432e5b6d6dSopenharmony_ci
7442e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7452e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(18);
7462e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7472e5b6d6dSopenharmony_ci  CHECK_EQ("42E530ADFCE0080000", buffer);
7482e5b6d6dSopenharmony_ci
7492e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7502e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(19);
7512e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7522e5b6d6dSopenharmony_ci  CHECK_EQ("29CF3E6CBE0C0500000", buffer);
7532e5b6d6dSopenharmony_ci
7542e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7552e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(20);
7562e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7572e5b6d6dSopenharmony_ci  CHECK_EQ("1A218703F6C783200000", buffer);
7582e5b6d6dSopenharmony_ci
7592e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7602e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(21);
7612e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7622e5b6d6dSopenharmony_ci  CHECK_EQ("1054F4627A3CB1F400000", buffer);
7632e5b6d6dSopenharmony_ci
7642e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7652e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(22);
7662e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7672e5b6d6dSopenharmony_ci  CHECK_EQ("A3518BD8C65EF38800000", buffer);
7682e5b6d6dSopenharmony_ci
7692e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7702e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(23);
7712e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7722e5b6d6dSopenharmony_ci  CHECK_EQ("6612F7677BFB5835000000", buffer);
7732e5b6d6dSopenharmony_ci
7742e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7752e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(24);
7762e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7772e5b6d6dSopenharmony_ci  CHECK_EQ("3FCBDAA0AD7D17212000000", buffer);
7782e5b6d6dSopenharmony_ci
7792e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7802e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(25);
7812e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7822e5b6d6dSopenharmony_ci  CHECK_EQ("27DF68A46C6E2E74B4000000", buffer);
7832e5b6d6dSopenharmony_ci
7842e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7852e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(26);
7862e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7872e5b6d6dSopenharmony_ci  CHECK_EQ("18EBA166C3C4DD08F08000000", buffer);
7882e5b6d6dSopenharmony_ci
7892e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7902e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(27);
7912e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7922e5b6d6dSopenharmony_ci  CHECK_EQ("F9344E03A5B0A259650000000", buffer);
7932e5b6d6dSopenharmony_ci
7942e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
7952e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(28);
7962e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
7972e5b6d6dSopenharmony_ci  CHECK_EQ("9BC0B0C2478E6577DF20000000", buffer);
7982e5b6d6dSopenharmony_ci
7992e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8002e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(29);
8012e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8022e5b6d6dSopenharmony_ci  CHECK_EQ("61586E796CB8FF6AEB740000000", buffer);
8032e5b6d6dSopenharmony_ci
8042e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8052e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(30);
8062e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8072e5b6d6dSopenharmony_ci  CHECK_EQ("3CD7450BE3F39FA2D32880000000", buffer);
8082e5b6d6dSopenharmony_ci
8092e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8102e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(31);
8112e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8122e5b6d6dSopenharmony_ci  CHECK_EQ("26068B276E7843C5C3F9500000000", buffer);
8132e5b6d6dSopenharmony_ci
8142e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8152e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(50);
8162e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8172e5b6d6dSopenharmony_ci  CHECK_EQ("149D1B4CFED03B23AB5F4E1196EF45C08000000000000", buffer);
8182e5b6d6dSopenharmony_ci
8192e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8202e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(100);
8212e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8222e5b6d6dSopenharmony_ci  CHECK_EQ("5827249F27165024FBC47DFCA9359BF316332D1B91ACEECF471FBAB06D9B2"
8232e5b6d6dSopenharmony_ci           "0000000000000000000000000", buffer);
8242e5b6d6dSopenharmony_ci
8252e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8262e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(200);
8272e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8282e5b6d6dSopenharmony_ci  CHECK_EQ("64C1F5C06C3816AFBF8DAFD5A3D756365BB0FD020E6F084E759C1F7C99E4F"
8292e5b6d6dSopenharmony_ci           "55B9ACC667CEC477EB958C2AEEB3C6C19BA35A1AD30B35C51EB72040920000"
8302e5b6d6dSopenharmony_ci           "0000000000000000000000000000000000000000000000", buffer);
8312e5b6d6dSopenharmony_ci
8322e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8332e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(500);
8342e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8352e5b6d6dSopenharmony_ci  CHECK_EQ("96741A625EB5D7C91039FEB5C5ACD6D9831EDA5B083D800E6019442C8C8223"
8362e5b6d6dSopenharmony_ci           "3EAFB3501FE2058062221E15121334928880827DEE1EC337A8B26489F3A40A"
8372e5b6d6dSopenharmony_ci           "CB440A2423734472D10BFCE886F41B3AF9F9503013D86D088929CA86EEB4D8"
8382e5b6d6dSopenharmony_ci           "B9C831D0BD53327B994A0326227CFD0ECBF2EB48B02387AAE2D4CCCDF1F1A1"
8392e5b6d6dSopenharmony_ci           "B8CC4F1FA2C56AD40D0E4DAA9C28CDBF0A549098EA13200000000000000000"
8402e5b6d6dSopenharmony_ci           "00000000000000000000000000000000000000000000000000000000000000"
8412e5b6d6dSopenharmony_ci           "0000000000000000000000000000000000000000000000", buffer);
8422e5b6d6dSopenharmony_ci
8432e5b6d6dSopenharmony_ci  AssignDecimalString(&bignum, "1234");
8442e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(1000);
8452e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8462e5b6d6dSopenharmony_ci  CHECK_EQ("1258040F99B1CD1CC9819C676D413EA50E4A6A8F114BB0C65418C62D399B81"
8472e5b6d6dSopenharmony_ci           "6361466CA8E095193E1EE97173553597C96673AF67FAFE27A66E7EF2E5EF2E"
8482e5b6d6dSopenharmony_ci           "E3F5F5070CC17FE83BA53D40A66A666A02F9E00B0E11328D2224B8694C7372"
8492e5b6d6dSopenharmony_ci           "F3D536A0AD1985911BD361496F268E8B23112500EAF9B88A9BC67B2AB04D38"
8502e5b6d6dSopenharmony_ci           "7FEFACD00F5AF4F764F9ABC3ABCDE54612DE38CD90CB6647CA389EA0E86B16"
8512e5b6d6dSopenharmony_ci           "BF7A1F34086E05ADBE00BD1673BE00FAC4B34AF1091E8AD50BA675E0381440"
8522e5b6d6dSopenharmony_ci           "EA8E9D93E75D816BAB37C9844B1441C38FC65CF30ABB71B36433AF26DD97BD"
8532e5b6d6dSopenharmony_ci           "ABBA96C03B4919B8F3515B92826B85462833380DC193D79F69D20DD6038C99"
8542e5b6d6dSopenharmony_ci           "6114EF6C446F0BA28CC772ACBA58B81C04F8FFDE7B18C4E5A3ABC51E637FDF"
8552e5b6d6dSopenharmony_ci           "6E37FDFF04C940919390F4FF92000000000000000000000000000000000000"
8562e5b6d6dSopenharmony_ci           "00000000000000000000000000000000000000000000000000000000000000"
8572e5b6d6dSopenharmony_ci           "00000000000000000000000000000000000000000000000000000000000000"
8582e5b6d6dSopenharmony_ci           "00000000000000000000000000000000000000000000000000000000000000"
8592e5b6d6dSopenharmony_ci           "0000000000000000000000000000", buffer);
8602e5b6d6dSopenharmony_ci
8612e5b6d6dSopenharmony_ci  Bignum bignum2;
8622e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "3DA774C07FB5DF54284D09C675A492165B830D5DAAEB2A7501"
8632e5b6d6dSopenharmony_ci                            "DA17CF9DFA1CA2282269F92A25A97314296B717E3DCBB9FE17"
8642e5b6d6dSopenharmony_ci                            "41A842FE2913F540F40796F2381155763502C58B15AF7A7F88"
8652e5b6d6dSopenharmony_ci                            "6F744C9164FF409A28F7FA0C41F89ED79C1BE9F322C8578B97"
8662e5b6d6dSopenharmony_ci                            "841F1CBAA17D901BE1230E3C00E1C643AF32638B5674E01FEA"
8672e5b6d6dSopenharmony_ci                            "96FC90864E621B856A9E1CE56E6EB545B9C2F8F0CC10DDA88D"
8682e5b6d6dSopenharmony_ci                            "CC6D282605F8DB67044F2DFD3695E7BA63877AE16701536AE6"
8692e5b6d6dSopenharmony_ci                            "567C794D0BFE338DFBB42D92D4215AF3BB22BF0A8B283FDDC2"
8702e5b6d6dSopenharmony_ci                            "C667A10958EA6D2");
8712e5b6d6dSopenharmony_ci  CHECK(bignum2.ToHexString(buffer, kBufferSize));
8722e5b6d6dSopenharmony_ci  CHECK_EQ("3DA774C07FB5DF54284D09C675A492165B830D5DAAEB2A7501"
8732e5b6d6dSopenharmony_ci           "DA17CF9DFA1CA2282269F92A25A97314296B717E3DCBB9FE17"
8742e5b6d6dSopenharmony_ci           "41A842FE2913F540F40796F2381155763502C58B15AF7A7F88"
8752e5b6d6dSopenharmony_ci           "6F744C9164FF409A28F7FA0C41F89ED79C1BE9F322C8578B97"
8762e5b6d6dSopenharmony_ci           "841F1CBAA17D901BE1230E3C00E1C643AF32638B5674E01FEA"
8772e5b6d6dSopenharmony_ci           "96FC90864E621B856A9E1CE56E6EB545B9C2F8F0CC10DDA88D"
8782e5b6d6dSopenharmony_ci           "CC6D282605F8DB67044F2DFD3695E7BA63877AE16701536AE6"
8792e5b6d6dSopenharmony_ci           "567C794D0BFE338DFBB42D92D4215AF3BB22BF0A8B283FDDC2"
8802e5b6d6dSopenharmony_ci           "C667A10958EA6D2", buffer);
8812e5b6d6dSopenharmony_ci
8822e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
8832e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(1);
8842e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8852e5b6d6dSopenharmony_ci  CHECK_EQ("2688A8F84FD1AB949930261C0986DB4DF931E85A8AD2FA8921284EE1C2BC51"
8862e5b6d6dSopenharmony_ci           "E55915823BBA5789E7EC99E326EEE69F543ECE890929DED9AC79489884BE57"
8872e5b6d6dSopenharmony_ci           "630AD569E121BB76ED8DAC8FB545A8AFDADF1F8860599AFC47A93B6346C191"
8882e5b6d6dSopenharmony_ci           "7237F5BD36B73EB29371F4A4EE7A116CB5E8E5808D1BEA4D7F7E3716090C13"
8892e5b6d6dSopenharmony_ci           "F29E5DDA53F0FD513362A2D20F6505314B9419DB967F8A8A89589FC43917C3"
8902e5b6d6dSopenharmony_ci           "BB892062B17CBE421DB0D47E34ACCCE060D422CFF60DCBD0277EE038BD509C"
8912e5b6d6dSopenharmony_ci           "7BC494D8D854F5B76696F927EA99BC00C4A5D7928434", buffer);
8922e5b6d6dSopenharmony_ci
8932e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
8942e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(2);
8952e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
8962e5b6d6dSopenharmony_ci  CHECK_EQ("1815699B31E30B3CDFBE17D185F44910BBBF313896C3DC95B4B9314D19B5B32"
8972e5b6d6dSopenharmony_ci           "F57AD71655476B630F3E02DF855502394A74115A5BA2B480BCBCD5F52F6F69D"
8982e5b6d6dSopenharmony_ci           "E6C5622CB5152A54788BD9D14B896DE8CB73B53C3800DDACC9C51E0C38FAE76"
8992e5b6d6dSopenharmony_ci           "2F9964232872F9C2738E7150C4AE3F1B18F70583172706FAEE26DC5A78C77A2"
9002e5b6d6dSopenharmony_ci           "FAA874769E52C01DA5C3499F233ECF3C90293E0FB69695D763DAA3AEDA5535B"
9012e5b6d6dSopenharmony_ci           "43DAEEDF6E9528E84CEE0EC000C3C8495C1F9C89F6218AF4C23765261CD5ADD"
9022e5b6d6dSopenharmony_ci           "0787351992A01E5BB8F2A015807AE7A6BB92A08", buffer);
9032e5b6d6dSopenharmony_ci
9042e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
9052e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(5);
9062e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9072e5b6d6dSopenharmony_ci  CHECK_EQ("5E13A4863ADEE3E5C9FE8D0A73423D695D62D8450CED15A8C9F368952C6DC3"
9082e5b6d6dSopenharmony_ci           "F0EE7D82F3D1EFB7AF38A3B3920D410AFCAD563C8F5F39116E141A3C5C14B3"
9092e5b6d6dSopenharmony_ci           "58CD73077EA35AAD59F6E24AD98F10D5555ABBFBF33AC361EAF429FD5FBE94"
9102e5b6d6dSopenharmony_ci           "17DA9EF2F2956011F9F93646AA38048A681D984ED88127073443247CCC167C"
9112e5b6d6dSopenharmony_ci           "B354A32206EF5A733E73CF82D795A1AD598493211A6D613C39515E0E0F6304"
9122e5b6d6dSopenharmony_ci           "DCD9C810F3518C7F6A7CB6C81E99E02FCC65E8FDB7B7AE97306CC16A8631CE"
9132e5b6d6dSopenharmony_ci           "0A2AEF6568276BE4C176964A73C153FDE018E34CB4C2F40", buffer);
9142e5b6d6dSopenharmony_ci
9152e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
9162e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(10);
9172e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9182e5b6d6dSopenharmony_ci  CHECK_EQ("8F8CB8EB51945A7E815809F6121EF2F4E61EF3405CD9432CAD2709749EEAFD"
9192e5b6d6dSopenharmony_ci           "1B81E843F14A3667A7BDCCC9E0BB795F63CDFDB62844AC7438976C885A0116"
9202e5b6d6dSopenharmony_ci           "29607DA54F9C023CC366570B7637ED0F855D931752038A614922D0923E382C"
9212e5b6d6dSopenharmony_ci           "B8E5F6C975672DB76E0DE471937BB9EDB11E28874F1C122D5E1EF38CECE9D0"
9222e5b6d6dSopenharmony_ci           "0723056BCBD4F964192B76830634B1D322B7EB0062F3267E84F5C824343A77"
9232e5b6d6dSopenharmony_ci           "4B7DCEE6DD464F01EBDC8C671BB18BB4EF4300A42474A6C77243F2A12B03BF"
9242e5b6d6dSopenharmony_ci           "0443C38A1C0D2701EDB393135AE0DEC94211F9D4EB51F990800", buffer);
9252e5b6d6dSopenharmony_ci
9262e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
9272e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(50);
9282e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9292e5b6d6dSopenharmony_ci  CHECK_EQ("107A8BE345E24407372FC1DE442CBA696BC23C4FFD5B4BDFD9E5C39559815"
9302e5b6d6dSopenharmony_ci           "86628CF8472D2D589F2FC2BAD6E0816EC72CBF85CCA663D8A1EC6C51076D8"
9312e5b6d6dSopenharmony_ci           "2D247E6C26811B7EC4D4300FB1F91028DCB7B2C4E7A60C151161AA7E65E79"
9322e5b6d6dSopenharmony_ci           "B40917B12B2B5FBE7745984D4E8EFA31F9AE6062427B068B144A9CB155873"
9332e5b6d6dSopenharmony_ci           "E7C0C9F0115E5AC72DC5A73C4796DB970BF9205AB8C77A6996EB1B417F9D1"
9342e5b6d6dSopenharmony_ci           "6232431E6313C392203601B9C22CC10DDA88DCC6D282605F8DB67044F2DFD"
9352e5b6d6dSopenharmony_ci           "3695E7BA63877AE16701536AE6567C794D0BFE338DFBB42D924CF964BD2C0"
9362e5b6d6dSopenharmony_ci           "F586E03A2FCD35A408000000000000", buffer);
9372e5b6d6dSopenharmony_ci
9382e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
9392e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(100);
9402e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9412e5b6d6dSopenharmony_ci  CHECK_EQ("46784A90ACD0ED3E7759CC585FB32D36EB6034A6F78D92604E3BAA5ED3D8B"
9422e5b6d6dSopenharmony_ci           "6E60E854439BE448897FB4B7EA5A3D873AA0FCB3CFFD80D0530880E45F511"
9432e5b6d6dSopenharmony_ci           "722A50CE7E058B5A6F5464DB7500E34984EE3202A9441F44FA1554C0CEA96"
9442e5b6d6dSopenharmony_ci           "B438A36F25E7C9D56D71AE2CD313EC37534DA299AC0854FC48591A7CF3171"
9452e5b6d6dSopenharmony_ci           "31265AA4AE62DE32344CE7BEEEF894AE686A2DAAFE5D6D9A10971FFD9C064"
9462e5b6d6dSopenharmony_ci           "5079B209E1048F58B5192D41D84336AC4C8C489EEF00939CFC9D55C122036"
9472e5b6d6dSopenharmony_ci           "01B9C22CC10DDA88DCC6D282605F8DB67044F2DFD3695E7BA3F67B96D3A32"
9482e5b6d6dSopenharmony_ci           "E11FB5561B68744C4035B0800DC166D49D98E3FD1D5BB2000000000000000"
9492e5b6d6dSopenharmony_ci           "0000000000", buffer);
9502e5b6d6dSopenharmony_ci
9512e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
9522e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(200);
9532e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9542e5b6d6dSopenharmony_ci  CHECK_EQ("508BD351221DF139D72D88CDC0416845A53EE2D0E6B98352509A9AC312F8C"
9552e5b6d6dSopenharmony_ci           "6CB1A144889416201E0B6CE66EA3EBE259B5FD79ECFC1FD77963CE516CC7E"
9562e5b6d6dSopenharmony_ci           "2FE73D4B5B710C19F6BCB092C7A2FD76286543B8DBD2C596DFF2C896720BA"
9572e5b6d6dSopenharmony_ci           "DFF7BC9C366ACEA3A880AEC287C5E6207DF2739B5326FC19D773BD830B109"
9582e5b6d6dSopenharmony_ci           "ED36C7086544BF8FDB9D4B73719C2B5BC2F571A5937EC46876CD428281F6B"
9592e5b6d6dSopenharmony_ci           "F287E1E07F25C1B1D46BC37324FF657A8B2E0071DB83B86123CA34004F406"
9602e5b6d6dSopenharmony_ci           "001082D7945E90C6E8C9A9FEC2B44BE0DDA46E9F52B152E4D1336D2FCFBC9"
9612e5b6d6dSopenharmony_ci           "96E30CA0082256737365158FE36482AA7EB9DAF2AB128F10E7551A3CD5BE6"
9622e5b6d6dSopenharmony_ci           "0A922F3A7D5EED38B634A7EC95BCF7021BA6820A292000000000000000000"
9632e5b6d6dSopenharmony_ci           "00000000000000000000000000000000", buffer);
9642e5b6d6dSopenharmony_ci
9652e5b6d6dSopenharmony_ci  bignum.AssignBignum(bignum2);
9662e5b6d6dSopenharmony_ci  bignum.MultiplyByPowerOfTen(500);
9672e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9682e5b6d6dSopenharmony_ci  CHECK_EQ("7845F900E475B5086885BAAAE67C8E85185ACFE4633727F82A4B06B5582AC"
9692e5b6d6dSopenharmony_ci           "BE933C53357DA0C98C20C5AC900C4D76A97247DF52B79F48F9E35840FB715"
9702e5b6d6dSopenharmony_ci           "D392CE303E22622B0CF82D9471B398457DD3196F639CEE8BBD2C146873841"
9712e5b6d6dSopenharmony_ci           "F0699E6C41F04FC7A54B48CEB995BEB6F50FE81DE9D87A8D7F849CC523553"
9722e5b6d6dSopenharmony_ci           "7B7BBBC1C7CAAFF6E9650BE03B308C6D31012AEF9580F70D3EE2083ADE126"
9732e5b6d6dSopenharmony_ci           "8940FA7D6308E239775DFD2F8C97FF7EBD525DAFA6512216F7047A62A93DC"
9742e5b6d6dSopenharmony_ci           "38A0165BDC67E250DCC96A0181DE935A70B38704DC71819F02FC5261FF7E1"
9752e5b6d6dSopenharmony_ci           "E5F11907678B0A3E519FF4C10A867B0C26CE02BE6960BA8621A87303C101C"
9762e5b6d6dSopenharmony_ci           "3F88798BB9F7739655946F8B5744E6B1EAF10B0C5621330F0079209033C69"
9772e5b6d6dSopenharmony_ci           "20DE2E2C8D324F0624463735D482BF291926C22A910F5B80FA25170B6B57D"
9782e5b6d6dSopenharmony_ci           "8D5928C7BCA3FE87461275F69BD5A1B83181DAAF43E05FC3C72C4E93111B6"
9792e5b6d6dSopenharmony_ci           "6205EBF49B28FEDFB7E7526CBDA658A332000000000000000000000000000"
9802e5b6d6dSopenharmony_ci           "0000000000000000000000000000000000000000000000000000000000000"
9812e5b6d6dSopenharmony_ci           "0000000000000000000000000000000000000", buffer);
9822e5b6d6dSopenharmony_ci}
9832e5b6d6dSopenharmony_ci
9842e5b6d6dSopenharmony_ci
9852e5b6d6dSopenharmony_ciTEST(DivideModuloIntBignum) {
9862e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
9872e5b6d6dSopenharmony_ci  Bignum bignum;
9882e5b6d6dSopenharmony_ci  Bignum other;
9892e5b6d6dSopenharmony_ci  Bignum third;
9902e5b6d6dSopenharmony_ci
9912e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
9922e5b6d6dSopenharmony_ci  other.AssignUInt16(2);
9932e5b6d6dSopenharmony_ci  CHECK_EQ(5, bignum.DivideModuloIntBignum(other));
9942e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
9952e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
9962e5b6d6dSopenharmony_ci
9972e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
9982e5b6d6dSopenharmony_ci  bignum.ShiftLeft(500);
9992e5b6d6dSopenharmony_ci  other.AssignUInt16(2);
10002e5b6d6dSopenharmony_ci  other.ShiftLeft(500);
10012e5b6d6dSopenharmony_ci  CHECK_EQ(5, bignum.DivideModuloIntBignum(other));
10022e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10032e5b6d6dSopenharmony_ci  CHECK_EQ("0", buffer);
10042e5b6d6dSopenharmony_ci
10052e5b6d6dSopenharmony_ci  bignum.AssignUInt16(11);
10062e5b6d6dSopenharmony_ci  other.AssignUInt16(2);
10072e5b6d6dSopenharmony_ci  CHECK_EQ(5, bignum.DivideModuloIntBignum(other));
10082e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10092e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
10102e5b6d6dSopenharmony_ci
10112e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
10122e5b6d6dSopenharmony_ci  bignum.ShiftLeft(500);
10132e5b6d6dSopenharmony_ci  other.AssignUInt16(1);
10142e5b6d6dSopenharmony_ci  bignum.AddBignum(other);
10152e5b6d6dSopenharmony_ci  other.AssignUInt16(2);
10162e5b6d6dSopenharmony_ci  other.ShiftLeft(500);
10172e5b6d6dSopenharmony_ci  CHECK_EQ(5, bignum.DivideModuloIntBignum(other));
10182e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10192e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
10202e5b6d6dSopenharmony_ci
10212e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
10222e5b6d6dSopenharmony_ci  bignum.ShiftLeft(500);
10232e5b6d6dSopenharmony_ci  other.AssignBignum(bignum);
10242e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x1234);
10252e5b6d6dSopenharmony_ci  third.AssignUInt16(0xFFF);
10262e5b6d6dSopenharmony_ci  bignum.AddBignum(third);
10272e5b6d6dSopenharmony_ci  CHECK_EQ(0x1234, bignum.DivideModuloIntBignum(other));
10282e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10292e5b6d6dSopenharmony_ci  CHECK_EQ("FFF", buffer);
10302e5b6d6dSopenharmony_ci
10312e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
10322e5b6d6dSopenharmony_ci  AssignHexString(&other, "1234567890");
10332e5b6d6dSopenharmony_ci  CHECK_EQ(0, bignum.DivideModuloIntBignum(other));
10342e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10352e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
10362e5b6d6dSopenharmony_ci
10372e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "12345678");
10382e5b6d6dSopenharmony_ci  AssignHexString(&other, "3789012");
10392e5b6d6dSopenharmony_ci  CHECK_EQ(5, bignum.DivideModuloIntBignum(other));
10402e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10412e5b6d6dSopenharmony_ci  CHECK_EQ("D9861E", buffer);
10422e5b6d6dSopenharmony_ci
10432e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "70000001");
10442e5b6d6dSopenharmony_ci  AssignHexString(&other, "1FFFFFFF");
10452e5b6d6dSopenharmony_ci  CHECK_EQ(3, bignum.DivideModuloIntBignum(other));
10462e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10472e5b6d6dSopenharmony_ci  CHECK_EQ("10000004", buffer);
10482e5b6d6dSopenharmony_ci
10492e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "28000000");
10502e5b6d6dSopenharmony_ci  AssignHexString(&other, "12A05F20");
10512e5b6d6dSopenharmony_ci  CHECK_EQ(2, bignum.DivideModuloIntBignum(other));
10522e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10532e5b6d6dSopenharmony_ci  CHECK_EQ("2BF41C0", buffer);
10542e5b6d6dSopenharmony_ci
10552e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
10562e5b6d6dSopenharmony_ci  bignum.ShiftLeft(500);
10572e5b6d6dSopenharmony_ci  other.AssignBignum(bignum);
10582e5b6d6dSopenharmony_ci  bignum.MultiplyByUInt32(0x1234);
10592e5b6d6dSopenharmony_ci  third.AssignUInt16(0xFFF);
10602e5b6d6dSopenharmony_ci  other.SubtractBignum(third);
10612e5b6d6dSopenharmony_ci  CHECK_EQ(0x1234, bignum.DivideModuloIntBignum(other));
10622e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10632e5b6d6dSopenharmony_ci  CHECK_EQ("1232DCC", buffer);
10642e5b6d6dSopenharmony_ci  CHECK_EQ(0, bignum.DivideModuloIntBignum(other));
10652e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
10662e5b6d6dSopenharmony_ci  CHECK_EQ("1232DCC", buffer);
10672e5b6d6dSopenharmony_ci}
10682e5b6d6dSopenharmony_ci
10692e5b6d6dSopenharmony_ci
10702e5b6d6dSopenharmony_ciTEST(Compare) {
10712e5b6d6dSopenharmony_ci  Bignum bignum1;
10722e5b6d6dSopenharmony_ci  Bignum bignum2;
10732e5b6d6dSopenharmony_ci  bignum1.AssignUInt16(1);
10742e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
10752e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum1, bignum2));
10762e5b6d6dSopenharmony_ci  CHECK(Bignum::Equal(bignum1, bignum2));
10772e5b6d6dSopenharmony_ci  CHECK(Bignum::LessEqual(bignum1, bignum2));
10782e5b6d6dSopenharmony_ci  CHECK(!Bignum::Less(bignum1, bignum2));
10792e5b6d6dSopenharmony_ci
10802e5b6d6dSopenharmony_ci  bignum1.AssignUInt16(0);
10812e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
10822e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
10832e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
10842e5b6d6dSopenharmony_ci  CHECK(!Bignum::Equal(bignum1, bignum2));
10852e5b6d6dSopenharmony_ci  CHECK(!Bignum::Equal(bignum2, bignum1));
10862e5b6d6dSopenharmony_ci  CHECK(Bignum::LessEqual(bignum1, bignum2));
10872e5b6d6dSopenharmony_ci  CHECK(!Bignum::LessEqual(bignum2, bignum1));
10882e5b6d6dSopenharmony_ci  CHECK(Bignum::Less(bignum1, bignum2));
10892e5b6d6dSopenharmony_ci  CHECK(!Bignum::Less(bignum2, bignum1));
10902e5b6d6dSopenharmony_ci
10912e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "1234567890ABCDEF12345");
10922e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "1234567890ABCDEF12345");
10932e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum1, bignum2));
10942e5b6d6dSopenharmony_ci
10952e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "1234567890ABCDEF12345");
10962e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "1234567890ABCDEF12346");
10972e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
10982e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
10992e5b6d6dSopenharmony_ci
11002e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "1234567890ABCDEF12345");
11012e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(500);
11022e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "1234567890ABCDEF12345");
11032e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(500);
11042e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum1, bignum2));
11052e5b6d6dSopenharmony_ci
11062e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "1234567890ABCDEF12345");
11072e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(500);
11082e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "1234567890ABCDEF12346");
11092e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(500);
11102e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11112e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11122e5b6d6dSopenharmony_ci
11132e5b6d6dSopenharmony_ci  bignum1.AssignUInt16(1);
11142e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(64);
11152e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "10000000000000000");
11162e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum1, bignum2));
11172e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum2, bignum1));
11182e5b6d6dSopenharmony_ci
11192e5b6d6dSopenharmony_ci  bignum1.AssignUInt16(1);
11202e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(64);
11212e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "10000000000000001");
11222e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11232e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11242e5b6d6dSopenharmony_ci
11252e5b6d6dSopenharmony_ci  bignum1.AssignUInt16(1);
11262e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(96);
11272e5b6d6dSopenharmony_ci  AssignHexString(&bignum2, "10000000000000001");
11282e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(32);
11292e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11302e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11312e5b6d6dSopenharmony_ci
11322e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "FFFFFFFFFFFFFFFF");
11332e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
11342e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(64);
11352e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11362e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11372e5b6d6dSopenharmony_ci
11382e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "FFFFFFFFFFFFFFFF");
11392e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(32);
11402e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
11412e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(96);
11422e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11432e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11442e5b6d6dSopenharmony_ci
11452e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "FFFFFFFFFFFFFFFF");
11462e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(32);
11472e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
11482e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(95);
11492e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum1, bignum2));
11502e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum2, bignum1));
11512e5b6d6dSopenharmony_ci
11522e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "FFFFFFFFFFFFFFFF");
11532e5b6d6dSopenharmony_ci  bignum1.ShiftLeft(32);
11542e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
11552e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(100);
11562e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11572e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11582e5b6d6dSopenharmony_ci
11592e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "100000000000000");
11602e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
11612e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(14*4);
11622e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum1, bignum2));
11632e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::Compare(bignum2, bignum1));
11642e5b6d6dSopenharmony_ci
11652e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "100000000000001");
11662e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(1);
11672e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(14*4);
11682e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum1, bignum2));
11692e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum2, bignum1));
11702e5b6d6dSopenharmony_ci
11712e5b6d6dSopenharmony_ci  AssignHexString(&bignum1, "200000000000000");
11722e5b6d6dSopenharmony_ci  bignum2.AssignUInt16(3);
11732e5b6d6dSopenharmony_ci  bignum2.ShiftLeft(14*4);
11742e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::Compare(bignum1, bignum2));
11752e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::Compare(bignum2, bignum1));
11762e5b6d6dSopenharmony_ci}
11772e5b6d6dSopenharmony_ci
11782e5b6d6dSopenharmony_ci
11792e5b6d6dSopenharmony_ciTEST(PlusCompare) {
11802e5b6d6dSopenharmony_ci  Bignum a;
11812e5b6d6dSopenharmony_ci  Bignum b;
11822e5b6d6dSopenharmony_ci  Bignum c;
11832e5b6d6dSopenharmony_ci  a.AssignUInt16(1);
11842e5b6d6dSopenharmony_ci  b.AssignUInt16(0);
11852e5b6d6dSopenharmony_ci  c.AssignUInt16(1);
11862e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
11872e5b6d6dSopenharmony_ci  CHECK(Bignum::PlusEqual(a, b, c));
11882e5b6d6dSopenharmony_ci  CHECK(Bignum::PlusLessEqual(a, b, c));
11892e5b6d6dSopenharmony_ci  CHECK(!Bignum::PlusLess(a, b, c));
11902e5b6d6dSopenharmony_ci
11912e5b6d6dSopenharmony_ci  a.AssignUInt16(0);
11922e5b6d6dSopenharmony_ci  b.AssignUInt16(0);
11932e5b6d6dSopenharmony_ci  c.AssignUInt16(1);
11942e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
11952e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::PlusCompare(c, b, a));
11962e5b6d6dSopenharmony_ci  CHECK(!Bignum::PlusEqual(a, b, c));
11972e5b6d6dSopenharmony_ci  CHECK(!Bignum::PlusEqual(c, b, a));
11982e5b6d6dSopenharmony_ci  CHECK(Bignum::PlusLessEqual(a, b, c));
11992e5b6d6dSopenharmony_ci  CHECK(!Bignum::PlusLessEqual(c, b, a));
12002e5b6d6dSopenharmony_ci  CHECK(Bignum::PlusLess(a, b, c));
12012e5b6d6dSopenharmony_ci  CHECK(!Bignum::PlusLess(c, b, a));
12022e5b6d6dSopenharmony_ci
12032e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890ABCDEF12345");
12042e5b6d6dSopenharmony_ci  b.AssignUInt16(1);
12052e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12062e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::PlusCompare(a, b, c));
12072e5b6d6dSopenharmony_ci
12082e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890ABCDEF12344");
12092e5b6d6dSopenharmony_ci  b.AssignUInt16(1);
12102e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12112e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
12122e5b6d6dSopenharmony_ci
12132e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12142e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4);
12152e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12162e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12172e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
12182e5b6d6dSopenharmony_ci
12192e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12202e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4);
12212e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12344");
12222e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12232e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
12242e5b6d6dSopenharmony_ci
12252e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12262e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4);
12272e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12346");
12282e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12292e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
12302e5b6d6dSopenharmony_ci
12312e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567891");
12322e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4);
12332e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12342e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12352e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
12362e5b6d6dSopenharmony_ci
12372e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567889");
12382e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4);
12392e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12402e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12412e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
12422e5b6d6dSopenharmony_ci
12432e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12442e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12452e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12462e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12472e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12482e5b6d6dSopenharmony_ci  c.ShiftLeft(32);
12492e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
12502e5b6d6dSopenharmony_ci
12512e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12522e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12532e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12344");
12542e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12552e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12562e5b6d6dSopenharmony_ci  c.ShiftLeft(32);
12572e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
12582e5b6d6dSopenharmony_ci
12592e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12602e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12612e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12346");
12622e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12632e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12642e5b6d6dSopenharmony_ci  c.ShiftLeft(32);
12652e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
12662e5b6d6dSopenharmony_ci
12672e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567891");
12682e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12692e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12702e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12712e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12722e5b6d6dSopenharmony_ci  c.ShiftLeft(32);
12732e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
12742e5b6d6dSopenharmony_ci
12752e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567889");
12762e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12772e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12782e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12792e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF12345");
12802e5b6d6dSopenharmony_ci  c.ShiftLeft(32);
12812e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
12822e5b6d6dSopenharmony_ci
12832e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12842e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12852e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
12862e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12872e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF1234500000000");
12882e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
12892e5b6d6dSopenharmony_ci
12902e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12912e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12922e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12344");
12932e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
12942e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF1234500000000");
12952e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
12962e5b6d6dSopenharmony_ci
12972e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
12982e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
12992e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12346");
13002e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
13012e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF1234500000000");
13022e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
13032e5b6d6dSopenharmony_ci
13042e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567891");
13052e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13062e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
13072e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
13082e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF1234500000000");
13092e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
13102e5b6d6dSopenharmony_ci
13112e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567889");
13122e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13132e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
13142e5b6d6dSopenharmony_ci  b.ShiftLeft(32);
13152e5b6d6dSopenharmony_ci  AssignHexString(&c, "1234567890ABCDEF1234500000000");
13162e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
13172e5b6d6dSopenharmony_ci
13182e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13192e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13202e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
13212e5b6d6dSopenharmony_ci  AssignHexString(&c, "123456789000000000ABCDEF12345");
13222e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
13232e5b6d6dSopenharmony_ci
13242e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13252e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13262e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12346");
13272e5b6d6dSopenharmony_ci  AssignHexString(&c, "123456789000000000ABCDEF12345");
13282e5b6d6dSopenharmony_ci  CHECK_EQ(1, Bignum::PlusCompare(a, b, c));
13292e5b6d6dSopenharmony_ci
13302e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13312e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13322e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12344");
13332e5b6d6dSopenharmony_ci  AssignHexString(&c, "123456789000000000ABCDEF12345");
13342e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
13352e5b6d6dSopenharmony_ci
13362e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13372e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13382e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
13392e5b6d6dSopenharmony_ci  b.ShiftLeft(16);
13402e5b6d6dSopenharmony_ci  AssignHexString(&c, "12345678900000ABCDEF123450000");
13412e5b6d6dSopenharmony_ci  CHECK_EQ(0, Bignum::PlusCompare(a, b, c));
13422e5b6d6dSopenharmony_ci
13432e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13442e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13452e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12344");
13462e5b6d6dSopenharmony_ci  b.ShiftLeft(16);
13472e5b6d6dSopenharmony_ci  AssignHexString(&c, "12345678900000ABCDEF123450000");
13482e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
13492e5b6d6dSopenharmony_ci
13502e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13512e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13522e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12345");
13532e5b6d6dSopenharmony_ci  b.ShiftLeft(16);
13542e5b6d6dSopenharmony_ci  AssignHexString(&c, "12345678900000ABCDEF123450001");
13552e5b6d6dSopenharmony_ci  CHECK_EQ(-1, Bignum::PlusCompare(a, b, c));
13562e5b6d6dSopenharmony_ci
13572e5b6d6dSopenharmony_ci  AssignHexString(&a, "1234567890");
13582e5b6d6dSopenharmony_ci  a.ShiftLeft(11*4 + 32);
13592e5b6d6dSopenharmony_ci  AssignHexString(&b, "ABCDEF12346");
13602e5b6d6dSopenharmony_ci  b.ShiftLeft(16);
13612e5b6d6dSopenharmony_ci  AssignHexString(&c, "12345678900000ABCDEF123450000");
13622e5b6d6dSopenharmony_ci  CHECK_EQ(+1, Bignum::PlusCompare(a, b, c));
13632e5b6d6dSopenharmony_ci}
13642e5b6d6dSopenharmony_ci
13652e5b6d6dSopenharmony_ci
13662e5b6d6dSopenharmony_ciTEST(Square) {
13672e5b6d6dSopenharmony_ci  Bignum bignum;
13682e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
13692e5b6d6dSopenharmony_ci
13702e5b6d6dSopenharmony_ci  bignum.AssignUInt16(1);
13712e5b6d6dSopenharmony_ci  bignum.Square();
13722e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
13732e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
13742e5b6d6dSopenharmony_ci
13752e5b6d6dSopenharmony_ci  bignum.AssignUInt16(2);
13762e5b6d6dSopenharmony_ci  bignum.Square();
13772e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
13782e5b6d6dSopenharmony_ci  CHECK_EQ("4", buffer);
13792e5b6d6dSopenharmony_ci
13802e5b6d6dSopenharmony_ci  bignum.AssignUInt16(10);
13812e5b6d6dSopenharmony_ci  bignum.Square();
13822e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
13832e5b6d6dSopenharmony_ci  CHECK_EQ("64", buffer);
13842e5b6d6dSopenharmony_ci
13852e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFF");
13862e5b6d6dSopenharmony_ci  bignum.Square();
13872e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
13882e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFE0000001", buffer);
13892e5b6d6dSopenharmony_ci
13902e5b6d6dSopenharmony_ci  AssignHexString(&bignum, "FFFFFFFFFFFFFF");
13912e5b6d6dSopenharmony_ci  bignum.Square();
13922e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
13932e5b6d6dSopenharmony_ci  CHECK_EQ("FFFFFFFFFFFFFE00000000000001", buffer);
13942e5b6d6dSopenharmony_ci}
13952e5b6d6dSopenharmony_ci
13962e5b6d6dSopenharmony_ci
13972e5b6d6dSopenharmony_ciTEST(AssignPowerUInt16) {
13982e5b6d6dSopenharmony_ci  Bignum bignum;
13992e5b6d6dSopenharmony_ci  char buffer[kBufferSize];
14002e5b6d6dSopenharmony_ci
14012e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(1, 0);
14022e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14032e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14042e5b6d6dSopenharmony_ci
14052e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(1, 1);
14062e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14072e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14082e5b6d6dSopenharmony_ci
14092e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(1, 2);
14102e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14112e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14122e5b6d6dSopenharmony_ci
14132e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(2, 0);
14142e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14152e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14162e5b6d6dSopenharmony_ci
14172e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(2, 1);
14182e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14192e5b6d6dSopenharmony_ci  CHECK_EQ("2", buffer);
14202e5b6d6dSopenharmony_ci
14212e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(2, 2);
14222e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14232e5b6d6dSopenharmony_ci  CHECK_EQ("4", buffer);
14242e5b6d6dSopenharmony_ci
14252e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(16, 1);
14262e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14272e5b6d6dSopenharmony_ci  CHECK_EQ("10", buffer);
14282e5b6d6dSopenharmony_ci
14292e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(16, 2);
14302e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14312e5b6d6dSopenharmony_ci  CHECK_EQ("100", buffer);
14322e5b6d6dSopenharmony_ci
14332e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(16, 5);
14342e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14352e5b6d6dSopenharmony_ci  CHECK_EQ("100000", buffer);
14362e5b6d6dSopenharmony_ci
14372e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(16, 8);
14382e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14392e5b6d6dSopenharmony_ci  CHECK_EQ("100000000", buffer);
14402e5b6d6dSopenharmony_ci
14412e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(16, 16);
14422e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14432e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000", buffer);
14442e5b6d6dSopenharmony_ci
14452e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(16, 30);
14462e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14472e5b6d6dSopenharmony_ci  CHECK_EQ("1000000000000000000000000000000", buffer);
14482e5b6d6dSopenharmony_ci
14492e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 0);
14502e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14512e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14522e5b6d6dSopenharmony_ci
14532e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 1);
14542e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14552e5b6d6dSopenharmony_ci  CHECK_EQ("A", buffer);
14562e5b6d6dSopenharmony_ci
14572e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 2);
14582e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14592e5b6d6dSopenharmony_ci  CHECK_EQ("64", buffer);
14602e5b6d6dSopenharmony_ci
14612e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 5);
14622e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14632e5b6d6dSopenharmony_ci  CHECK_EQ("186A0", buffer);
14642e5b6d6dSopenharmony_ci
14652e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 8);
14662e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14672e5b6d6dSopenharmony_ci  CHECK_EQ("5F5E100", buffer);
14682e5b6d6dSopenharmony_ci
14692e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 16);
14702e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14712e5b6d6dSopenharmony_ci  CHECK_EQ("2386F26FC10000", buffer);
14722e5b6d6dSopenharmony_ci
14732e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 30);
14742e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14752e5b6d6dSopenharmony_ci  CHECK_EQ("C9F2C9CD04674EDEA40000000", buffer);
14762e5b6d6dSopenharmony_ci
14772e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(10, 31);
14782e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14792e5b6d6dSopenharmony_ci  CHECK_EQ("7E37BE2022C0914B2680000000", buffer);
14802e5b6d6dSopenharmony_ci
14812e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(2, 0);
14822e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14832e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14842e5b6d6dSopenharmony_ci
14852e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(2, 100);
14862e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14872e5b6d6dSopenharmony_ci  CHECK_EQ("10000000000000000000000000", buffer);
14882e5b6d6dSopenharmony_ci
14892e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(17, 0);
14902e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14912e5b6d6dSopenharmony_ci  CHECK_EQ("1", buffer);
14922e5b6d6dSopenharmony_ci
14932e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(17, 99);
14942e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
14952e5b6d6dSopenharmony_ci  CHECK_EQ("1942BB9853FAD924A3D4DD92B89B940E0207BEF05DB9C26BC1B757"
14962e5b6d6dSopenharmony_ci           "80BE0C5A2C2990E02A681224F34ED68558CE4C6E33760931",
14972e5b6d6dSopenharmony_ci           buffer);
14982e5b6d6dSopenharmony_ci
14992e5b6d6dSopenharmony_ci  bignum.AssignPowerUInt16(0xFFFF, 99);
15002e5b6d6dSopenharmony_ci  CHECK(bignum.ToHexString(buffer, kBufferSize));
15012e5b6d6dSopenharmony_ci  CHECK_EQ("FF9D12F09B886C54E77E7439C7D2DED2D34F669654C0C2B6B8C288250"
15022e5b6d6dSopenharmony_ci           "5A2211D0E3DC9A61831349EAE674B11D56E3049D7BD79DAAD6C9FA2BA"
15032e5b6d6dSopenharmony_ci           "528E3A794299F2EE9146A324DAFE3E88967A0358233B543E233E575B9"
15042e5b6d6dSopenharmony_ci           "DD4E3AA7942146426C328FF55BFD5C45E0901B1629260AF9AE2F310C5"
15052e5b6d6dSopenharmony_ci           "50959FAF305C30116D537D80CF6EBDBC15C5694062AF1AC3D956D0A41"
15062e5b6d6dSopenharmony_ci           "B7E1B79FF11E21D83387A1CE1F5882B31E4B5D8DE415BDBE6854466DF"
15072e5b6d6dSopenharmony_ci           "343362267A7E8833119D31D02E18DB5B0E8F6A64B0ED0D0062FFFF",
15082e5b6d6dSopenharmony_ci           buffer);
15092e5b6d6dSopenharmony_ci}
1510