Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pack float data wrong #4

Open
alex-hsl opened this issue Nov 14, 2012 · 0 comments
Open

pack float data wrong #4

alex-hsl opened this issue Nov 14, 2012 · 0 comments

Comments

@alex-hsl
Copy link

I think that the method of using pack uint data method to pack float data is wrong, because the head sign of packing float is different from the head sign of packing uint, so I modify code:

// Packs a given value and writes it into the specified writer.
func PackFloat32(writer io.Writer, value float32) (n int, err error) {
valueToUint32 := _(_uint32)(unsafe.Pointer(&value))
return writer.Write([]byte{0xca, byte(valueToUint32 >> 24), byte(valueToUint32 >> 16), byte(valueToUint32 >> 8), byte(valueToUint32)})
}

// Packs a given value and writes it into the specified writer.
func PackFloat64(writer io.Writer, value float64) (n int, err error) {
valueToUint64 := _(_uint64)(unsafe.Pointer(&value))
return writer.Write([]byte{0xcb, byte(valueToUint64 >> 56), byte(valueToUint64 >> 48), byte(valueToUint64 >> 40), byte(valueToUint64 >> 32), byte(valueToUint64 >> 24), byte(valueToUint64 >> 16), byte(valueToUint64 >> 8), byte(valueToUint64)})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant