8 #include <boost/test/unit_test.hpp>
27 "\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
28 "\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
29 const char R1ArrayHex[] =
"7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
32 const uint64_t
R1LLow64 = 0x121156cfdb4a529cULL;
35 "\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf"
36 "\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
39 const char R1LplusR2L[] =
"549FB09FEA236A1EA3E31D4D58F1B1369288D204211CA751527CFC175767850C";
42 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
43 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
47 "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
48 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
52 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
53 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
57 static std::string
ArrayToString(
const unsigned char A[],
unsigned int width)
59 std::stringstream Stream;
61 for (
unsigned int i = 0; i < width; ++i)
63 Stream<<std::setw(2)<<std::setfill(
'0')<<(
unsigned int)A[width-i-1];
87 uint64_t Tmp64 = 0xc4dab720d9c7acaaULL;
88 for (
unsigned int i = 0; i < 256; ++i)
126 static void shiftArrayRight(
unsigned char* to,
const unsigned char* from,
unsigned int arrayLength,
unsigned int bitsToShift)
128 for (
unsigned int T=0;
T < arrayLength; ++
T)
130 unsigned int F = (
T+bitsToShift/8);
132 to[
T] = uint8_t(from[F] >> (bitsToShift % 8));
135 if (F + 1 < arrayLength)
136 to[
T] |= uint8_t(from[(F + 1)] << (8 - bitsToShift % 8));
140 static void shiftArrayLeft(
unsigned char* to,
const unsigned char* from,
unsigned int arrayLength,
unsigned int bitsToShift)
142 for (
unsigned int T=0;
T < arrayLength; ++
T)
144 if (
T >= bitsToShift/8)
146 unsigned int F =
T-bitsToShift/8;
147 to[
T] = uint8_t(from[F] << (bitsToShift % 8));
148 if (
T >= bitsToShift/8+1)
149 to[
T] |= uint8_t(from[F - 1] >> (8 - bitsToShift % 8));
158 unsigned char TmpArray[32];
160 for (
unsigned int i = 0; i < 256; ++i)
164 TmpL =
OneL; TmpL <<= i;
167 TmpL =
HalfL; TmpL >>= (255-i);
172 TmpL =
R1L; TmpL <<= i;
177 TmpL =
R1L; TmpL >>= i;
182 TmpL =
MaxL; TmpL <<= i;
187 TmpL =
MaxL; TmpL >>= i;
192 for (
unsigned int i = 0; i < 128; ++i) {
195 for (
unsigned int i = 128; i < 256; ++i) {
204 unsigned char TmpArray[32];
205 for (
unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(~
R1Array[i]); }
210 for (
unsigned int i = 0; i < 256; ++i)
217 #define CHECKBITWISEOPERATOR(_A_,_B_,_OP_) \
218 for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(_A_##Array[i] _OP_ _B_##Array[i]); } \
219 BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L));
221 #define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \
222 TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L));
226 unsigned char TmpArray[32];
261 uint64_t Tmp64 = 0xe1db685c9a0b47a2ULL;
271 for (
unsigned int i = 0; i < 256; ++i) {
274 BOOST_CHECK( TmpL >= 0 && TmpL > 0 && 0 < TmpL && 0 <= TmpL);
292 for (
unsigned int i = 1; i < 256; ++i) {
297 TmpL = (
MaxL>>i); TmpL += 1;
304 TmpL =
arith_uint256(0xbedc77e27940a7ULL); TmpL += 0xee8d836fce66fbULL;
306 TmpL -= 0xee8d836fce66fbULL;
BOOST_CHECK(TmpL == 0xbedc77e27940a7ULL);
313 for (
unsigned int i = 1; i < 256; ++i) {
316 TmpL = (
HalfL >> (i-1));
319 TmpL = (
HalfL >> (i-1));
344 BOOST_CHECK((
R2L * 0x87654321UL).
ToString() ==
"23f7816e30c4ae2017257b7a0fa64d60402f5234d46e746b61c960d09a26d070");
351 BOOST_CHECK((
R1L / D1L).
ToString() ==
"00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a");
352 BOOST_CHECK((
R1L / D2L).
ToString() ==
"000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a");
357 BOOST_CHECK((
R2L / D1L).
ToString() ==
"000000000000000013e1665895a1cc981de6d93670105a6b3ec3b73141b3a3c5");
358 BOOST_CHECK((
R2L / D2L).
ToString() ==
"000000000e8f0abe753bb0afe2e9437ee85d280be60882cf0bd1aaf7fa3cc2c4");
368 return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
392 for (
unsigned int i = 0; i < 255; ++i)
397 for (
int i = 256; i > 53; --i)
399 uint64_t R1L64part = (
R1L>>192).GetLow64();
400 for (
int i = 53; i > 0; --i)
402 BOOST_CHECK((
R1L>>(256-i)).getdouble() == (
double)(R1L64part >> (64-i)));
417 num.
SetCompact(0x00123456, &fNegative, &fOverflow);
423 num.
SetCompact(0x01003456, &fNegative, &fOverflow);
429 num.
SetCompact(0x02000056, &fNegative, &fOverflow);
435 num.
SetCompact(0x03000000, &fNegative, &fOverflow);
441 num.
SetCompact(0x04000000, &fNegative, &fOverflow);
447 num.
SetCompact(0x00923456, &fNegative, &fOverflow);
453 num.
SetCompact(0x01803456, &fNegative, &fOverflow);
459 num.
SetCompact(0x02800056, &fNegative, &fOverflow);
465 num.
SetCompact(0x03800000, &fNegative, &fOverflow);
471 num.
SetCompact(0x04800000, &fNegative, &fOverflow);
477 num.
SetCompact(0x01123456, &fNegative, &fOverflow);
487 num.
SetCompact(0x01fedcba, &fNegative, &fOverflow);
493 num.
SetCompact(0x02123456, &fNegative, &fOverflow);
499 num.
SetCompact(0x03123456, &fNegative, &fOverflow);
505 num.
SetCompact(0x04123456, &fNegative, &fOverflow);
511 num.
SetCompact(0x04923456, &fNegative, &fOverflow);
517 num.
SetCompact(0x05009234, &fNegative, &fOverflow);
523 num.
SetCompact(0x20123456, &fNegative, &fOverflow);
529 num.
SetCompact(0xff123456, &fNegative, &fOverflow);
552 unsigned char TmpArray[32];