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

Function makeConstWithPrecision

const.go:63–87  ·  view source on GitHub ↗
(strVal string)

Source from the content-addressed store, hash-verified

61}
62
63func makeConstWithPrecision(strVal string) *constWithPrecision {
64 c := &constWithPrecision{}
65 if _, _, err := c.unrounded.SetString(strVal); err != nil {
66 panic(err)
67 }
68 // The length of the string might be one higher than the available precision
69 // (because of the decimal point), but that's ok.
70 maxPrec := uint32(len(strVal))
71 for p := uint32(1); p < maxPrec; p *= 2 {
72 var d Decimal
73
74 ctx := Context{
75 Precision: p,
76 Rounding: RoundHalfUp,
77 MaxExponent: MaxExponent,
78 MinExponent: MinExponent,
79 }
80 _, err := ctx.Round(&d, &c.unrounded)
81 if err != nil {
82 panic(err)
83 }
84 c.vals = append(c.vals, d)
85 }
86 return c
87}
88
89// get returns the given constant, rounded down to a precision at least as high
90// as the given precision.

Callers 2

const.goFile · 0.85
TestConstWithPrecisionFunction · 0.85

Calls 2

RoundMethod · 0.95
SetStringMethod · 0.45

Tested by 1

TestConstWithPrecisionFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…