package main
import (
"fmt"
"bytes"
"github.com/lunixbochs/struc"
)
type I struct {
i float32 `struc:"float32"`
}
type O struct {
o int `struc:"int32"`
}
func float32ToInt32(f float32) int {
var buf bytes.Buffer
t := &I{f}
e := struc.Pack(&buf, t)
if (e != nil) {
fmt.Println("encoding error", e)
}
o := &O{}
ee := struc.Unpack(&buf, o)
if (e != nil) {
fmt.Println("decoding error", ee)
}
return o.o
}
func main() {
fmt.Println("float32ToInt32", float32ToInt32(32.3))
}
I'm not sure if this is a bug in goplayground, my code, or struc, but I figured I'd report it here in case there's something obvious I'm missing.
https://play.golang.org/p/xW7R-0YjQ8n
Results in the incorrect output: