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; }
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(); }