Ejemplo n.º 1
0
  static uint128 sigma1_sum(const uint64 n) {
    uint32 v = isqrt(n);
    uint128 ret = 0;

    for (uint32 i = 1; i <= v; ++i) {
      uint64 t = n / i;
      ret += uint128(t) * (uint64(2) * i + t + 1);
    }
    ret -= uint128(v) * v * (v + 1);
    return ret >> 1;
  }
Ejemplo n.º 2
0
FastDivision<uint64>::FastDivision(uint64 n) {
  // n should be < 2^63.
  if (n == 1) {
    shamt = 0;
    magic_num = 1;
  } else {
    shamt = 127 - clz(n - 1);
    magic_num = div128_64_small((uint128(1) << shamt) + n - 1, n);
  }
  mod = n;
}
Ejemplo n.º 3
0
   real128& real128::operator /= ( const real128& o )
   { try {
      FC_ASSERT( o.fixed > uint128(0), "Divide by Zero" );
       
      fc::bigint self(fixed);
      fc::bigint other(o.fixed);
      self *= FC_REAL128_PRECISION;
      self /= other;
      fixed = self;

      return *this;
   } FC_CAPTURE_AND_RETHROW( (*this)(o) ) }
Ejemplo n.º 4
0
uint128 RippleAddress::getSeed() const
{
    switch (nVersion) {
    case VER_NONE:
		throw std::runtime_error("unset source - getSeed");

    case VER_FAMILY_SEED:
		return uint128(vchData);

    default:
		throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
    }
}
uint128 STObject::getFieldH128 (SField::ref field) const
{
    const SerializedType* rf = peekAtPField (field);

    if (!rf) throw std::runtime_error ("Field not found");

    SerializedTypeID id = rf->getSType ();

    if (id == STI_NOTPRESENT) return uint128 (); // optional field not present

    const STHash128* cf = dynamic_cast<const STHash128*> (rf);

    if (!cf) throw std::runtime_error ("Wrong field type");

    return cf->getValue ();
}
Ejemplo n.º 6
0
    uint128::operator std::string ()const
    {
      if(*this == 0) { return "0"; }

      // at worst it will be size digits (base 2) so make our buffer
      // that plus room for null terminator
      static char sz [128 + 1];
       sz[sizeof(sz) - 1] = '\0';

      uint128 ii(*this);
      int i = 128 - 1;

      while (ii != 0 && i) {

      uint128 remainder;
      divide(ii, uint128(10), ii, remainder);
          sz [--i] = "0123456789abcdefghijklmnopqrstuvwxyz"[remainder.to_integer()];
      }

      return &sz[i];
    }
Ejemplo n.º 7
0
 friend uint128 operator << ( const uint128& l, const uint128& r )  { return uint128(l)<<=r;  }
Ejemplo n.º 8
0
 uint128::operator bigint()const
 {
    auto tmp  = uint128( bswap_64( hi ), bswap_64( lo ) );
    bigint bi( (char*)&tmp, sizeof(tmp) );
    return bi;
 }
Ejemplo n.º 9
0
 uint128::uint128( const fc::bigint& bi )
 {
    *this = uint128( std::string(bi) ); // TODO: optimize this...
 }
Ejemplo n.º 10
0
 friend uint128 operator + ( const uint128& l, const uint128& r )   { return uint128(l)+=r;   }
Ejemplo n.º 11
0
inline constexpr uint64 operator / (uint64 n, FastDivision<uint64> d) {
  return (uint128(n) * d.magic_num) >> d.shamt;
}
Ejemplo n.º 12
0
 DYND_CUDA_HOST_DEVICE inline uint128 operator-(uint64_t rhs) const
 {
   uint64_t lo = m_lo + ~rhs + 1;
   return uint128(m_hi + 0xffffffffffffffffULL + (lo < m_lo), lo);
 }
Ejemplo n.º 13
0
 friend uint128 operator - ( const uint128& l, const uint128& r )   { return uint128(l)-=r;   }
Ejemplo n.º 14
0
 DYND_CUDA_HOST_DEVICE inline uint128 operator+(uint32_t rhs) const
 {
   uint64_t lo = m_lo + static_cast<uint64_t>(rhs);
   return uint128(m_hi + (lo < m_lo), lo);
 }
Ejemplo n.º 15
0
 DYND_CUDA_HOST_DEVICE inline uint128 operator-(const uint128 &rhs) const
 {
   uint64_t lo = m_lo + ~rhs.m_lo + 1;
   return uint128(m_hi + ~rhs.m_hi + (lo < m_lo), lo);
 }
Ejemplo n.º 16
0
 friend uint128 operator * ( const uint128& l, const uint128& r )   { return uint128(l)*=r;   }
Ejemplo n.º 17
0
 DYND_CUDA_HOST_DEVICE inline uint128 operator+(uint64_t rhs) const
 {
   uint64_t lo = m_lo + rhs;
   return uint128(m_hi + (lo < m_lo), lo);
 }
Ejemplo n.º 18
0
 friend uint128 operator ^ ( const uint128& l, const uint128& r )   { return uint128(l)^=r;   }
Ejemplo n.º 19
0
 friend uint128 operator & ( const uint128& l, const uint128& r )   { return uint128(l)&=r;   }
Ejemplo n.º 20
0
 friend uint128 operator | ( const uint128& l, const uint128& r )   { return uint128(l)=(r);  }
Ejemplo n.º 21
0
 friend uint128 operator % ( const uint128& l, const uint128& r )   { return uint128(l)%=r;   }
Ejemplo n.º 22
0
 friend uint128 operator / ( const uint128& l, const uint128& r )   { return uint128(l)/=r;   }