ExampleInexact demonstrates how to detect inexact operations.
()
| 44 | |
| 45 | // ExampleInexact demonstrates how to detect inexact operations. |
| 46 | func 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 | |
| 67 | func ExampleContext_Quantize() { |
| 68 | input, _, _ := apd.NewFromString("123.45") |
nothing calls this directly
no test coverage detected
searching dependent graphs…