redis-shake工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
719 B

package structure
import (
"encoding/binary"
"github.com/alibaba/RedisShake/internal/log"
"io"
"math"
"strconv"
)
func ReadFloat(rd io.Reader) float64 {
u := ReadUint8(rd)
switch u {
case 253:
return math.NaN()
case 254:
return math.Inf(0)
case 255:
return math.Inf(-1)
default:
buf := make([]byte, u)
_, err := io.ReadFull(rd, buf)
if err != nil {
return 0
}
v, err := strconv.ParseFloat(string(buf), 64)
if err != nil {
log.PanicError(err)
}
return v
}
}
func ReadDouble(rd io.Reader) float64 {
var buf = make([]byte, 8)
_, err := io.ReadFull(rd, buf)
if err != nil {
log.PanicError(err)
}
num := binary.LittleEndian.Uint64(buf)
return math.Float64frombits(num)
}