]> Cypherpunks repositories - gostls13.git/commitdiff
Make strconv.atof("-0") return -0
authorRuss Cox <rsc@golang.org>
Wed, 3 Dec 2008 21:29:13 +0000 (13:29 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 3 Dec 2008 21:29:13 +0000 (13:29 -0800)
and update test.

R=iant
DELTA=11  (3 added, 1 deleted, 7 changed)
OCL=20350
CL=20362

src/lib/strconv/atof.go
src/lib/strconv/atof_test.go

index 9345b9939673c68675116b3defdfcf36328b1c9a..8869e2032c903ca131f4caa3b46e126f8ef495d5 100644 (file)
@@ -110,14 +110,16 @@ var powtab = []int{
 }
 
 func DecimalToFloatBits(neg bool, d *Decimal, trunc bool, flt *FloatInfo) (b uint64, overflow bool) {
+       var exp int;
+       var mant uint64;
+
        // Zero is always a special case.
        if d.nd == 0 {
-               return 0, false
+               mant = 0;
+               exp = flt.bias;
+               goto out;
        }
 
-       var exp int;
-       var mant uint64;
-
        // Obvious overflow/underflow.
        // These bounds are for 64-bit floats.
        // Will have to change if we want to support 80-bit floats in the future.
@@ -212,7 +214,7 @@ func DecimalToFloat64Int(neg bool, d *Decimal) float64 {
                f = f*10 + float64(d.d[i] - '0');
        }
        if neg {
-               f = -f;
+               f *= -1;        // BUG work around 6g f = -f.
        }
        return f;
 }
@@ -223,7 +225,7 @@ func DecimalToFloat32Int(neg bool, d *Decimal) float32 {
                f = f*10 + float32(d.d[i] - '0');
        }
        if neg {
-               f = -f;
+               f *= -1;        // BUG work around 6g f = -f.
        }
        return f;
 }
index cf4603f810256b3696e6ecdf21e22f9cb78ca7fa..ab4fcd1462242c619c43176ff5189f5c87a2b36f 100644 (file)
@@ -32,7 +32,7 @@ var tests = []Test {
        Test{ "100000000000000016777215", "1.0000000000000001e+23", nil },
        Test{ "100000000000000016777216", "1.0000000000000003e+23", nil },
        Test{ "-1", "-1", nil },
-       Test{ "-0", "0", nil },
+       Test{ "-0", "-0", nil },
        Test{ "1e-20", "1e-20", nil },
        Test{ "625e-3", "0.625", nil },