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

Function ExampleErrDecimal

example_test.go:89–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87}
88
89func ExampleErrDecimal() {
90 c := apd.BaseContext.WithPrecision(5)
91 ed := apd.MakeErrDecimal(c)
92 d := apd.New(10, 0)
93 fmt.Printf("%s, err: %v\n", d, ed.Err())
94 ed.Add(d, d, apd.New(2, 1)) // add 20
95 fmt.Printf("%s, err: %v\n", d, ed.Err())
96 ed.Quo(d, d, apd.New(0, 0)) // divide by zero
97 fmt.Printf("%s, err: %v\n", d, ed.Err())
98 ed.Sub(d, d, apd.New(1, 0)) // attempt to subtract 1
99 // The subtraction doesn't occur and doesn't change the error.
100 fmt.Printf("%s, err: %v\n", d, ed.Err())
101 // Output:
102 // 10, err: <nil>
103 // 30, err: <nil>
104 // Infinity, err: division by zero
105 // Infinity, err: division by zero
106}
107
108// ExampleRoundToIntegralExact demonstrates how to use RoundToIntegralExact to
109// check if a number is an integer or not. Note the variations between integer

Callers

nothing calls this directly

Calls 5

WithPrecisionMethod · 0.80
ErrMethod · 0.80
AddMethod · 0.45
QuoMethod · 0.45
SubMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…