private static double ReadFP(Stream stream, int headByte)
{
int b;
if (headByte == 0xf9) {
// Half-precision
var bytes = new byte[2];
if (stream.Read(bytes, 0, bytes.Length) != bytes.Length) {
throw new IOException("Premature end of stream");
}
b = ((int)bytes[0]) & 0xff;
b <<= 8;
b |= ((int)bytes[1]) & 0xff;
return (double)HalfPrecisionToSingle(b);
}
if (headByte == 0xfa) {
var bytes = new byte[4];
if (stream.Read(bytes, 0, bytes.Length) != bytes.Length) {
throw new IOException("Premature end of stream");
}
b = ((int)bytes[0]) & 0xff;
b <<= 8;
b |= ((int)bytes[1]) & 0xff;
b <<= 8;
b |= ((int)bytes[2]) & 0xff;
b <<= 8;
b |= ((int)bytes[3]) & 0xff;
return (double)ToSingle(b);
}
if (headByte == 0xfb) {
var bytes = new byte[8];
if (stream.Read(bytes, 0, bytes.Length) != bytes.Length) {
throw new IOException("Premature end of stream");
}
long lb;
lb = ((long)bytes[0]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[1]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[2]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[3]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[4]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[5]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[6]) & 0xff;
lb <<= 8;
lb |= ((long)bytes[7]) & 0xff;
return (double)ToDouble(lb);
}
throw new IOException("Not a valid headbyte for ReadFP");
}