decodeDouble function

double decodeDouble(
  1. List<int> buffer,
  2. int offset
)

Decodes 8 little-endian bytes from buffer at offset as an IEEE 754 double-precision float.

Throws a RangeError if fewer than 8 bytes are available at offset.

Implementation

double decodeDouble(List<int> buffer, int offset) {
  if (offset + 8 > buffer.length) {
    throw RangeError(
      'Not enough bytes to decode double at offset $offset '
      '(need 8, have ${buffer.length - offset})',
    );
  }
  final bd = ByteData(8);
  bd.setUint8(0, buffer[offset]);
  bd.setUint8(1, buffer[offset + 1]);
  bd.setUint8(2, buffer[offset + 2]);
  bd.setUint8(3, buffer[offset + 3]);
  bd.setUint8(4, buffer[offset + 4]);
  bd.setUint8(5, buffer[offset + 5]);
  bd.setUint8(6, buffer[offset + 6]);
  bd.setUint8(7, buffer[offset + 7]);
  return bd.getFloat64(0, Endian.little);
}