本文整理汇总了C++中ObNumber::from方法的典型用法代码示例。如果您正苦于以下问题:C++ ObNumber::from方法的具体用法?C++ ObNumber::from怎么用?C++ ObNumber::from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObNumber
的用法示例。
在下文中一共展示了ObNumber::from方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mtime_decimal
static int mtime_decimal(const ObObjCastParams ¶ms, 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;
}
示例2: int_decimal
static int int_decimal(const ObObjCastParams ¶ms, 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;
}
示例3: 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;
}
示例4: varchar_decimal
static int varchar_decimal(const ObObjCastParams ¶ms, 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;
}
示例5: double_decimal
static int double_decimal(const ObObjCastParams ¶ms, 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;
}
示例6: knuth_div_unsigned
void ObNumber::knuth_div_unsigned(const uint32_t *dividend,
const ObNumber &divisor,
ObNumber "ient, int8_t qidx, ObNumber &remainder)
{
OB_ASSERT(divisor.words_[divisor.nwords_ - 1] >= HALF_BASE); // (BASE ^ divisor_n)/2 <= divisor
OB_ASSERT(0 <= qidx && qidx < MAX_NWORDS);
ObNumber cdividend;
cdividend.nwords_ = static_cast<int8_t> (divisor.nwords_ + 1);
for (int8_t i = 0; i < cdividend.nwords_; ++i)
{
cdividend.words_[i] = dividend[i];
}
ObNumber base;
base.from(BASE);
ObNumber p;
mul_words(base, divisor, p);
p.remove_leading_zeroes_unsigned();
int cmp = compare_words_unsigned(cdividend, p);
if (cmp >= 0)
{
sub_words_unsigned(cdividend, p, cdividend);
knuth_div_unsigned(cdividend.words_, divisor, quotient, qidx, remainder); // recursively called at most once
quotient.words_[qidx + 1] = 1;
}
else
{
int8_t n = divisor.nwords_;
uint64_t q = (UBASE * dividend[n] + dividend[n - 1]) / divisor.words_[n - 1];
if (q >= UBASE)
{
q = UBASE - 1;
}
ObNumber Q;
Q.from(q);
ObNumber T;
mul_words(Q, divisor, T);
T.remove_leading_zeroes_unsigned();
for (int i = 0; i < 2; ++i)
{
cmp = compare_words_unsigned(T, cdividend);
if (cmp > 0)
{
Q.from(--q);
sub_words_unsigned(T, divisor, T);
}
else
{
break;
}
} // end for
if (Q.nwords_ == 1)
{
quotient.words_[qidx] = Q.words_[0];
}
else
{
OB_ASSERT(Q.is_zero());
quotient.words_[qidx] = 0;
}
sub_words_unsigned(cdividend, T, remainder);
}
}