github.com/rsc/tmp@v0.0.0-20240517235954-6deaab19748b/bootstrap/internal/gc/big/example_test.go (about) 1 // Do not edit. Bootstrap copy of /Users/rsc/g/go/src/cmd/internal/gc/big/example_test.go 2 3 // Copyright 2012 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package big_test 8 9 import ( 10 "fmt" 11 "log" 12 "math/big" 13 ) 14 15 func ExampleRat_SetString() { 16 r := new(big.Rat) 17 r.SetString("355/113") 18 fmt.Println(r.FloatString(3)) 19 // Output: 3.142 20 } 21 22 func ExampleInt_SetString() { 23 i := new(big.Int) 24 i.SetString("644", 8) // octal 25 fmt.Println(i) 26 // Output: 420 27 } 28 29 func ExampleRat_Scan() { 30 // The Scan function is rarely used directly; 31 // the fmt package recognizes it as an implementation of fmt.Scanner. 32 r := new(big.Rat) 33 _, err := fmt.Sscan("1.5000", r) 34 if err != nil { 35 log.Println("error scanning value:", err) 36 } else { 37 fmt.Println(r) 38 } 39 // Output: 3/2 40 } 41 42 func ExampleInt_Scan() { 43 // The Scan function is rarely used directly; 44 // the fmt package recognizes it as an implementation of fmt.Scanner. 45 i := new(big.Int) 46 _, err := fmt.Sscan("18446744073709551617", i) 47 if err != nil { 48 log.Println("error scanning value:", err) 49 } else { 50 fmt.Println(i) 51 } 52 // Output: 18446744073709551617 53 }