tape: Add float functions to the encoder

This commit is contained in:
2025-06-21 18:33:25 -04:00
parent 376a3f1b46
commit 663cab6b77
2 changed files with 26 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package tape
import "io"
import "math"
// Decodable is any type that can decode itself from a decoder.
type Decodable interface {
@@ -125,3 +126,17 @@ func (this *Decoder) ReadGBEU() (value uint64, n int, err error) {
}
}
}
// ReadFloat32 decldes a 32-bit floating point value from the input reader.
func (this *Decoder) ReadFloat32() (value float32, n int, err error) {
bits, nn, err := this.ReadUint32()
n += nn; if err != nil { return 0, n, err }
return math.Float32frombits(bits), n, nil
}
// ReadFloat64 decldes a 64-bit floating point value from the input reader.
func (this *Decoder) ReadFloat64() (value float64, n int, err error) {
bits, nn, err := this.ReadUint64()
n += nn; if err != nil { return 0, n, err }
return math.Float64frombits(bits), n, nil
}