Skip to content

Commit 9b00d50

Browse files
committed
Revert "std: float64/32 clean up e-09 to e-9"
This reverts commit 10b9ac0.
1 parent ffc487c commit 9b00d50

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

Diff for: stream_float.go

-16
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ func (stream *Stream) WriteFloat32(val float32) {
2727
}
2828
}
2929
stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 32)
30-
if fmt == 'e' {
31-
// clean up e-09 to e-9
32-
n := len(stream.buf)
33-
if n >= 4 && stream.buf[n-4] == 'e' && stream.buf[n-3] == '-' && stream.buf[n-2] == '0' {
34-
stream.buf[n-2] = stream.buf[n-1]
35-
stream.buf = stream.buf[:n-1]
36-
}
37-
}
3830
}
3931

4032
// WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster
@@ -84,14 +76,6 @@ func (stream *Stream) WriteFloat64(val float64) {
8476
}
8577
}
8678
stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 64)
87-
if fmt == 'e' {
88-
// clean up e-09 to e-9
89-
n := len(stream.buf)
90-
if n >= 4 && stream.buf[n-4] == 'e' && stream.buf[n-3] == '-' && stream.buf[n-2] == '0' {
91-
stream.buf[n-2] = stream.buf[n-1]
92-
stream.buf = stream.buf[:n-1]
93-
}
94-
}
9579
}
9680

9781
// WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster

Diff for: value_tests/float_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"github.com/json-iterator/go"
8+
"github.com/stretchr/testify/require"
79
"strconv"
810
"testing"
9-
10-
jsoniter "github.com/json-iterator/go"
11-
"github.com/stretchr/testify/require"
1211
)
1312

1413
func Test_read_float(t *testing.T) {
@@ -89,7 +88,7 @@ func Test_write_float32(t *testing.T) {
8988

9089
stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0)
9190
stream.WriteFloat32(float32(0.0000001))
92-
should.Equal("1e-7", string(stream.Buffer()))
91+
should.Equal("1e-07", string(stream.Buffer()))
9392
}
9493

9594
func Test_write_float64(t *testing.T) {
@@ -126,5 +125,5 @@ func Test_write_float64(t *testing.T) {
126125

127126
stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0)
128127
stream.WriteFloat64(float64(0.0000001))
129-
should.Equal("1e-7", string(stream.Buffer()))
128+
should.Equal("1e-07", string(stream.Buffer()))
130129
}

0 commit comments

Comments
 (0)