When I write a float to the buffer, it does not read the same value:
> var b = new Buffer(4);
undefined
> b.fill(0)
undefined
> b.writeFloatBE(3.14159,0)
undefined
> b.readFloatBE(0)
3.141590118408203
>
(^C again to quit)
>
Why?
EDIT:
My working theory is that since javascript saves all numbers as double precision, it is possible that the buffer implementation does not have a null value for the remaining 4 bytes of double when it reads the float back:
> var b = new Buffer(4)
undefined
> b.fill(0)
undefined
> b.writeFloatBE(0.1,0)
undefined
> b.readFloatBE(0)
0.10000000149011612
>
I think this suggests that we have zeros for 7 digits after the decimal (well, actually, 8), and then there is trash. I think there is an error in the node buffer that reads these floats. This is what I think. This is node version 0.10.26.
source
share