...
1 package ieee754
2
3 import (
4 "encoding/binary"
5 "io"
6 "math"
7 )
8
9
10
11 func DecodeFloat32(buf []byte) (float32, error) {
12 if len(buf) < 4 {
13 return 0, io.ErrUnexpectedEOF
14 }
15
16 raw := binary.LittleEndian.Uint32(buf[:4])
17 return math.Float32frombits(raw), nil
18 }
19
20
21
22 func DecodeFloat64(buf []byte) (float64, error) {
23 if len(buf) < 8 {
24 return 0, io.ErrUnexpectedEOF
25 }
26
27 raw := binary.LittleEndian.Uint64(buf)
28 return math.Float64frombits(raw), nil
29 }
30
View as plain text