Skip to content

Commit

Permalink
strconv: fix round up corner case
Browse files Browse the repository at this point in the history
Comment described the correct condition
but the code did not implement it.

Fixes #2625.

R=remyoudompheng
CC=golang-dev
https://golang.org/cl/5530082
  • Loading branch information
rsc committed Jan 12, 2012
1 parent 701f70a commit 6f77cd2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pkg/strconv/ftoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {

// Okay to round up if upper has a different digit and
// either upper is inclusive or upper is bigger than the result of rounding up.
okup := m != u && (inclusive || i+1 < upper.nd)
okup := m != u && (inclusive || m+1 < u || i+1 < upper.nd)

// If it's okay to do either, then round to the nearest one.
// If it's okay to do only one, do it.
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/strconv/ftoa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ var ftoatests = []ftoaTest{
{2.2250738585072012e-308, 'g', -1, "2.2250738585072014e-308"},
// http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/
{2.2250738585072011e-308, 'g', -1, "2.225073858507201e-308"},

// Issue 2625.
{383260575764816448, 'f', 0, "383260575764816448"},
{383260575764816448, 'g', -1, "3.8326057576481645e+17"},
}

func TestFtoa(t *testing.T) {
Expand Down

0 comments on commit 6f77cd2

Please sign in to comment.