-- double rd_dbl_basic(byte f1..8)
-- @f1..8 - The 8 bytes composing a little endian double

local function rd_dbl_basic(f1, f2, f3, f4, f5, f6, f7, f8)
	local sign = bit.rshift(f8, 7)
	local exp = bit.lshift(bit.band(f8, 0x7F), 4) + bit.rshift(f7, 4)
	local frac = bit.band(f7, 0x0F) * 2 ^ 48
	local normal = 1

	frac = frac + (f6 * 2 ^ 40) + (f5 * 2 ^ 32) + (f4 * 2 ^ 24) + (f3 * 2 ^ 16) + (f2 * 2 ^ 8) + f1 -- help

	if exp == 0 then
		if frac == 0 then
			return sign * 0
		else
			normal = 0
			exp = 1
		end
	elseif exp == 0x7FF then
		if frac == 0 then
			return sign * (1 / 0)
		else
			return sign * (0 / 0)
		end
	end

	return (-1) ^ sign * 2 ^ (exp - 1023) * (normal + frac / 2 ^ 52)
end
