]> Cypherpunks repositories - gostls13.git/commit
strconv: fix incorrect bit size in ParseComplex; add tests
authorBen Hoyt <benhoyt@gmail.com>
Fri, 14 Aug 2020 10:58:49 +0000 (22:58 +1200)
committerRobert Griesemer <gri@golang.org>
Fri, 30 Oct 2020 00:13:25 +0000 (00:13 +0000)
commit60f42ea61cb7e1de8d54432d8fb9ab028b8a575d
tree3e8a70150e11189cb3b16fd46bf6d14f7be4bd72
parent01efc9a3c54f1b8fc772084e3311b6e1ccdfabec
strconv: fix incorrect bit size in ParseComplex; add tests

In ParseComplex, the "size" passed to parseFloatPrefix should be 64 for
complex128, not 128. It still works because of how parseFloatPrefix
is forgiving about the size if it's not 32, but worth fixing anyway.

Make ParseComplex and ParseFloat return a bit size error for anything
other than 128 or 64 (for ParseComplex), or 64 or 32 (for ParseFloat).
Add "InvalidBitSize" tests for these cases.

Add tests for ParseComplex with bitSize==64: this is done in a similar
way to how the ParseFloat 32-bit tests work, re-using the tests for the
larger bit size.

Add tests for FormatComplex -- there were none before.

Fixes #40706

Change-Id: I16ddd546e5237207cc3b8c2181dd708eca42b04f
Reviewed-on: https://go-review.googlesource.com/c/go/+/248219
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Minux Ma <minux@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/strconv/atoc.go
src/strconv/atoc_test.go
src/strconv/atof.go
src/strconv/atof_test.go
src/strconv/ctoa_test.go [new file with mode: 0644]
src/strconv/ftoa_test.go