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

Function Add

cpp/src/gandiva/precompiled/decimal_ops.cc:211–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211BasicDecimal128 Add(const BasicDecimalScalar128& x, const BasicDecimalScalar128& y,
212 int32_t out_precision, int32_t out_scale) {
213 if (out_precision < DecimalTypeUtil::kMaxPrecision) {
214 // fast-path add
215 return AddFastPath(x, y, out_scale);
216 } else {
217 int32_t min_lz = MinLeadingZeros(x, y);
218 if (min_lz >= 3) {
219 // If both numbers have at least MIN_LZ leading zeros, we can add them directly
220 // without the risk of overflow.
221 // We want the result to have at least 2 leading zeros, which ensures that it fits
222 // into the maximum decimal because 2^126 - 1 < 10^38 - 1. If both x and y have at
223 // least 3 leading zeros, then we are guaranteed that the result will have at lest 2
224 // leading zeros.
225 return AddNoOverflow(x, y, out_scale);
226 } else {
227 // slower-version : add whole/fraction parts separately, and then, combine.
228 return AddLarge(x, y, out_scale);
229 }
230 }
231}
232
233BasicDecimal128 Subtract(const BasicDecimalScalar128& x, const BasicDecimalScalar128& y,
234 int32_t out_precision, int32_t out_scale) {

Callers 5

VerifyMethod · 0.70
SubtractFunction · 0.70
BuildMethod · 0.50
RegisterMethod · 0.50

Calls 4

AddFastPathFunction · 0.85
MinLeadingZerosFunction · 0.85
AddNoOverflowFunction · 0.85
AddLargeFunction · 0.85

Tested by 1

VerifyMethod · 0.56