]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: fix round up corner case
authorRuss Cox <rsc@golang.org>
Thu, 12 Jan 2012 19:32:28 +0000 (11:32 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 12 Jan 2012 19:32:28 +0000 (11:32 -0800)
Comment described the correct condition
but the code did not implement it.

Fixes #2625.

R=remyoudompheng
CC=golang-dev
https://golang.org/cl/5530082

src/pkg/strconv/ftoa.go
src/pkg/strconv/ftoa_test.go

index f4434fd51753c8a96e0ecee3406f09af2c8ae063..b1d4b32f03ee0d3c058973f2c7e2c2f365222dfb 100644 (file)
@@ -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.
index 40c71a28b4dd5320153492b8ef79a5c2f8e05415..1d90a67f528f110e146f91fd50071498efdbc965 100644 (file)
@@ -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) {