9#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";
29const char R1ArrayHex[] =
"7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
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";
40 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
41 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
45 "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
46 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
50 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
51 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
59 for (
unsigned int i = 0; i <
width; ++i)
86 for (
unsigned int i = 0; i < 256; ++i)
157 for (
unsigned int i = 0; i < 256; ++i)
189 for (
unsigned int i = 0; i < 128; ++i) {
192 for (
unsigned int i = 128; i < 256; ++i) {
207 for (
unsigned int i = 0; i < 256; ++i)
214#define CHECKBITWISEOPERATOR(_A_,_B_,_OP_) \
215 for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(_A_##Array[i] _OP_ _B_##Array[i]); } \
216 BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L));
218#define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \
219 TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L));
268 for (
unsigned int i = 0; i < 256; ++i) {
292 for (
unsigned int i = 1; i < 256; ++i) {
313 for (
unsigned int i = 1; i < 256; ++i) {
328 BOOST_CHECK((
R1L *
R1L).ToString() ==
"62a38c0486f01e45879d7910a7761bf30d5237e9873f9bff3642a732c4d84f10");
329 BOOST_CHECK((
R1L *
R2L).ToString() ==
"de37805e9986996cfba76ff6ba51c008df851987d9dd323f0e5de07760529c40");
334 BOOST_CHECK((
R2L *
R2L).ToString() ==
"ac8c010096767d3cae5005dec28bb2b45a1d85ab7996ccd3e102a650f74ff100");
343 BOOST_CHECK((
R1L * 3).ToString() ==
"7759b1c0ed14047f961ad09b20ff83687876a0181a367b813634046f91def7d4");
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();
395 for (
unsigned int i = 0; i < 255; ++i)
400 for (
int i = 256; i > 53; --i)
403 for (
int i = 53; i > 0; --i)
574 for (
uint8_t num : {0, 1, 0xff}) {
arith_uint256 UintToArith256(const uint256 &a)
uint256 ArithToUint256(const arith_uint256 &a)
static void shiftArrayLeft(unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
static void shiftArrayRight(unsigned char *to, const unsigned char *from, unsigned int arrayLength, unsigned int bitsToShift)
BOOST_CHECK_LT(ZeroL, OneL)
#define CHECKBITWISEOPERATOR(_A_, _B_, _OP_)
#define CHECKASSIGNMENTOPERATOR(_A_, _B_, _OP_)
const unsigned char ZeroArray[]
const unsigned char R1Array[]
const arith_uint256 HalfL
const unsigned char OneArray[]
BOOST_AUTO_TEST_CASE(shifts)
static bool almostEqual(double d1, double d2)
const unsigned char R2Array[]
static std::string ArrayToString(const unsigned char A[], unsigned int width)
static arith_uint256 arith_uint256V(const std::vector< unsigned char > &vch)
Convert vector to arith_uint256, via uint256 blob.
const unsigned char MaxArray[]
unsigned char TmpArray[32]
const arith_uint256 ZeroL
256-bit unsigned big integer.
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
uint32_t GetCompact(bool fNegative=false) const
unsigned int size() const
std::string ToString() const
uint64_t GetLow64() const
std::string GetHex() const
Hex encoding of the number (with the most significant digits first).
static std::optional< uint256 > FromHex(std::string_view str)
BOOST_AUTO_TEST_SUITE_END()
#define T(expected, seed, data)
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.