11 pow10 = []uint64{1, 10, 100, 1000, 10000, 100000, 1000000}
14 // WriteFloat32 write float32 to stream
15 func (stream *Stream) WriteFloat32(val float32) {
16 abs := math.Abs(float64(val))
18 // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
20 if float32(abs) < 1e-6 || float32(abs) >= 1e21 {
24 stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 32)
27 // WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster
28 func (stream *Stream) WriteFloat32Lossy(val float32) {
34 stream.WriteFloat32(val)
38 exp := uint64(1000000) // 6
39 lval := uint64(float64(val)*float64(exp) + 0.5)
40 stream.WriteUint64(lval / exp)
46 for p := precision - 1; p > 0 && fval < pow10[p]; p-- {
49 stream.WriteUint64(fval)
50 for stream.buf[len(stream.buf)-1] == '0' {
51 stream.buf = stream.buf[:len(stream.buf)-1]
55 // WriteFloat64 write float64 to stream
56 func (stream *Stream) WriteFloat64(val float64) {
59 // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
61 if abs < 1e-6 || abs >= 1e21 {
65 stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 64)
68 // WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster
69 func (stream *Stream) WriteFloat64Lossy(val float64) {
75 stream.WriteFloat64(val)
79 exp := uint64(1000000) // 6
80 lval := uint64(val*float64(exp) + 0.5)
81 stream.WriteUint64(lval / exp)
87 for p := precision - 1; p > 0 && fval < pow10[p]; p-- {
90 stream.WriteUint64(fval)
91 for stream.buf[len(stream.buf)-1] == '0' {
92 stream.buf = stream.buf[:len(stream.buf)-1]