public static double extendedToDouble(byte[] buf) throws NumberFormatException {
        ByteBuffer b = ByteBuffer.wrap(buf, 0, 10).order(ByteOrder.BIG_ENDIAN);
        int e = b.getShort();
        double sign = ((e & 0x80) != 0) ? -1 : 1;
        e &= 0x7fff;
        long m = b.getLong();

        double normal = (m & 0x8000000000000000L) != 0 ? 1 : 0;
        m &= 0x7fffffffffffffffL;

        if (m == 0) {
            return 0;
        } else {
            if (e == 0) {
                e = -16382;
            } else if ((e & 0x7fff) == 0x7fff) {
                throw new NumberFormatException("NAN or Infinity");
            } else {
                e -= 16383;
            }
        }
		// Shifting the divisor by 62 bits and then dividing the result by 2 deals
        // with the fact that java does not having unsign longs
        return sign * (normal + (double) m / (1L << 62) / 2) * Math.pow(2.0, (float) e);
    }