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

Method rootSpecials

context.go:440–468  ·  view source on GitHub ↗
(d, x *Decimal, factor int32)

Source from the content-addressed store, hash-verified

438}
439
440func (c *Context) rootSpecials(d, x *Decimal, factor int32) (bool, Condition, error) {
441 if c.shouldSetAsNaN(x, nil) {
442 res, err := c.setAsNaN(d, x, nil)
443 return true, res, err
444 }
445 if x.Form == Infinite {
446 if x.Negative {
447 d.Set(decimalNaN)
448 res, err := c.goError(InvalidOperation)
449 return true, res, err
450 }
451 d.Set(decimalInfinity)
452 return true, 0, nil
453 }
454
455 switch x.Sign() {
456 case -1:
457 if factor%2 == 0 {
458 d.Set(decimalNaN)
459 res, err := c.goError(InvalidOperation)
460 return true, res, err
461 }
462 case 0:
463 d.Set(x)
464 d.Exponent /= factor
465 return true, 0, nil
466 }
467 return false, 0, nil
468}
469
470// Sqrt sets d to the square root of x. Sqrt uses the Babylonian method
471// for computing the square root, which uses O(log p) steps for p digits

Callers 2

SqrtMethod · 0.95
CbrtMethod · 0.95

Calls 5

shouldSetAsNaNMethod · 0.95
setAsNaNMethod · 0.95
goErrorMethod · 0.95
SetMethod · 0.45
SignMethod · 0.45

Tested by

no test coverage detected