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

Method QuoInteger

context.go:370–393  ·  view source on GitHub ↗

QuoInteger sets d to the integer part of the quotient x/y. If the result cannot fit in d.Precision digits, an error is returned.

(d, x, y *Decimal)

Source from the content-addressed store, hash-verified

368// QuoInteger sets d to the integer part of the quotient x/y. If the result
369// cannot fit in d.Precision digits, an error is returned.
370func (c *Context) QuoInteger(d, x, y *Decimal) (Condition, error) {
371 if set, res, err := c.quoSpecials(d, x, y, false); set {
372 return res, err
373 }
374
375 // The sign of the result is the exclusive or of the signs of the operands.
376 neg := x.Negative != y.Negative
377 var res Condition
378
379 var tmp BigInt
380 a, b, _, err := upscale(x, y, &tmp)
381 if err != nil {
382 return 0, fmt.Errorf("QuoInteger: %w", err)
383 }
384 d.Coeff.Quo(a, b)
385 d.Form = Finite
386 if d.NumDigits() > int64(c.Precision) {
387 d.Set(decimalNaN)
388 res |= DivisionImpossible
389 }
390 d.Exponent = 0
391 d.Negative = neg
392 return c.goError(res)
393}
394
395// Rem sets d to the remainder part of the quotient x/y. If
396// the integer part cannot fit in d.Precision digits, an error is returned.

Callers 2

RunMethod · 0.45
TestErrDecimalFunction · 0.45

Calls 6

quoSpecialsMethod · 0.95
goErrorMethod · 0.95
upscaleFunction · 0.85
NumDigitsMethod · 0.80
QuoMethod · 0.45
SetMethod · 0.45

Tested by 2

RunMethod · 0.36
TestErrDecimalFunction · 0.36