ToFloat64Array converts the value to float64 slice if it's a Float64Array.
()
| 1005 | |
| 1006 | // ToFloat64Array converts the value to float64 slice if it's a Float64Array. |
| 1007 | func (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. |
| 1031 | func (v *Value) ToBigInt64Array() ([]int64, error) { |