+ 1
When to use Float32Array or something like that?
I don't know clearly what Float32Array and his friends are, such as Float64Array, Int32Array, Uint32Array, and I don't know what it is. Can someone tell me?
3 odpowiedzi
+ 1
Numbers in javascript are a weird mix of whole numbers (integer/int) and floating point numbers (float). That's fine most of the time but sometimes you need more control.
For example, take the html <canvas>. It is made up of pixels, each pixel is exactly 4 bytes long, one byte each for red, green, blue, and alpha.
In javascript we don't have a way to deal with individual bytes, and we don't really have a way to deal with whole numbers, so working on pixel data would be nearly impossible. Uint8ClampedArray to the rescue, there it is guaranteed that each element is a whole number that's 1 byte long, so a canvas' image data is stored in one of them.
I haven't used the Float arrays at all, but I think you'd need them when doing stuff with audio or the graphics card.
tl;dr sometimes it is important to have fixed-size datatypes.
Int: whole number
Float: number with a fraction
Uint: unsinged int, positive whole number
8, 16, 32, 64: Size in bits of the array elements
0
So it's like that
0
That's indeed how it is haha