MCPcopy Create free account
hub / github.com/cockroachdb/apd / upscale

Function upscale

decimal.go:385–408  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
385func 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.
411func (d *Decimal) setBig(b *BigInt) *BigInt {

Callers 4

addMethod · 0.85
QuoIntegerMethod · 0.85
RemMethod · 0.85
TestUpscaleFunction · 0.85

Calls 2

tableExp10Function · 0.85
MulMethod · 0.45

Tested by 1

TestUpscaleFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…