diff --git a/bit/decode.go b/bit/decode.go index e098b46..41c6d0f 100644 --- a/bit/decode.go +++ b/bit/decode.go @@ -7,7 +7,13 @@ import ( // normalized values are represented with 11 significant bits. we pre-compute a // divisor so that we can use a multiply instruction and avoid using // floating-point division during the lifecycle of the program. -var normal_divisor = float32(1.0) / float32(2047) +const normal_divisor = float32(1.0) / float32(2047) + +const ( + coord_ibits = 14 // number of integer bits in a coord value + coord_fbits = 5 // number of fractional bits in a coord value + coord_res = 1.0 / 1 << coord_fbits +) // ReadUbitVar reads a prefixed uint value. A prefix is 2 bits wide, followed // by the 4 least-significant bits, then a variable number of most-significant @@ -135,3 +141,29 @@ func ReadNormal(r Reader) float32 { return -float32(r.ReadBits(11)) * normal_divisor } } + +// an angle is just a quantized float between 0 and 360 +func ReadAngle(r Reader, bits uint) float32 { + return float32(r.ReadBits(bits)) * 360.0 / float32(uint(1)<= 32 { return ieeeFloat32Decoder } @@ -82,5 +86,7 @@ func floatDecoder(f *Field) decoder { // reads an IEEE 754 binary float value off of the stream func ieeeFloat32Decoder(br bit.Reader) interface{} { - return math.Float32frombits(uint32(br.ReadBits(32))) + u := uint32(br.ReadBits(32)) + Debug.Printf("ieee float32 decode bits: %d", u) + return math.Float32frombits(u) }