I'm using TypedArray to append binary data into a file on the device. The data I'm collecting are from the accelerometer, and I would like to store those data with only 3 decimal values, which I achieve by doing so:
accel.x ? accel.x.toFixed(3) : 0;
I tried to use both Float32Array and Float64Array for my TypedArray and when I try to read from the file the bytes I just wrote (to make sure i got everything working properly, and I do) I see that whenever I'm using Float64Bytes I successfully have the 3 digit precision I was asking for in that previous piece of code, but when I'm using Float32Array, for some reason I can't get a 3 digit precision, but rather a 14 digit precision.
It's not a big deal, because my code is still working, but I'm using TypedArray to optimize storage use and I'm wondering if there might be a bug. I shouldn't be getting a 14 digit precision, it should be 7, like any other C-like float variable. I'm afraid that my program might end up using more memory than it should have.
A little update after a further investigation: by monitoring the memory usage through the MemoryUsage interface and the "used" property, I have found that using Float32Array still allows me to use less memory compared to Float64Array. At this point, my idea that there might be a bug either in JerryScript or in JavaScript becomes more realistic. There is not way a get a 14 digit precision from a 32 bit float.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Here is two samples of the same code. I just changed the part related to the Typed Arrays:
- 32bit:
Best AnswerIs there a chance that the problem is with toFixed()? It's been reported as buggy elsewhere.
Best Answerwell if it were, i don't think it makes sense that it would act weird only when using Float32Array
but who knows, it could be it
Best AnswerMoreover, if I try to console.log my data before putting into the Float32Array, it correctly shows 3 decimal digits.
Best Answer