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

Function ExampleContext_overflow

example_test.go:24–43  ·  view source on GitHub ↗

ExampleOverflow demonstrates how to detect or error on overflow.

()

Source from the content-addressed store, hash-verified

22
23// ExampleOverflow demonstrates how to detect or error on overflow.
24func ExampleContext_overflow() {
25 // Create a context that will overflow at 1e3.
26 c := apd.Context{
27 MaxExponent: 2,
28 Traps: apd.Overflow,
29 }
30 one := apd.New(1, 0)
31 d := apd.New(997, 0)
32 for {
33 res, err := c.Add(d, d, one)
34 fmt.Printf("d: %8s, overflow: %5v, err: %v\n", d, res.Overflow(), err)
35 if err != nil {
36 return
37 }
38 }
39 // Output:
40 // d: 998, overflow: false, err: <nil>
41 // d: 999, overflow: false, err: <nil>
42 // d: Infinity, overflow: true, err: overflow
43}
44
45// ExampleInexact demonstrates how to detect inexact operations.
46func ExampleContext_inexact() {

Callers

nothing calls this directly

Calls 2

AddMethod · 0.95
OverflowMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…