lunixbochs / struc

Better binary packing for Go
MIT License
572 stars 45 forks source link

Half Floats (float16) #39

Closed lain-dono closed 5 years ago

lain-dono commented 8 years ago

wiki: Half-precision floating-point format

type Point struct {
  X float64 `struc:"float16"`
  Y float64 `struc:"float16"`
}
lunixbochs commented 8 years ago

Should be a custom type like Int3 from here: https://github.com/lunixbochs/struc/issues/35

I'm almost done implementing it.

lunixbochs commented 8 years ago

You should be able to use the struc.Float16 type for field values now. I'll need to do some plumbing before it's usable via struc:"float16" because that can't be used to specify completely custom types yet.

There's a pile of tests listed here that should handle most cases: https://github.com/lunixbochs/struc/blob/master/custom_float16_test.go#L19

It has some mild precision issues vs float64 at the extreme ends and doesn't pack/unpack -0 properly, so those tests are disabled, but that's to be expected.

13rac1 commented 5 years ago

FWIW I consider this issue closeable.