When converting data to/from a Buffer using 32-bit floating point numbers, it seems that nodejs extends the float to double using some criteria that makes the transformation not reversible:
(当使用32位浮点数将数据与Buffer之间进行数据转换时,似乎nodejs使用一些使转换不可逆的条件将float扩展为double:)
> f=3.81357913e+32
3.81357913e+32
> b.Buffer.alloc(4)
<Buffer 00 00 00 00>
> b.writeFloatBE(f)
4
> b
<Buffer 75 96 6b 4f>
So it seems that the original value (3.81357913e+32) is represented as 0x75966b4f (Big endian IEEE-754, single precision) Now, when you read the same value, you get a different value:
(因此,似乎原始值(3.81357913e + 32)表示为0x75966b4f(大端IEEE-754,单精度),现在,当您读取相同的值时,会得到一个不同的值:)
> b
<Buffer 75 96 6b 4f>
> b.readFloatBE()
3.813579129065691e+32
So the two values are different.
(因此,这两个值是不同的。)
I would expect the two values to be the same.(我希望这两个值是相同的。)
It seems the readFloatBE()
produces a 64-bit double-precision with arbitrary values.(似乎readFloatBE()
产生具有任意值的64位双精度。)
I understand when rounding a double to a float, you lose precision.
(我了解到将双精度数四舍五入为浮点数会失去精度。)
All the following numbers when reduced to float have the same encoded value:(以下所有数字减为float时,都具有相同的编码值:)
3.813579129099999e+32 -> 0x75966b4f
3.813579129065691e+32 -> 0x75966b4f
3.813579129000000e+32 -> 0x75966b4f
... but where is this value (3.813579129065691e+32) comes from?
(...但是这个值(3.813579129065691e + 32)从哪里来?)
(Tested with node.js v.11.12.0)
((已使用node.js v.11.12.0测试))
ask by fabrizi0 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…