| 329 | } |
| 330 | |
| 331 | BasicDecimal128 Multiply(const BasicDecimalScalar128& x, const BasicDecimalScalar128& y, |
| 332 | int32_t out_precision, int32_t out_scale, bool* overflow) { |
| 333 | BasicDecimal128 result; |
| 334 | *overflow = false; |
| 335 | if (out_precision < DecimalTypeUtil::kMaxPrecision) { |
| 336 | // fast-path multiply |
| 337 | result = x.value() * y.value(); |
| 338 | DCHECK_EQ(x.scale() + y.scale(), out_scale); |
| 339 | DCHECK_LE(BasicDecimal128::Abs(result), BasicDecimal128::GetMaxValue()); |
| 340 | } else if (x.value() == 0 || y.value() == 0) { |
| 341 | // Handle this separately to avoid divide-by-zero errors. |
| 342 | result = BasicDecimal128(0, 0); |
| 343 | } else { |
| 344 | result = MultiplyMaxPrecision(x, y, out_scale, overflow); |
| 345 | } |
| 346 | DCHECK(*overflow || BasicDecimal128::Abs(result) <= BasicDecimal128::GetMaxValue()); |
| 347 | return result; |
| 348 | } |
| 349 | |
| 350 | BasicDecimal128 Divide(int64_t context, const BasicDecimalScalar128& x, |
| 351 | const BasicDecimalScalar128& y, int32_t out_precision, |