Skip to content

Commit d45bbbb

Browse files
committed
- use global variables for math.Inf usage
- add complex (math.Inf(1), math.Inf(-1)) case and reverse
1 parent 96cea1a commit d45bbbb

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

src/strconv/atoc_test.go

+39-37
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,18 @@ func TestParseComplex(t *testing.T) {
153153
// ErrRange
154154

155155
// next float64 - too large
156-
{"1.7976931348623159e308+1.7976931348623159e308i", complex(math.Inf(1), math.Inf(1)), ErrRange},
157-
{"-1.7976931348623159e308-1.7976931348623159e308i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
158-
{"0x1p1024+0x1p1024i", complex(math.Inf(1), math.Inf(1)), ErrRange},
159-
{"-0x1p1024-0x1p1024i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
160-
{"0x2p1023+0x2p1023i", complex(math.Inf(1), math.Inf(1)), ErrRange},
161-
{"-0x2p1023-0x2p1023i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
162-
{"0x.1p1028+0x.1p1028i", complex(math.Inf(1), math.Inf(1)), ErrRange},
163-
{"-0x.1p1028-0x.1p1028i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
164-
{"0x.2p1027+0x.2p1027i", complex(math.Inf(1), math.Inf(1)), ErrRange},
165-
{"-0x.2p1027-0x.2p1027i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
156+
{"1.7976931348623159e308+1.7976931348623159e308i", infpp, ErrRange},
157+
{"-1.7976931348623159e308-1.7976931348623159e308i", infmm, ErrRange},
158+
{"0x1p1024+0x1p1024i", infpp, ErrRange},
159+
{"0x1p1024-0x1p1024i", infpm, ErrRange},
160+
{"-0x1p1024+0x1p1024i", infmp, ErrRange},
161+
{"-0x1p1024-0x1p1024i", infmm, ErrRange},
162+
{"0x2p1023+0x2p1023i", infpp, ErrRange},
163+
{"-0x2p1023-0x2p1023i", infmm, ErrRange},
164+
{"0x.1p1028+0x.1p1028i", infpp, ErrRange},
165+
{"-0x.1p1028-0x.1p1028i", infmm, ErrRange},
166+
{"0x.2p1027+0x.2p1027i", infpp, ErrRange},
167+
{"-0x.2p1027-0x.2p1027i", infmm, ErrRange},
166168

167169
// the border is ...158079
168170
// borderline - okay
@@ -171,20 +173,20 @@ func TestParseComplex(t *testing.T) {
171173
{"0x1.fffffffffffff7fffp1023+0x1.fffffffffffff7fffp1023i", 1.7976931348623157e+308 + 1.7976931348623157e+308i, nil},
172174
{"-0x1.fffffffffffff7fffp1023-0x1.fffffffffffff7fffp1023i", -1.7976931348623157e+308 - 1.7976931348623157e+308i, nil},
173175
// borderline - too large
174-
{"1.797693134862315808e308+1.797693134862315808e308i", complex(math.Inf(1), math.Inf(1)), ErrRange},
175-
{"-1.797693134862315808e308-1.797693134862315808e308i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
176-
{"0x1.fffffffffffff8p1023+0x1.fffffffffffff8p1023i", complex(math.Inf(1), math.Inf(1)), ErrRange},
177-
{"-0x1.fffffffffffff8p1023-0x1.fffffffffffff8p1023i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
178-
{"0x1fffffffffffff.8p+971+0x1fffffffffffff.8p+971i", complex(math.Inf(1), math.Inf(1)), ErrRange},
179-
{"-0x1fffffffffffff8p+967-0x1fffffffffffff8p+967i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
180-
{"0x.1fffffffffffff8p1027+0x.1fffffffffffff8p1027i", complex(math.Inf(1), math.Inf(1)), ErrRange},
181-
{"-0x.1fffffffffffff9p1027-0x.1fffffffffffff9p1027i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
176+
{"1.797693134862315808e308+1.797693134862315808e308i", infpp, ErrRange},
177+
{"-1.797693134862315808e308-1.797693134862315808e308i", infmm, ErrRange},
178+
{"0x1.fffffffffffff8p1023+0x1.fffffffffffff8p1023i", infpp, ErrRange},
179+
{"-0x1.fffffffffffff8p1023-0x1.fffffffffffff8p1023i", infmm, ErrRange},
180+
{"0x1fffffffffffff.8p+971+0x1fffffffffffff.8p+971i", infpp, ErrRange},
181+
{"-0x1fffffffffffff8p+967-0x1fffffffffffff8p+967i", infmm, ErrRange},
182+
{"0x.1fffffffffffff8p1027+0x.1fffffffffffff8p1027i", infpp, ErrRange},
183+
{"-0x.1fffffffffffff9p1027-0x.1fffffffffffff9p1027i", infmm, ErrRange},
182184

183185
// a little too large
184186
{"1e308+1e308i", 1e+308 + 1e+308i, nil},
185-
{"2e308+2e308i", complex(math.Inf(1), math.Inf(1)), ErrRange},
186-
{"1e309+1e309i", complex(math.Inf(1), math.Inf(1)), ErrRange},
187-
{"0x1p1025+0x1p1025i", complex(math.Inf(1), math.Inf(1)), ErrRange},
187+
{"2e308+2e308i", infpp, ErrRange},
188+
{"1e309+1e309i", infpp, ErrRange},
189+
{"0x1p1025+0x1p1025i", infpp, ErrRange},
188190
{"2e308", complex(math.Inf(1), 0), ErrRange},
189191
{"1e309", complex(math.Inf(1), 0), ErrRange},
190192
{"0x1p1025", complex(math.Inf(1), 0), ErrRange},
@@ -193,28 +195,28 @@ func TestParseComplex(t *testing.T) {
193195
{"0x1p1025i", complex(0, math.Inf(1)), ErrRange},
194196

195197
// way too large
196-
{"1e310+1e310i", complex(math.Inf(1), math.Inf(1)), ErrRange},
197-
{"-1e310-1e310i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
198-
{"1e400+1e400i", complex(math.Inf(1), math.Inf(1)), ErrRange},
199-
{"-1e400-1e400i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
200-
{"1e400000+1e400000i", complex(math.Inf(1), math.Inf(1)), ErrRange},
201-
{"-1e400000-1e400000i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
202-
{"0x1p1030+0x1p1030i", complex(math.Inf(1), math.Inf(1)), ErrRange},
203-
{"0x1p2000+0x1p2000i", complex(math.Inf(1), math.Inf(1)), ErrRange},
204-
{"0x1p2000000000+0x1p2000000000i", complex(math.Inf(1), math.Inf(1)), ErrRange},
205-
{"-0x1p1030-0x1p1030i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
206-
{"-0x1p2000-0x1p2000i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
207-
{"-0x1p2000000000-0x1p2000000000i", complex(math.Inf(-1), math.Inf(-1)), ErrRange},
198+
{"1e310+1e310i", infpp, ErrRange},
199+
{"-1e310-1e310i", infmm, ErrRange},
200+
{"1e400+1e400i", infpp, ErrRange},
201+
{"-1e400-1e400i", infmm, ErrRange},
202+
{"1e400000+1e400000i", infpp, ErrRange},
203+
{"-1e400000-1e400000i", infmm, ErrRange},
204+
{"0x1p1030+0x1p1030i", infpp, ErrRange},
205+
{"0x1p2000+0x1p2000i", infpp, ErrRange},
206+
{"0x1p2000000000+0x1p2000000000i", infpp, ErrRange},
207+
{"-0x1p1030-0x1p1030i", infmm, ErrRange},
208+
{"-0x1p2000-0x1p2000i", infmm, ErrRange},
209+
{"-0x1p2000000000-0x1p2000000000i", infmm, ErrRange},
208210

209211
// try to overflow exponent
210212
{"1e-4294967296+1e-4294967296i", 0, nil},
211-
{"1e+4294967296+1e+4294967296i", complex(math.Inf(1), math.Inf(1)), ErrRange},
213+
{"1e+4294967296+1e+4294967296i", infpp, ErrRange},
212214
{"1e-18446744073709551616+1e-18446744073709551616i", 0, nil},
213-
{"1e+18446744073709551616+1e+18446744073709551616i", complex(math.Inf(1), math.Inf(1)), ErrRange},
215+
{"1e+18446744073709551616+1e+18446744073709551616i", infpp, ErrRange},
214216
{"0x1p-4294967296+0x1p-4294967296i", 0, nil},
215-
{"0x1p+4294967296+0x1p+4294967296i", complex(math.Inf(1), math.Inf(1)), ErrRange},
217+
{"0x1p+4294967296+0x1p+4294967296i", infpp, ErrRange},
216218
{"0x1p-18446744073709551616+0x1p-18446744073709551616i", 0, nil},
217-
{"0x1p+18446744073709551616+0x1p+18446744073709551616i", complex(math.Inf(1), math.Inf(1)), ErrRange},
219+
{"0x1p+18446744073709551616+0x1p+18446744073709551616i", infpp, ErrRange},
218220
}
219221

220222
for _, tt := range tests {

0 commit comments

Comments
 (0)