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

Function ExampleContext_inexact

example_test.go:46–65  ·  view source on GitHub ↗

ExampleInexact demonstrates how to detect inexact operations.

()

Source from the content-addressed store, hash-verified

44
45// ExampleInexact demonstrates how to detect inexact operations.
46func ExampleContext_inexact() {
47 d := apd.New(27, 0)
48 three := apd.New(3, 0)
49 c := apd.BaseContext.WithPrecision(5)
50 for {
51 res, err := c.Quo(d, d, three)
52 fmt.Printf("d: %7s, inexact: %5v, err: %v\n", d, res.Inexact(), err)
53 if err != nil {
54 return
55 }
56 if res.Inexact() {
57 return
58 }
59 }
60 // Output:
61 // d: 9.0000, inexact: false, err: <nil>
62 // d: 3.0000, inexact: false, err: <nil>
63 // d: 1.0000, inexact: false, err: <nil>
64 // d: 0.33333, inexact: true, err: <nil>
65}
66
67func ExampleContext_Quantize() {
68 input, _, _ := apd.NewFromString("123.45")

Callers

nothing calls this directly

Calls 3

WithPrecisionMethod · 0.80
InexactMethod · 0.80
QuoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…