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 "cmd/compile/internal/big" 9 "fmt" 10 "log" 11 ) 12 13 func ExampleRat_SetString() { 14 r := new(big.Rat) 15 r.SetString("355/113") 16 fmt.Println(r.FloatString(3)) 17 // Output: 3.142 18 } 19 20 func ExampleInt_SetString() { 21 i := new(big.Int) 22 i.SetString("644", 8) // octal 23 fmt.Println(i) 24 // Output: 420 25 } 26 27 func ExampleRat_Scan() { 28 // The Scan function is rarely used directly; 29 // the fmt package recognizes it as an implementation of fmt.Scanner. 30 r := new(big.Rat) 31 _, err := fmt.Sscan("1.5000", r) 32 if err != nil { 33 log.Println("error scanning value:", err) 34 } else { 35 fmt.Println(r) 36 } 37 // Output: 3/2 38 } 39 40 func ExampleInt_Scan() { 41 // The Scan function is rarely used directly; 42 // the fmt package recognizes it as an implementation of fmt.Scanner. 43 i := new(big.Int) 44 _, err := fmt.Sscan("18446744073709551617", i) 45 if err != nil { 46 log.Println("error scanning value:", err) 47 } else { 48 fmt.Println(i) 49 } 50 // Output: 18446744073709551617 51 } 52