当前位置: 首页>>代码示例>>C++>>正文


C++ ObNumber类代码示例

本文整理汇总了C++中ObNumber的典型用法代码示例。如果您正苦于以下问题:C++ ObNumber类的具体用法?C++ ObNumber怎么用?C++ ObNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ObNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

inline void ObNumber::div_uint32(const ObNumber &dividend, uint32_t divisor, ObNumber &quotient, ObNumber &remainder)
{
    OB_ASSERT(0 < dividend.nwords_);
    OB_ASSERT(MAX_NWORDS >= dividend.nwords_);
    OB_ASSERT(0 < divisor);
    int64_t carry = 0;
    for (int i = dividend.nwords_ - 1; i >= 0; --i)
    {
        carry = carry * BASE + dividend.words_[i];
        quotient.words_[i] = static_cast<uint32_t> (carry / divisor);
        carry = carry % divisor;
    }
    quotient.nwords_ = dividend.nwords_;
    quotient.remove_leading_zeroes();

    if (0 == carry)
    {
        remainder.set_zero(); // remainder is zero
    }
    else
    {
        remainder.words_[0] = static_cast<uint32_t> (carry);
        remainder.nwords_ = 1;
    }
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:25,代码来源:ob_number.cpp

示例2: int_decimal

 static int int_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObIntType);
     ObNumber num;
     num.from(in.get_int());
     out.set_decimal(num); // @todo optimize
     return OB_SUCCESS;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:9,代码来源:ob_obj_cast.cpp

示例3: mtime_decimal

 static int mtime_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     ObNumber num;
     num.from(static_cast<int64_t> (in.get_mtime()));
     out.set_decimal(num);
     return OB_SUCCESS;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:9,代码来源:ob_obj_cast.cpp

示例4: switch

void ObObj::print_value(FILE* fd)
{
  switch (get_type())
  {
    case ObNullType:
      fprintf(fd, "nil");
      break;
    case ObIntType:
      fprintf(fd, "%ld", value_.int_val);
      break;
    case ObVarcharType:
      fprintf(fd, "%.*s", val_len_, value_.varchar_val);
      break;
    case ObFloatType:
      fprintf(fd, "%2f", value_.float_val);
      break;
    case ObDoubleType:
      fprintf(fd, "%2lf", value_.double_val);
      break;
    case ObDateTimeType:
      fprintf(fd, "%s", time2str(value_.time_val));
      break;
    case ObPreciseDateTimeType:
      fprintf(fd, "%s", time2str(value_.precisetime_val));
      break;
    case ObModifyTimeType:
      fprintf(fd, "%s", time2str(value_.modifytime_val));
      break;
    case ObCreateTimeType:
      fprintf(fd, "%s", time2str(value_.createtime_val));
      break;
    case ObSeqType:
      fprintf(fd, "seq");
      break;
    case ObExtendType:
      fprintf(fd, "%lde", value_.ext_val);
      break;
    case ObBoolType:
      fprintf(fd, "%c", value_.bool_val ? 'Y': 'N');
      break;
    case ObDecimalType:
      {
        char num_buf[ObNumber::MAX_PRINTABLE_SIZE];
        ObNumber num;
        get_decimal(num);
        num.to_string(num_buf, ObNumber::MAX_PRINTABLE_SIZE);
        fprintf(fd, "%s", num_buf);
        break;
      }
    default:
      break;
  }
}
开发者ID:Alibaba-boonya,项目名称:oceanbase,代码行数:53,代码来源:ob_object.cpp

示例5: is_negative

int ObNumber::cast_to_int64(int64_t &i64) const
{
    int ret = OB_SUCCESS;
    i64 = 0;
    bool is_neg = is_negative();
    ObNumber pos_clone = *this;
    if (is_neg)
    {
        negate(*this, pos_clone);
    }

    ObNumber remainder;
    int vscale = vscale_;
    int digits[DOUBLE_PRECISION_NDIGITS];
    int digit_idx = DOUBLE_PRECISION_NDIGITS - 1;
    while (!pos_clone.is_zero())
    {
        div_uint32(pos_clone, 10, pos_clone, remainder);
        if (vscale > 0)
        {
            vscale--;
        }
        else
        {
            OB_ASSERT(digit_idx >= 0);
            if (remainder.is_zero())
            {
                digits[digit_idx--] = 0;
            }
            else
            {
                OB_ASSERT(1 == remainder.nwords_);
                OB_ASSERT(remainder.words_[0] < 10 && remainder.words_[0] > 0);
                digits[digit_idx--] = remainder.words_[0];
            }
        } // end while
    }
    OB_ASSERT(digit_idx >= -1);
    for (int i = digit_idx + 1; i < DOUBLE_PRECISION_NDIGITS; ++i)
    {
        i64 = i64 * 10 + digits[i];
    }
    if (is_neg)
    {
        i64 = -i64;
    }
    return ret;
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:48,代码来源:ob_number.cpp

示例6: set_flag

int ObObj::set_decimal(const ObNumber &num, int8_t precision, int8_t scale, bool is_add /*= false*/)
{
  int ret = OB_SUCCESS;
  set_flag(is_add);
  meta_.type_ = ObDecimalType;
  meta_.dec_precision_ = static_cast<uint8_t>(precision) & META_PREC_MASK;
  meta_.dec_scale_ = static_cast<uint8_t>(scale) & META_SCALE_MASK;
  int8_t nwords = 0;
  int8_t vscale = 0;
  uint32_t words[ObNumber::MAX_NWORDS];
  ret = num.round_to(precision, scale, nwords, vscale, words);
  if (OB_SUCCESS == ret)
  {
    if (nwords <= 3)
    {
      meta_.dec_nwords_ = static_cast<uint8_t>(nwords - 1) & META_NWORDS_MASK;
      meta_.dec_vscale_ = static_cast<uint8_t>(vscale) & META_VSCALE_MASK;
      memcpy(reinterpret_cast<uint32_t*>(&val_len_), words, sizeof(uint32_t)*nwords);
    }
    else
    {
      //@todo, use ob_pool.h to allocate memory
      ret = OB_NOT_IMPLEMENT;
    }
  }
  return ret;
}
开发者ID:Alibaba-boonya,项目名称:oceanbase,代码行数:27,代码来源:ob_object.cpp

示例7: negate

int ObNumber::negate(ObNumber &res) const
{
    int ret = OB_SUCCESS;
    if (this->nwords_ >= MAX_NWORDS)
    {
        jlog(WARNING, "value out of range to do negate");
        ret = JD_VALUE_OUT_OF_RANGE;
    }
    else
    {
        res = *this;
        res.extend_words(static_cast<int8_t> (this->nwords_ + 1));
        negate(res, res);
        res.remove_leading_zeroes();
    }
    return ret;
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:17,代码来源:ob_number.cpp

示例8: OB_ASSERT

int ObNumber::round_to(int8_t precision, int8_t scale, int8_t &nwords, int8_t &vscale, uint32_t *words) const
{
    OB_ASSERT(precision >= scale && 0 <= scale && NULL != words);
    int ret = OB_SUCCESS;
    ObNumber clone = *this;
    bool is_neg = is_negative();
    if (is_neg)
    {
        negate(clone, clone);
    }
    if (clone.vscale_ > scale)
    {
        clone.right_shift(static_cast<int8_t> (clone.vscale_ - scale));
        clone.remove_leading_zeroes();
    }
    ObNumber clone_clone = clone;
    int8_t vprec = 0;
    ObNumber remainder;
    while (!clone_clone.is_zero())
    {
        div_uint32(clone_clone, 10, clone_clone, remainder);
        clone_clone.remove_leading_zeroes();
        ++vprec;
    }
    if (vprec > precision)
    {
        ret = JD_VALUE_OUT_OF_RANGE;
        jlog(WARNING, "value is not representable with the precision and scale, p=%hhd s=%hhd vp=%hhd vs=%hhd",
                precision, scale, vprec, this->vscale_);
    }
    else
    {
        if (is_neg)
        {
            negate(clone, clone);
        }
        nwords = clone.nwords_;
        vscale = clone.vscale_;
        for (int8_t i = 0; i < clone.nwords_; ++i)
        {
            words[i] = clone.words_[i];
        }
    }
    return ret;
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:45,代码来源:ob_number.cpp

示例9: varchar_decimal

 static int varchar_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     const string &varchar = in.get_varchar();
     ObNumber num;
     if (OB_SUCCESS != (ret = num.from(varchar.data(), varchar.length())))
     {
         jlog(WARNING, "failed to convert varchar to decimal, err=%d varchar=%.*s",
                 ret, varchar.length(), varchar.data());
     }
     else
     {
         out.set_decimal(num); // @todo optimize
     }
     return OB_SUCCESS;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:18,代码来源:ob_obj_cast.cpp

示例10: compare

int ObNumber::compare(const ObNumber &other) const
{
    int ret = 0;
    ObNumber res;
    if (OB_SUCCESS != this->sub(other, res))
    {
        // return 0 even if error occur
    }
    else if (res.is_negative())
    {
        ret = -1;
    }
    else if (!res.is_zero())
    {
        ret = 1;
    }
    return ret;
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:18,代码来源:ob_number.cpp

示例11: double_decimal

 static int double_decimal(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDoubleType);
     static const int64_t MAX_DOUBLE_PRINT_SIZE = 64;
     char buf[MAX_DOUBLE_PRINT_SIZE];
     snprintf(buf, MAX_DOUBLE_PRINT_SIZE, "%f", in.get_double());
     ObNumber num;
     if (OB_SUCCESS != (ret = num.from(buf)))
     {
         jlog(WARNING, "failed to convert float to decimal, err=%d", ret);
     }
     else
     {
         out.set_decimal(num);
     }
     return ret;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:19,代码来源:ob_obj_cast.cpp

示例12: round_fraction_part

void ObNumber::round_fraction_part(int8_t scale)
{
    ObNumber *clone = this;
    ObNumber neg_this;
    bool is_neg = is_negative();
    if (is_neg)
    {
        negate(*this, neg_this);
        clone = &neg_this;
    }
    if (vscale_ > scale)
    {
        clone->right_shift(static_cast<int8_t> (vscale_ - scale));
    }
    if (is_neg)
    {
        negate(*clone, *this);
    }
    remove_leading_zeroes();
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:20,代码来源:ob_number.cpp

示例13: get_decimal

int ObObj::get_decimal(ObNumber &num, bool &is_add) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (ObDecimalType == meta_.type_)
  {
    ret = OB_SUCCESS;
    is_add = (ADD == meta_.op_flag_);
    int8_t nwords = static_cast<int8_t>(meta_.dec_nwords_ + 1);
    int8_t vscale = meta_.dec_vscale_;
    if (nwords <= 3)
    {
      num.from(vscale, nwords, reinterpret_cast<const uint32_t*>(&val_len_));
    }
    else
    {
      num.from(vscale, nwords, value_.dec_words_);
    }
  }
  return ret;
}
开发者ID:Alibaba-boonya,项目名称:oceanbase,代码行数:20,代码来源:ob_object.cpp

示例14: add

int ObNumber::add(const ObNumber &other, ObNumber &res) const
{
    int ret = OB_SUCCESS;
    res.set_zero();
    ObNumber n1 = *this;
    ObNumber n2 = other;
    if (n1.vscale_ > SINGLE_PRECISION_NDIGITS)
    {
        n1.round_fraction_part(SINGLE_PRECISION_NDIGITS);
    }
    if (n2.vscale_ > SINGLE_PRECISION_NDIGITS)
    {
        n2.round_fraction_part(SINGLE_PRECISION_NDIGITS);
    }
    int8_t res_nwords = static_cast<int8_t> (std::max(n1.nwords_, n2.nwords_) + 1);
    if (res_nwords > MAX_NWORDS)
    {
        jlog(WARNING, "number out of range");
        ret = JD_VALUE_OUT_OF_RANGE;
    }
    else
    {
        n1.extend_words(res_nwords);
        n2.extend_words(res_nwords);
    }
    if (n1.vscale_ > n2.vscale_)
    {
        ret = n2.left_shift(static_cast<int8_t> (n1.vscale_ - n2.vscale_), false);
    }
    else if (n1.vscale_ < n2.vscale_)
    {
        ret = n1.left_shift(static_cast<int8_t> (n2.vscale_ - n1.vscale_), false);
    }
    if (OB_SUCCESS == ret)
    {
        add_words(n1, n2, res);
        res.remove_leading_zeroes();
    }
    return ret;
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:40,代码来源:ob_number.cpp

示例15: mul

int ObNumber::mul(const ObNumber &other, ObNumber &res) const
{
    int ret = OB_SUCCESS;
    res.set_zero();
    if (!this->is_zero() && !other.is_zero())
    {
        ObNumber multiplicand = *this;
        ObNumber multiplier = other;
        bool res_is_neg = false;
        if (multiplicand.is_negative())
        {
            negate(multiplicand, multiplicand);
            res_is_neg = true;
        }
        if (multiplier.is_negative())
        {
            negate(multiplier, multiplier);
            res_is_neg = !res_is_neg;
        }
        if (multiplicand.vscale_ > SINGLE_PRECISION_NDIGITS)
        {
            multiplicand.round_fraction_part(SINGLE_PRECISION_NDIGITS);
        }
        if (multiplier.vscale_ > SINGLE_PRECISION_NDIGITS)
        {
            multiplier.round_fraction_part(SINGLE_PRECISION_NDIGITS);
        }
        res.vscale_ = static_cast<int8_t> (multiplicand.vscale_ + multiplier.vscale_);
        ret = mul_words(multiplicand, multiplier, res);
        res.remove_leading_zeroes();
        if (res_is_neg)
        {
            negate(res, res);
        }
    }
    return ret;
}
开发者ID:taotaochanghe,项目名称:sql_parser,代码行数:37,代码来源:ob_number.cpp


注:本文中的ObNumber类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。