MCPcopy Create free account
hub / github.com/apache/arrow / ReduceScaleBy

Method ReduceScaleBy

cpp/src/arrow/util/basic_decimal.cc:121–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121BasicDecimal32 BasicDecimal32::ReduceScaleBy(int32_t reduce_by, bool round) const {
122 DCHECK_GE(reduce_by, 0);
123 DCHECK_LE(reduce_by, kMaxScale);
124
125 if (reduce_by == 0) {
126 return *this;
127 }
128
129 BasicDecimal32 divisor(DecimalTraits<BasicDecimal32>::powers_of_ten()[reduce_by]);
130 BasicDecimal32 result;
131 BasicDecimal32 remainder;
132 auto s = Divide(divisor, &result, &remainder);
133 DCHECK_EQ(s, DecimalStatus::kSuccess);
134 if (round) {
135 auto divisor_half = DecimalTraits<BasicDecimal32>::half_powers_of_ten()[reduce_by];
136 if (remainder.Abs() >= divisor_half) {
137 result += Sign();
138 }
139 }
140 return result;
141}
142
143const BasicDecimal32& BasicDecimal32::GetScaleMultiplier(int32_t scale) {
144 DCHECK_GE(scale, 0);

Callers 12

TYPED_TESTFunction · 0.80
TESTFunction · 0.80
CallMethod · 0.80
CallMethod · 0.80
CallMethod · 0.80
MultiplyMethod · 0.80
RoundMethod · 0.80
RoundMethod · 0.80
TEST_FFunction · 0.80
CheckAndReduceScaleFunction · 0.80
ModifyScaleAndPrecisionFunction · 0.80

Calls 3

AbsMethod · 0.80
DivideFunction · 0.70
SignFunction · 0.70

Tested by 3

TYPED_TESTFunction · 0.64
TESTFunction · 0.64
TEST_FFunction · 0.64