I'm not sure you're understanding that the problem has nothing to do with the int conversion, it's due to the loss of precision in the log and divide operations. If you've ever taken a Numerical Analysis course, you may recall the many dangers of working with floating point numbers. In general, what you want to do is impossible for arbitrary real numbers; for example, 2^70 and (2^70)-1 are both represented by the same floating point number, so there's no way to tell that log2 of the first is 70 while log2 of the second is 69.
I would probably use something like this. It's rather ugly (and untested) but it should be more accurate than using logs.
function Log2(x as Double) as Integer
lg = 0
val = 1.0
while x > val
lg = lg + 1
val = val * 2
end while
return lg
end function
--Mark