Skip to content

Instantly share code, notes, and snippets.

@zhyon404
Created August 22, 2019 07:38
Show Gist options
  • Save zhyon404/eb4676b4653b11471b25a2bb3595246b to your computer and use it in GitHub Desktop.
Save zhyon404/eb4676b4653b11471b25a2bb3595246b to your computer and use it in GitHub Desktop.
func floatSlice2bytes(s []float64) []byte {
b := (*reflect.SliceHeader)(unsafe.Pointer(&s))
b.Cap = b.Cap * 8
b.Len = b.Len * 8
return *(*[]byte)(unsafe.Pointer(&s))
}
func bytes2floatSlice(s []byte) []float64 {
b := (*reflect.SliceHeader)(unsafe.Pointer(&s))
b.Cap = b.Cap / 8
b.Len = b.Len / 8
return *(*[]float64)(unsafe.Pointer(&s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment