blob: 078be47f956940d5fed438817a3e0bdc65ab504d [file] [log] [blame]
Andrew Gerrandddd67f22012-01-25 10:29:44 +11001// 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
5package big_test
6
7import (
8 "fmt"
9 "log"
10 "math/big"
11)
12
Andrew Gerrandddd67f22012-01-25 10:29:44 +110013func ExampleRat_SetString() {
14 r := new(big.Rat)
15 r.SetString("355/113")
16 fmt.Println(r.FloatString(3))
Andrew Gerrand11e113d2012-02-16 11:50:28 +110017 // Output: 3.142
Andrew Gerrandddd67f22012-01-25 10:29:44 +110018}
19
Andrew Gerrandddd67f22012-01-25 10:29:44 +110020func ExampleInt_SetString() {
21 i := new(big.Int)
22 i.SetString("644", 8) // octal
23 fmt.Println(i)
Andrew Gerrand11e113d2012-02-16 11:50:28 +110024 // Output: 420
Andrew Gerrandddd67f22012-01-25 10:29:44 +110025}
26
Andrew Gerrandddd67f22012-01-25 10:29:44 +110027func 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 }
Andrew Gerrand11e113d2012-02-16 11:50:28 +110037 // Output: 3/2
Andrew Gerrandddd67f22012-01-25 10:29:44 +110038}
39
Andrew Gerrandddd67f22012-01-25 10:29:44 +110040func 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 }
Andrew Gerrand11e113d2012-02-16 11:50:28 +110050 // Output: 18446744073709551617
Andrew Gerrandddd67f22012-01-25 10:29:44 +110051}