Mul returns d * d2.
(d2 Decimal)
| 556 | |
| 557 | // Mul returns d * d2. |
| 558 | func (d Decimal) Mul(d2 Decimal) Decimal { |
| 559 | d.ensureInitialized() |
| 560 | d2.ensureInitialized() |
| 561 | |
| 562 | expInt64 := int64(d.exp) + int64(d2.exp) |
| 563 | if expInt64 > math.MaxInt32 || expInt64 < math.MinInt32 { |
| 564 | // NOTE(vadim): better to panic than give incorrect results, as |
| 565 | // Decimals are usually used for money |
| 566 | panic(fmt.Sprintf("exponent %v overflows an int32!", expInt64)) |
| 567 | } |
| 568 | |
| 569 | d3Value := new(big.Int).Mul(d.value, d2.value) |
| 570 | return Decimal{ |
| 571 | value: d3Value, |
| 572 | exp: int32(expInt64), |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | // Shift shifts the decimal in base 10. |
| 577 | // It shifts left when shift is positive and right if shift is negative. |