Created
August 22, 2019 07:38
-
-
Save zhyon404/eb4676b4653b11471b25a2bb3595246b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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