log2 accepts a double and returns a double.
You don't show the declaration of Doffset, but I'm assuming you've also declared it as an int. Doubles are aproximations, so if log2 returns 2.999999999 storing it in an int will result in it being truncated to 2.