bool operator == ( const price& a, const price& b ) { if( std::tie( a.base.symbol, a.quote.symbol ) != std::tie( b.base.symbol, b.quote.symbol ) ) return false; const auto amult = uint128_t( b.quote.amount.value ) * a.base.amount.value; const auto bmult = uint128_t( a.quote.amount.value ) * b.base.amount.value; return amult == bmult; }
bool operator < ( const price& a, const price& b ) { if( a.base.symbol < b.base.symbol ) return true; if( a.base.symbol > b.base.symbol ) return false; if( a.quote.symbol < b.quote.symbol ) return true; if( a.quote.symbol > b.quote.symbol ) return false; const auto amult = uint128_t( b.quote.amount.value ) * a.base.amount.value; const auto bmult = uint128_t( a.quote.amount.value ) * b.base.amount.value; return amult < bmult; }
TEST(External, multiply){ bool t = true; bool f = false; uint8_t u8 = 0xaaULL; uint16_t u16 = 0xaaaaULL; uint32_t u32 = 0xaaaaaaaaULL; uint64_t u64 = 0xaaaaaaaaaaaaaaaaULL; uint128_t u128 (0xaaaaaaaaaaaaaaaaULL, 0xaaaaaaaaaaaaaaaaULL); const uint256_t val(0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL); EXPECT_EQ(t * val, uint256_t(0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL)); EXPECT_EQ(f * val, uint256_t(0x0000000000000000ULL, 0x0000000000000000ULL, 0x0000000000000000ULL, 0x0000000000000000ULL)); EXPECT_EQ(u8 * val, uint256_t(0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffff60ULL)); EXPECT_EQ(u16 * val, uint256_t(0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffff5f60ULL)); EXPECT_EQ(u32 * val, uint256_t(0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffff5f5f5f60ULL)); EXPECT_EQ(u64 * val, uint256_t(0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL, 0x5f5f5f5f5f5f5f60ULL)); EXPECT_EQ(u128 * val, uint256_t(0xffffffffffffffffULL, 0xffffffffffffffffULL, 0x5f5f5f5f5f5f5f5fULL, 0x5f5f5f5f5f5f5f60ULL)); EXPECT_EQ(t *= val, true); EXPECT_EQ(f *= val, false); EXPECT_EQ(u8 *= val, (uint8_t) 0x60ULL); EXPECT_EQ(u16 *= val, (uint16_t) 0x5f60ULL); EXPECT_EQ(u32 *= val, (uint32_t) 0x5f5f5f60ULL); EXPECT_EQ(u64 *= val, (uint64_t) 0x5f5f5f5f5f5f5f60ULL); EXPECT_EQ(u128 *= val, uint128_t(0x5f5f5f5f5f5f5f5fULL, 0x5f5f5f5f5f5f5f60ULL)); }
TEST(External, divide){ bool t = true; bool f = false; uint8_t u8 = 0xaaULL; uint16_t u16 = 0xaaaaULL; uint32_t u32 = 0xaaaaaaaaULL; uint64_t u64 = 0xaaaaaaaaaaaaaaaaULL; uint128_t u128 (0xaaaaaaaaaaaaaaaaULL, 0xaaaaaaaaaaaaaaaaULL); const uint256_t val(0x7bULL); EXPECT_EQ(t / val, false); EXPECT_EQ(f / val, false); EXPECT_EQ(u8 / val, uint256_t(0x1ULL)); EXPECT_EQ(u16 / val, uint256_t(0x163ULL)); EXPECT_EQ(u32 / val, uint256_t(0x163356bULL)); EXPECT_EQ(u64 / val, uint256_t(0x163356b88ac0de0ULL)); EXPECT_EQ(u128 / val, uint256_t(0x0000000000000000ULL, 0x0000000000000000ULL, 0x163356b88ac0de0ULL, 0x163356b88ac0de01ULL)); EXPECT_EQ(t /= val, false); EXPECT_EQ(f /= val, false); EXPECT_EQ(u8 /= val, (uint8_t) 0x1ULL); EXPECT_EQ(u16 /= val, (uint16_t) 0x163ULL); EXPECT_EQ(u32 /= val, (uint32_t) 0x163356bULL); EXPECT_EQ(u64 /= val, (uint64_t) 0x163356b88ac0de0ULL); EXPECT_EQ(u128 /= val, uint128_t(0x163356b88ac0de0ULL, 0x163356b88ac0de01ULL)); }
TEST(External, subtract){ bool t = true; bool f = false; uint8_t u8 = 0xaaULL; uint16_t u16 = 0xaaaaULL; uint32_t u32 = 0xaaaaaaaaULL; uint64_t u64 = 0xaaaaaaaaaaaaaaaaULL; uint128_t u128 (0xaaaaaaaaaaaaaaaaULL, 0xaaaaaaaaaaaaaaaaULL); const uint256_t val(0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL); EXPECT_EQ(t - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f11ULL)); EXPECT_EQ(f - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f10ULL)); EXPECT_EQ(u8 - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0fbaULL)); EXPECT_EQ(u16 - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0fb9baULL)); EXPECT_EQ(u32 - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0fb9b9b9baULL)); EXPECT_EQ(u64 - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0xb9b9b9b9b9b9b9baULL)); EXPECT_EQ(u128 - val, uint256_t(0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL, 0xb9b9b9b9b9b9b9b9ULL, 0xb9b9b9b9b9b9b9baULL)); EXPECT_EQ(t -= val, true); EXPECT_EQ(f -= val, true); EXPECT_EQ(u8 -= val, (uint8_t) 0xbaULL); EXPECT_EQ(u16 -= val, (uint16_t) 0xb9baULL); EXPECT_EQ(u32 -= val, (uint32_t) 0xb9b9b9baULL); EXPECT_EQ(u64 -= val, (uint64_t) 0xb9b9b9b9b9b9b9baULL); EXPECT_EQ(u128 -= val, uint128_t(0xb9b9b9b9b9b9b9b9ULL, 0xb9b9b9b9b9b9b9baULL)); }
uint128_t TileQueue::getQueueMasterID(const Eye eye) const { uint32_t index = lunchbox::getIndexOfLastBit(eye); LatencyQueue* queue = _queueMaster[index]; if (queue) return queue->_queue.getID(); return uint128_t(); }
TEST(External, and){ bool t = true; bool f = false; uint8_t u8 = 0xaaULL; uint16_t u16 = 0xaaaaULL; uint32_t u32 = 0xaaaaaaaaULL; uint64_t u64 = 0xaaaaaaaaaaaaaaaaULL; const uint128_t val(0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL); EXPECT_EQ(t & val, uint128_t(0x0ULL)); EXPECT_EQ(f & val, uint128_t(0x0ULL)); EXPECT_EQ(u8 & val, uint128_t(0xa0ULL)); EXPECT_EQ(u16 & val, uint128_t(0xa0a0ULL)); EXPECT_EQ(u32 & val, uint128_t(0xa0a0a0a0ULL)); EXPECT_EQ(u64 & val, uint128_t(0xa0a0a0a0a0a0a0a0ULL)); EXPECT_EQ(t &= val, false); EXPECT_EQ(f &= val, false); EXPECT_EQ(u8 &= val, (uint8_t) 0xa0ULL); EXPECT_EQ(u16 &= val, (uint16_t) 0xa0a0ULL); EXPECT_EQ(u32 &= val, (uint32_t) 0xa0a0a0a0ULL); EXPECT_EQ(u64 &= val, (uint64_t) 0xa0a0a0a0a0a0a0a0ULL); // zero EXPECT_EQ(uint128_t() & val, 0); }
asset operator*(const asset &a, const price &b) { if (a.symbol_name() == b.base.symbol_name()) { FC_ASSERT(b.base.amount.value > 0); uint128_t result = (uint128_t(a.amount.value) * b.quote.amount.value) / b.base.amount.value; FC_ASSERT(result.hi == 0); return asset(result.to_uint64(), b.quote.symbol); } else if (a.symbol_name() == b.quote.symbol_name()) { FC_ASSERT(b.quote.amount.value > 0); uint128_t result = (uint128_t(a.amount.value) * b.base.amount.value) / b.quote.amount.value; FC_ASSERT(result.hi == 0); return asset(result.to_uint64(), b.base.symbol); } FC_THROW_EXCEPTION(fc::assert_exception, "invalid asset * price", ("asset", a)("price", b)); }
asset operator * ( const asset& a, const price& b ) { if( a.symbol_name() == b.base.symbol_name() ) { FC_ASSERT( b.base.amount.value > 0 ); uint128_t result = (uint128_t(a.amount.value) * b.quote.amount.value)/b.base.amount.value; FC_ASSERT( result <= uint64_t(-1) ); return asset( result.to_uint64(), b.quote.symbol ); } else if( a.symbol_name() == b.quote.symbol_name() ) { FC_ASSERT( b.quote.amount.value > 0 ); uint128_t result = (uint128_t(a.amount.value) * b.base.amount.value)/b.quote.amount.value; //FC_ASSERT( result <= STEEMIT_MAX_SHARE_SUPPLY, "${result}", ("result",result)("max",STEEMIT_MAX_SHARE_SUPPLY)("asset",a)("price",b) ); FC_ASSERT( result <= uint64_t(-1) ); return asset( result.to_uint64(), b.base.symbol ); } FC_THROW_EXCEPTION( fc::assert_exception, "invalid asset * price", ("asset",a)("price",b) ); }
uint128_t computeMinMax() const { uint64_t xMax = 0; uint64_t xMin = std::numeric_limits<uint64_t>::max(); for (ItemsCIter i = items.begin(); i != items.end(); ++i) { const Item& item = *i; xMin = LB_MIN(xMin, item.start); xMax = LB_MAX(xMax, item.end); } return uint128_t(xMax, xMin); }
share_type calc_percent_reward( share_type current_supply ) { static_assert( shift_constant > 0, "shift constant cannot be zero" ); static_assert( shift_constant < 128, "shift constant is implausibly large, re-check your arguments" ); static_assert( multiply_constant > 256, "multiply constant is implausibly small, re-check your arguments" ); static_assert( multiply_constant < UINT64_MAX / (10 * uint64_t( STEEMIT_100_PERCENT )), "multiply constant is too large, we may be in danger of overflow" ); static_assert( (percent == 0) || (percent > STEEMIT_1_PERCENT), "percent is smaller than 1%, re-check your arguments" ); static_assert( percent <= STEEMIT_100_PERCENT, "percent is implausibly large, re-check your arguments (if you really mean to do this, you should revise the overflow check above accordingly)" ); static const uint128_t half = uint128_t(1) << (shift_constant - 1); uint128_t reward = current_supply.value; reward *= (percent * multiply_constant); // compile-time constant, fits in 64 bits reward += half; // round to nearest whole integer instead of truncating reward >>= shift_constant; return reward.to_uint64(); }
void Config::setApplicationNetNode( co::NodePtr netNode ) { if( netNode.isValid( )) { LBASSERT( _state == STATE_UNUSED ); _state = STATE_STOPPED; setAppNodeID( netNode->getNodeID( )); } else { LBASSERT( _state == STATE_STOPPED ); _state = STATE_UNUSED; setAppNodeID( uint128_t( )); } Node* node = findApplicationNode(); LBASSERT( node ); if( node ) node->setNode( netNode ); }
TEST(External, equals){ const bool t = true; const bool f = false; const uint8_t u8 = 0xaaULL; const uint16_t u16 = 0xaaaaULL; const uint32_t u32 = 0xaaaaaaaaULL; const uint64_t u64 = 0xaaaaaaaaaaaaaaaaULL; EXPECT_EQ(t, uint128_t(t)); EXPECT_EQ(f, uint128_t(f)); EXPECT_EQ(u8, uint128_t(u8)); EXPECT_EQ(u16, uint128_t(u16)); EXPECT_EQ(u32, uint128_t(u32)); EXPECT_EQ(u64, uint128_t(u64)); }
ObjectDataIStream* DataIStreamQueue::tryPop() { QueuedStream stream(uint128_t(), (ObjectDataIStream*)0); _queued.tryPop(stream); return stream.second; }
uint128_t operator() (const uint128_t & x) const { return uint128_t(revcomp_block(x._lower), revcomp_block(x._upper)) << (128 - _k * NT_WIDTH); }
TEST(Comparison, equals){ EXPECT_EQ( (uint128_t(0xdeadbeefULL) == uint128_t(0xdeadbeefULL)), true); EXPECT_EQ(!(uint128_t(0xdeadbeefULL) == uint128_t(0xfee1baadULL)), true); }
RoutingTable::RoutingTable() { _root = new Zone(NULL, uint128_t(), 0, new KBucket()); _last_leaves_merge = get_current_time(); }
uint128_t deserializeRequest( const ::zeroeq::Event& event ) { const auto& data = GetRequest( event.getData( )); return uint128_t( data->eventHigh(), data->eventLow( )); }
template <typename T> T & operator%=(T & lhs, uint128_t rhs){ lhs = (T) (uint128_t(lhs) % rhs); return lhs; }
template <typename T> T operator/(T lhs, uint128_t rhs){ return (T) (uint128_t(lhs) / rhs); }
TEST(Arithmetic, decrement){ uint128_t value(0); EXPECT_EQ(--value, uint128_t(0xffffffffffffffffULL, 0xffffffffffffffffULL)); EXPECT_EQ(value--, uint128_t(0xffffffffffffffffULL, 0xffffffffffffffffULL)); EXPECT_EQ(--value, uint128_t(0xffffffffffffffffULL, 0xfffffffffffffffdULL)); }
TEST(BitWise, and){ uint128_t t ((bool) true); uint128_t f ((bool) false); uint128_t u8 ((uint8_t) 0xaaULL); uint128_t u16((uint16_t) 0xaaaaULL); uint128_t u32((uint32_t) 0xaaaaaaaaULL); uint128_t u64((uint64_t) 0xaaaaaaaaaaaaaaaaULL); const uint128_t val(0xf0f0f0f0f0f0f0f0ULL, 0xf0f0f0f0f0f0f0f0ULL); EXPECT_EQ(t & val, uint128_t(0)); EXPECT_EQ(f & val, uint128_t(0)); EXPECT_EQ(u8 & val, uint128_t(0xa0ULL)); EXPECT_EQ(u16 & val, uint128_t(0xa0a0ULL)); EXPECT_EQ(u32 & val, uint128_t(0xa0a0a0a0ULL)); EXPECT_EQ(u64 & val, uint128_t(0xa0a0a0a0a0a0a0a0ULL)); EXPECT_EQ(t &= val, uint128_t(0x0ULL)); EXPECT_EQ(f &= val, uint128_t(0x0ULL)); EXPECT_EQ(u8 &= val, uint128_t(0xa0ULL)); EXPECT_EQ(u16 &= val, uint128_t(0xa0a0ULL)); EXPECT_EQ(u32 &= val, uint128_t(0xa0a0a0a0ULL)); EXPECT_EQ(u64 &= val, uint128_t(0xa0a0a0a0a0a0a0a0ULL)); }
inline uint128_t operator() (const uint128_t & x) const { return uint128_t(reverse_block(x._lower), reverse_block(x._upper)); }