4#include <boost/multiprecision/cpp_int.hpp>
11 typedef boost::multiprecision::uint128_t
m128;
14 static void divide(
const T &numerator,
const T &denominator,
T "ient,
T &remainder)
16 static const int bits =
sizeof(
T) * 8;
18 if(denominator == 0) {
19 throw std::domain_error(
"divide by zero");
27 while((n >=
d) && (((
d >> (bits - 1)) & 1) == 0)) {
56 std::string::const_iterator i = sz.begin();
78 while(i != sz.end()) {
82 if(ch >=
'A' && ch <=
'Z') {
83 if(((ch -
'A') + 10) < radix) {
88 }
else if(ch >=
'a' && ch <=
'z') {
89 if(((ch -
'a') + 10) < radix) {
94 }
else if(ch >=
'0' && ch <=
'9') {
95 if((ch -
'0') < radix) {
120 uint128::operator bigint()
const
122 auto tmp = uint128( bswap_64( hi ), bswap_64( lo ) );
123 bigint bi( (
char*)&tmp,
sizeof(tmp) );
128 *
this =
uint128( std::string(bi) );
131 uint128::operator std::string ()
const
133 if(*
this == 0) {
return "0"; }
137 static char sz [128 + 1];
138 sz[
sizeof(sz) - 1] =
'\0';
143 while (ii != 0 && i) {
146 divide(ii,
uint128(10), ii, remainder);
147 sz [--i] =
"0123456789abcdefghijklmnopqrstuvwxyz"[remainder.
to_integer()];
164 const unsigned int halfsize = 128 / 2;
179 hi |= (lo & mask) >> (halfsize - n);
199 const unsigned int halfsize = 128 / 2;
215 lo |= (hi & mask) << (halfsize - n);
226 auto self = (
m128(hi) << 64) +
m128(lo);
229 hi =
static_cast<uint64_t>(self >> 64);
230 lo =
static_cast<uint64_t>((self << 64 ) >> 64);
253 divide(*
this, b, quotient, *
this);
354 0x5555555555555555ULL,
355 0x3333333333333333ULL,
356 0x0F0F0F0F0F0F0F0FULL,
357 0x00FF00FF00FF00FFULL,
358 0x0000FFFF0000FFFFULL,
359 0x00000000FFFFFFFFULL
365 for(
int i=0, w=1; i<6; i++, w+=w )
367 x = (x & m[i]) + ((x >> w) & m[i]);
374 return _popcount_64( lo ) + _popcount_64( hi );
an implementation of 128 bit unsigned integer
uint32_t to_integer() const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
boost::multiprecision::uint128_t m128
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)
unsigned __int64 uint64_t