I am trying to calculate the Nth number in the Fibonacci Sequence using Binet's Formula, however I have found the following two problems with my current implementation.
If N > 46 it overflows and if N is negative it doesnt work for some reason.
Here's my snippet of code.
Code:long double f(short N) { double phi = (1+pow(5,0.5))/2; return ceil((pow(phi,N) - pow(1-phi,N))/pow(5,0.5)); }