1

I have an array of arraybuffers, meaning that I have

array[1] -> once this is clicked on, in the console, it holds this 

[object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer][object ArrayBuffer]

I have to take these arraybuffers and turn them back into arrays that I can read from. Originally, I had only one of these and was using

    temp_float_array = new Float32Array(arr_buff); //turns array buffer data from hex bytes to an array of floats
    for (var i = 0; i < temp_float_array.length; i++) {
        float_array[i] = parseFloat(temp_float_array[i]);
    }

to take the arraybuffer and turn it into a float32array, and then from there using parseFloat to make it a normal array. Now that I have a lot of these arraybuffers I need to turn each one to a human readable array. Thanks for any help or advice.

Each arraybuffer holds about 50K values in it,

[-91.51844787597656,-91.5179443359375,-91.5174560546875,-91.51744842529297,-91.55493927001953,-91.5665283203125,-91.57928466796875,-91.59294128417969,-91.607177734375,-91.62168884277344...etc]

ideally I need these values back just as they are.

1
  • To round trip FP to text to the same FP needs at least 9 significant digits in text for float32. To round trip text to FP to the same text, do not have more than 6 significant in text. If text-fp-text needs more than 6 significant digits, use float64, good for 15. Commented May 27, 2021 at 19:01

1 Answer 1

1

For anybody in the future this is what I ended up doing.

    temp_float_array = new Float32Array(arr_buff); //turns array buffer data from hex bytes to an array of floats
            for (var j = 0; j < temp_float_array.length; j++) {
                part_arr[j] = parseFloat(temp_float_array[j]);
            }
            float_array = float_array + part_arr;

I used a nested for loop. This was inside of my main for loop, arr_buff was each individual arraybuffer. This gave me an array of float32 arrays for each arraybuffer. Outside of my main for loop I then had

float_array = float_array.split(',');
for (var u = 0; u < float_array.length; u++) {
    float_array[u] = parseFloat(float_array[u]);
}

Splitting the values at the commas and then taking float_array, which now has my array of float32 arrays and then turned that into one massive array with a few million values. Not the cleanest or fastest solution I'm sure, but my working solution for now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.