
Binet's Formula
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(1phi,N))/pow(5,0.5));
}

I don't see why it would overflow at 46  however, if your intermediate results are double (such as the phi, pow(), ceil() etc), there's little point in using long double for the result.
Negative N is unlikely to be solved with this formula, as x^N would not be anywhere similar to what the definition of the Fibonacci series defines for negative N. I'm pretty sure that Binet's formula is not valid for negative N.

Mats