buf.readDoubleLE(offset)


  • offset <integer> 开始读取的偏移量。必须满足0 <= offset <= buf.length - 8
  • 返回: <number>

用指定的字节序格式(readDoubleBE() 返回大端序, readDoubleLE() 返回小端序)从 buf 中指定的 offset 读取一个 64 位双精度值。

const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);

console.log(buf.readDoubleBE(0));
// 输出: 8.20788039913184e-304
console.log(buf.readDoubleLE(0));
// 输出: 5.447603722011605e-270
console.log(buf.readDoubleLE(1));
// 抛出异常 ERR_OUT_OF_RANGE。
  • offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8.
  • Returns: <number>

Reads a 64-bit double from buf at the specified offset with specified endian format (readDoubleBE() returns big endian, readDoubleLE() returns little endian).

const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);

console.log(buf.readDoubleBE(0));
// Prints: 8.20788039913184e-304
console.log(buf.readDoubleLE(0));
// Prints: 5.447603722011605e-270
console.log(buf.readDoubleLE(1));
// Throws ERR_OUT_OF_RANGE