summaryrefslogtreecommitdiff
path: root/src/lib/strconv/atof.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-11-19 12:50:34 -0800
committerRuss Cox <rsc@golang.org>2008-11-19 12:50:34 -0800
commitd50e9592957199d766080f283deabed170f71ba8 (patch)
tree95c5b99eab6e3cc755f12490f049910116c3a1eb /src/lib/strconv/atof.go
parenta6b71cb1ad58a14a778e28107cea6360b84591f3 (diff)
downloadgolang-d50e9592957199d766080f283deabed170f71ba8.tar.gz
essentially 100% coverage of strconv in tests.
fix a few bugs. R=r DELTA=294 (275 added, 9 deleted, 10 changed) OCL=19595 CL=19595
Diffstat (limited to 'src/lib/strconv/atof.go')
-rw-r--r--src/lib/strconv/atof.go25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/lib/strconv/atof.go b/src/lib/strconv/atof.go
index 5f019d3ec..76b5ebacd 100644
--- a/src/lib/strconv/atof.go
+++ b/src/lib/strconv/atof.go
@@ -15,6 +15,8 @@ import (
"strconv";
)
+package var optimize = true // can change for testing
+
// TODO(rsc): Better truncation handling.
func StringToDecimal(s string) (neg bool, d *Decimal, trunc bool, ok bool) {
i := 0;
@@ -182,16 +184,7 @@ func DecimalToFloatBits(neg bool, d *Decimal, trunc bool, flt *FloatInfo) (b uin
// Denormalized?
if mant&(1<<flt.mantbits) == 0 {
- if exp != flt.bias+1 {
- // TODO: remove - has no business panicking
- panicln("DecimalToFloatBits", exp, flt.bias+1);
- }
- exp--;
- } else {
- if exp <= flt.bias {
- // TODO: remove - has no business panicking
- panicln("DecimalToFloatBits1", exp, flt.bias);
- }
+ exp = flt.bias;
}
goto out;
@@ -327,8 +320,10 @@ export func atof64(s string) (f float64, err *os.Error) {
if !ok {
return 0, os.EINVAL;
}
- if f, ok := DecimalToFloat64(neg, d, trunc); ok {
- return f, nil;
+ if optimize {
+ if f, ok := DecimalToFloat64(neg, d, trunc); ok {
+ return f, nil;
+ }
}
b, ovf := DecimalToFloatBits(neg, d, trunc, &float64info);
f = sys.float64frombits(b);
@@ -343,8 +338,10 @@ export func atof32(s string) (f float32, err *os.Error) {
if !ok {
return 0, os.EINVAL;
}
- if f, ok := DecimalToFloat32(neg, d, trunc); ok {
- return f, nil;
+ if optimize {
+ if f, ok := DecimalToFloat32(neg, d, trunc); ok {
+ return f, nil;
+ }
}
b, ovf := DecimalToFloatBits(neg, d, trunc, &float32info);
f = sys.float32frombits(uint32(b));