Problem using pow(2,floor(log2(N)))

In the FIBEASY question

I have used a section of code for calculating the nearest number which can be expressed as 2^k, where k is some number.

First approach by using : floor(log2(N))

Secod approach by using :

    ll pos = 0 ;
	while (N >>= 1) ++pos;

N has a limit of 10^18;

First approach :
This fails in the second subtask.

Using bitwise shift gives an AC.

Any ideas why the first method fails…?

See this post, and the one linked from it.

I used log2((long double) N ) and it worked…But i cant figure out why?