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

Method Rem

context.go:397–438  ·  view source on GitHub ↗

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

(d, x, y *Decimal)

Source from the content-addressed store, hash-verified

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.
397func (c *Context) Rem(d, x, y *Decimal) (Condition, error) {
398 if c.shouldSetAsNaN(x, y) {
399 return c.setAsNaN(d, x, y)
400 }
401
402 if x.Form != Finite {
403 d.Set(decimalNaN)
404 return c.goError(InvalidOperation)
405 }
406 if y.Form == Infinite {
407 d.Set(x)
408 return 0, nil
409 }
410
411 var res Condition
412 if y.IsZero() {
413 if x.IsZero() {
414 res |= DivisionUndefined
415 } else {
416 res |= InvalidOperation
417 }
418 d.Set(decimalNaN)
419 return c.goError(res)
420 }
421 var tmp1 BigInt
422 a, b, s, err := upscale(x, y, &tmp1)
423 if err != nil {
424 return 0, fmt.Errorf("Rem: %w", err)
425 }
426 var tmp2 BigInt
427 tmp2.QuoRem(a, b, &d.Coeff)
428 if NumDigits(&tmp2) > int64(c.Precision) {
429 d.Set(decimalNaN)
430 return c.goError(DivisionImpossible)
431 }
432 d.Form = Finite
433 d.Exponent = s
434 // The sign of the result is sign if the dividend.
435 d.Negative = x.Negative
436 res |= c.round(d, d)
437 return c.goError(res)
438}
439
440func (c *Context) rootSpecials(d, x *Decimal, factor int32) (bool, Condition, error) {
441 if c.shouldSetAsNaN(x, nil) {

Callers

nothing calls this directly

Calls 9

shouldSetAsNaNMethod · 0.95
setAsNaNMethod · 0.95
goErrorMethod · 0.95
QuoRemMethod · 0.95
roundMethod · 0.95
upscaleFunction · 0.85
NumDigitsFunction · 0.85
IsZeroMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected