File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright 2012 The Go Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style
3+ // license that can be found in the LICENSE file.
4+
5+ package big_test
6+
7+ import (
8+ "fmt"
9+ "log"
10+ "math/big"
11+ )
12+
13+ // 3.142
14+ func ExampleRat_SetString () {
15+ r := new (big.Rat )
16+ r .SetString ("355/113" )
17+ fmt .Println (r .FloatString (3 ))
18+ }
19+
20+ // 420
21+ func ExampleInt_SetString () {
22+ i := new (big.Int )
23+ i .SetString ("644" , 8 ) // octal
24+ fmt .Println (i )
25+ }
26+
27+ // 3/2
28+ func ExampleRat_Scan () {
29+ // The Scan function is rarely used directly;
30+ // the fmt package recognizes it as an implementation of fmt.Scanner.
31+ r := new (big.Rat )
32+ _ , err := fmt .Sscan ("1.5000" , r )
33+ if err != nil {
34+ log .Println ("error scanning value:" , err )
35+ } else {
36+ fmt .Println (r )
37+ }
38+ }
39+
40+ // 18446744073709551617
41+ func ExampleInt_Scan () {
42+ // The Scan function is rarely used directly;
43+ // the fmt package recognizes it as an implementation of fmt.Scanner.
44+ i := new (big.Int )
45+ _ , err := fmt .Sscan ("18446744073709551617" , i )
46+ if err != nil {
47+ log .Println ("error scanning value:" , err )
48+ } else {
49+ fmt .Println (i )
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments