LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package strconv_test | 5 package strconv_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "fmt" | 9 "fmt" |
10 "os" | 10 "os" |
(...skipping 10 matching lines...) Expand all Loading... |
21 return 1 | 21 return 1 |
22 case i == 1: | 22 case i == 1: |
23 return 2 | 23 return 2 |
24 } | 24 } |
25 return pow2(i/2) * pow2(i-i/2) | 25 return pow2(i/2) * pow2(i-i/2) |
26 } | 26 } |
27 | 27 |
28 // Wrapper around strconv.Atof64. Handles dddddp+ddd (binary exponent) | 28 // Wrapper around strconv.Atof64. Handles dddddp+ddd (binary exponent) |
29 // itself, passes the rest on to strconv.Atof64. | 29 // itself, passes the rest on to strconv.Atof64. |
30 func myatof64(s string) (f float64, ok bool) { | 30 func myatof64(s string) (f float64, ok bool) { |
31 » a := strings.Split(s, "p", 2) | 31 » a := strings.SplitN(s, "p", 2) |
32 if len(a) == 2 { | 32 if len(a) == 2 { |
33 n, err := strconv.Atoi64(a[0]) | 33 n, err := strconv.Atoi64(a[0]) |
34 if err != nil { | 34 if err != nil { |
35 return 0, false | 35 return 0, false |
36 } | 36 } |
37 e, err1 := strconv.Atoi(a[1]) | 37 e, err1 := strconv.Atoi(a[1]) |
38 if err1 != nil { | 38 if err1 != nil { |
39 println("bad e", a[1]) | 39 println("bad e", a[1]) |
40 return 0, false | 40 return 0, false |
41 } | 41 } |
(...skipping 23 matching lines...) Expand all Loading... |
65 f1, err := strconv.Atof64(s) | 65 f1, err := strconv.Atof64(s) |
66 if err != nil { | 66 if err != nil { |
67 return 0, false | 67 return 0, false |
68 } | 68 } |
69 return f1, true | 69 return f1, true |
70 } | 70 } |
71 | 71 |
72 // Wrapper around strconv.Atof32. Handles dddddp+ddd (binary exponent) | 72 // Wrapper around strconv.Atof32. Handles dddddp+ddd (binary exponent) |
73 // itself, passes the rest on to strconv.Atof32. | 73 // itself, passes the rest on to strconv.Atof32. |
74 func myatof32(s string) (f float32, ok bool) { | 74 func myatof32(s string) (f float32, ok bool) { |
75 » a := strings.Split(s, "p", 2) | 75 » a := strings.SplitN(s, "p", 2) |
76 if len(a) == 2 { | 76 if len(a) == 2 { |
77 n, err := strconv.Atoi(a[0]) | 77 n, err := strconv.Atoi(a[0]) |
78 if err != nil { | 78 if err != nil { |
79 println("bad n", a[0]) | 79 println("bad n", a[0]) |
80 return 0, false | 80 return 0, false |
81 } | 81 } |
82 e, err1 := strconv.Atoi(a[1]) | 82 e, err1 := strconv.Atoi(a[1]) |
83 if err1 != nil { | 83 if err1 != nil { |
84 println("bad p", a[1]) | 84 println("bad p", a[1]) |
85 return 0, false | 85 return 0, false |
(...skipping 23 matching lines...) Expand all Loading... |
109 break | 109 break |
110 } | 110 } |
111 if err2 != nil { | 111 if err2 != nil { |
112 t.Fatal("testfp: read testfp.txt: " + err2.String()) | 112 t.Fatal("testfp: read testfp.txt: " + err2.String()) |
113 } | 113 } |
114 line = line[0 : len(line)-1] | 114 line = line[0 : len(line)-1] |
115 lineno++ | 115 lineno++ |
116 if len(line) == 0 || line[0] == '#' { | 116 if len(line) == 0 || line[0] == '#' { |
117 continue | 117 continue |
118 } | 118 } |
119 » » a := strings.Split(line, " ", -1) | 119 » » a := strings.Split(line, " ") |
120 if len(a) != 4 { | 120 if len(a) != 4 { |
121 t.Error("testfp.txt:", lineno, ": wrong field count") | 121 t.Error("testfp.txt:", lineno, ": wrong field count") |
122 continue | 122 continue |
123 } | 123 } |
124 var s string | 124 var s string |
125 var v float64 | 125 var v float64 |
126 switch a[0] { | 126 switch a[0] { |
127 case "float64": | 127 case "float64": |
128 var ok bool | 128 var ok bool |
129 v, ok = myatof64(a[2]) | 129 v, ok = myatof64(a[2]) |
(...skipping 10 matching lines...) Expand all Loading... |
140 } | 140 } |
141 s = fmt.Sprintf(a[1], v1) | 141 s = fmt.Sprintf(a[1], v1) |
142 v = float64(v1) | 142 v = float64(v1) |
143 } | 143 } |
144 if s != a[3] { | 144 if s != a[3] { |
145 t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], "
", a[2], " (", v, ") ", | 145 t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], "
", a[2], " (", v, ") ", |
146 "want ", a[3], " got ", s) | 146 "want ", a[3], " got ", s) |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
LEFT | RIGHT |