MCPcopy Create free account
hub / github.com/buke/quickjs-go / ToFloat64Array

Method ToFloat64Array

value.go:1007–1028  ·  view source on GitHub ↗

ToFloat64Array converts the value to float64 slice if it's a Float64Array.

()

Source from the content-addressed store, hash-verified

1005
1006// ToFloat64Array converts the value to float64 slice if it's a Float64Array.
1007func (v *Value) ToFloat64Array() ([]float64, error) {
1008 if !v.IsFloat64Array() {
1009 return nil, errors.New("value is not a Float64Array")
1010 }
1011
1012 buffer, byteOffset, byteLength, _ := v.getTypedArrayInfo()
1013 defer buffer.Free()
1014
1015 totalSize := uint(byteOffset + byteLength)
1016 bytes, err := buffer.ToByteArray(totalSize)
1017 if err != nil {
1018 return nil, err
1019 }
1020
1021 data := bytes[byteOffset : byteOffset+byteLength]
1022 result := make([]float64, len(data)/8)
1023 for i := 0; i < len(result); i++ {
1024 bits := binary.LittleEndian.Uint64(data[i*8:])
1025 result[i] = math.Float64frombits(bits)
1026 }
1027 return result, nil
1028}
1029
1030// ToBigInt64Array converts the value to int64 slice if it's a BigInt64Array.
1031func (v *Value) ToBigInt64Array() ([]int64, error) {

Callers 3

TestContextTypedArraysFunction · 0.80
unmarshalSliceMethod · 0.80
TestValueTypedArraysFunction · 0.80

Calls 6

IsFloat64ArrayMethod · 0.95
getTypedArrayInfoMethod · 0.95
NewMethod · 0.80
ToByteArrayMethod · 0.80
Uint64Method · 0.80
FreeMethod · 0.45

Tested by 2

TestContextTypedArraysFunction · 0.64
TestValueTypedArraysFunction · 0.64