upscale converts a and b to BigInts with the same scaling. It returns them with this scaling, along with the scaling. An error can be produced if the resulting scale factor is out of range. The tmp argument must be provided and can be (but won't always be) one of the return values.
(a, b *Decimal, tmp *BigInt)
| 383 | // if the resulting scale factor is out of range. The tmp argument must be |
| 384 | // provided and can be (but won't always be) one of the return values. |
| 385 | func upscale(a, b *Decimal, tmp *BigInt) (*BigInt, *BigInt, int32, error) { |
| 386 | if a.Exponent == b.Exponent { |
| 387 | return &a.Coeff, &b.Coeff, a.Exponent, nil |
| 388 | } |
| 389 | swapped := false |
| 390 | if a.Exponent < b.Exponent { |
| 391 | swapped = true |
| 392 | b, a = a, b |
| 393 | } |
| 394 | s := int64(a.Exponent) - int64(b.Exponent) |
| 395 | // TODO(mjibson): figure out a better way to upscale numbers with highly |
| 396 | // differing exponents. |
| 397 | if s > MaxExponent { |
| 398 | return nil, nil, 0, errors.New(errExponentOutOfRangeStr) |
| 399 | } |
| 400 | x := tmp |
| 401 | e := tableExp10(s, x) |
| 402 | x.Mul(&a.Coeff, e) |
| 403 | y := &b.Coeff |
| 404 | if swapped { |
| 405 | x, y = y, x |
| 406 | } |
| 407 | return x, y, b.Exponent, nil |
| 408 | } |
| 409 | |
| 410 | // setBig sets b to d's coefficient with negative. |
| 411 | func (d *Decimal) setBig(b *BigInt) *BigInt { |
searching dependent graphs…