Skip to content

pack float data wrong #4

Open
Open
@alex-hsl

Description

@alex-hsl

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)})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions