本文整理汇总了C++中ObNumber::is_negative方法的典型用法代码示例。如果您正苦于以下问题:C++ ObNumber::is_negative方法的具体用法?C++ ObNumber::is_negative怎么用?C++ ObNumber::is_negative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObNumber
的用法示例。
在下文中一共展示了ObNumber::is_negative方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: div
int ObNumber::div(const ObNumber &other, ObNumber &res) const
{
int ret = OB_SUCCESS;
res.set_zero();
if (other.is_zero())
{
jlog(WARNING, "divisor is zero");
ret = JD_DIVISION_BY_ZERO;
}
else if (!this->is_zero())
{
res.vscale_ = QUOTIENT_SCALE;
ObNumber dividend = *this;
ObNumber divisor = other;
ObNumber remainder;
bool res_is_neg = false;
if (dividend.is_negative())
{
negate(dividend, dividend);
res_is_neg = true;
}
if (dividend.vscale_ > DOUBLE_PRECISION_NDIGITS)
{
dividend.round_fraction_part(DOUBLE_PRECISION_NDIGITS);
}
if (divisor.vscale_ > SINGLE_PRECISION_NDIGITS)
{
divisor.round_fraction_part(SINGLE_PRECISION_NDIGITS);
}
if (dividend.vscale_ < divisor.vscale_
|| res.vscale_ > dividend.vscale_ - divisor.vscale_)
{
if (OB_SUCCESS != (ret = dividend.left_shift(static_cast<int8_t> (res.vscale_ + divisor.vscale_ - dividend.vscale_), true)))
{
jlog(WARNING, "left shift overflow, err=%d res_vscale=%hhd other_vscale=%hhd this_vscale=%hhd",
ret, res.vscale_, divisor.vscale_, dividend.vscale_);
}
}
if (OB_LIKELY(OB_SUCCESS == ret))
{
if (divisor.is_negative())
{
negate(divisor, divisor);
res_is_neg = !res_is_neg;
}
divisor.remove_leading_zeroes_unsigned();
div_words(dividend, divisor, res, remainder);
if (OB_UNLIKELY(res_is_neg))
{
negate(res, res);
}
res.remove_leading_zeroes();
}
}
return ret;
}
示例2: 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;
}
示例3: 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;
}