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

Function ReduceScaleBy

cpp/src/gandiva/decimal_xlarge.cc:167–183  ·  view source on GitHub ↗

divide input by 10^reduce_by, and round up the fractional part.

Source from the content-addressed store, hash-verified

165
166// divide input by 10^reduce_by, and round up the fractional part.
167static int256_t ReduceScaleBy(int256_t in, int32_t reduce_by) {
168 if (reduce_by == 0) {
169 // nothing to do.
170 return in;
171 }
172
173 int256_t divisor = GetScaleMultiplier(reduce_by);
174 DCHECK_GT(divisor, 0);
175 DCHECK_EQ(divisor % 2, 0); // multiple of 10.
176 auto result = in / divisor;
177 auto remainder = in % divisor;
178 // round up (same as BasicDecimal128::ReduceScaleBy)
179 if (abs(remainder) >= (divisor >> 1)) {
180 result += (in > 0 ? 1 : -1);
181 }
182 return result;
183}
184
185// multiply input by 10^increase_by.
186static int256_t IncreaseScaleBy(int256_t in, int32_t increase_by) {

Callers 1

Calls 1

GetScaleMultiplierFunction · 0.85

Tested by

no test coverage detected