Commit 6a10f720 authored by Robert Griesemer's avatar Robert Griesemer

math/big: don't return io.EOF on successful call of ParseFloat

Fixes $9938.

Change-Id: Ie8680a875225748abd660fb26b4c25546e7b92d3
Reviewed-on: https://go-review.googlesource.com/5620Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
parent 99482f2f
...@@ -126,11 +126,9 @@ func (z *Float) Scan(r io.ByteScanner, base int) (f *Float, b int, err error) { ...@@ -126,11 +126,9 @@ func (z *Float) Scan(r io.ByteScanner, base int) (f *Float, b int, err error) {
} }
// Parse is like z.Scan(r, base), but instead of reading from an // Parse is like z.Scan(r, base), but instead of reading from an
// io.ByteScanner, it parses the string s. An error is returned if the // io.ByteScanner, it parses the string s. An error is returned if
// string contains invalid or trailing characters not belonging to the // the string contains invalid or trailing bytes not belonging to
// number. // the number.
//
// TODO(gri) define possible errors more precisely
func (z *Float) Parse(s string, base int) (f *Float, b int, err error) { func (z *Float) Parse(s string, base int) (f *Float, b int, err error) {
r := strings.NewReader(s) r := strings.NewReader(s)
...@@ -139,11 +137,10 @@ func (z *Float) Parse(s string, base int) (f *Float, b int, err error) { ...@@ -139,11 +137,10 @@ func (z *Float) Parse(s string, base int) (f *Float, b int, err error) {
} }
// entire string must have been consumed // entire string must have been consumed
var ch byte if ch, err2 := r.ReadByte(); err2 == nil {
if ch, err = r.ReadByte(); err != io.EOF { err = fmt.Errorf("expected end of string, found %q", ch)
if err == nil { } else if err2 != io.EOF {
err = fmt.Errorf("expected end of string, found %q", ch) err = err2
}
} }
return return
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package big package big
import ( import (
"io"
"math" "math"
"strconv" "strconv"
"testing" "testing"
...@@ -59,7 +58,7 @@ func TestFloatSetFloat64String(t *testing.T) { ...@@ -59,7 +58,7 @@ func TestFloatSetFloat64String(t *testing.T) {
{"+10000000000000000000000000000000000000000e-0", 1e40}, {"+10000000000000000000000000000000000000000e-0", 1e40},
} { } {
var x Float var x Float
x.prec = 53 // TODO(gri) find better solution x.SetPrec(53)
_, ok := x.SetString(test.s) _, ok := x.SetString(test.s)
if !ok { if !ok {
t.Errorf("%s: parse error", test.s) t.Errorf("%s: parse error", test.s)
...@@ -313,8 +312,7 @@ func TestFloatFormat(t *testing.T) { ...@@ -313,8 +312,7 @@ func TestFloatFormat(t *testing.T) {
{"3.14", 'x', 0, "%x"}, {"3.14", 'x', 0, "%x"},
} { } {
f, _, err := ParseFloat(test.x, 0, 1000, ToNearestEven) f, _, err := ParseFloat(test.x, 0, 1000, ToNearestEven)
// TODO(gri) should we return io.EOF at the end? if err != nil {
if err != nil && err != io.EOF {
t.Errorf("%v: %s", test, err) t.Errorf("%v: %s", test, err)
continue continue
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment