예제 #1
0
파일: asset.cpp 프로젝트: iamsmooth/steem
      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;
      }
예제 #2
0
파일: asset.cpp 프로젝트: iamsmooth/steem
      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;
      }
예제 #3
0
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));
}
예제 #4
0
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));
}
예제 #5
0
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));
}
예제 #6
0
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();
}
예제 #7
0
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);
}
예제 #8
0
파일: asset.cpp 프로젝트: Rsteem/steem
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));
}
예제 #9
0
파일: asset.cpp 프로젝트: pharesim/steem
 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) );
 }
예제 #10
0
파일: data.cpp 프로젝트: Eyescale/GLStats
    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);
    }
예제 #11
0
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();
}
예제 #12
0
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 );
}
예제 #13
0
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));
}
예제 #14
0
ObjectDataIStream* DataIStreamQueue::tryPop()
{
    QueuedStream stream(uint128_t(), (ObjectDataIStream*)0);
    _queued.tryPop(stream);
    return stream.second;
}
예제 #15
0
파일: kmer.hpp 프로젝트: raymondr/cosmo
 uint128_t operator() (const uint128_t & x) const {
     return uint128_t(revcomp_block(x._lower), revcomp_block(x._upper)) << (128 - _k * NT_WIDTH);
 }
예제 #16
0
TEST(Comparison, equals){
    EXPECT_EQ( (uint128_t(0xdeadbeefULL) == uint128_t(0xdeadbeefULL)), true);
    EXPECT_EQ(!(uint128_t(0xdeadbeefULL) == uint128_t(0xfee1baadULL)), true);
}
예제 #17
0
RoutingTable::RoutingTable()
{
    _root = new Zone(NULL, uint128_t(), 0, new KBucket());
    _last_leaves_merge = get_current_time();
}
예제 #18
0
파일: vocabulary.cpp 프로젝트: favreau/zeq
uint128_t deserializeRequest( const ::zeroeq::Event& event )
{
    const auto& data = GetRequest( event.getData( ));
    return uint128_t( data->eventHigh(), data->eventLow( ));
}
예제 #19
0
파일: uint128.cpp 프로젝트: jiffe/focalcoin
template <typename T> T & operator%=(T & lhs, uint128_t rhs){
    lhs = (T) (uint128_t(lhs) % rhs);
    return lhs;
}
예제 #20
0
파일: uint128.cpp 프로젝트: jiffe/focalcoin
template <typename T> T operator/(T lhs, uint128_t rhs){
    return (T) (uint128_t(lhs) / rhs);
}
예제 #21
0
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));
}
예제 #22
0
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));
}
예제 #23
0
파일: kmer.hpp 프로젝트: raymondr/cosmo
 inline uint128_t operator() (const uint128_t & x) const {
     return uint128_t(reverse_block(x._lower), reverse_block(x._upper));
 }