Looking for a better way to calculate the fibonacci function using a mathematical formula.
I've tried the following formula without success:
fib(n) = ((1 + 5^0.5) / 2)^n - ((1 - 5^0.5) / 2)^n / 5^0.5
const fib=(n)=>{
return ((1+(5**0.5))/2)**n-((1-(5**0.5))/2)**n/(5**0.5)
}
If anyone has a different approach, I would greatly appreciate it. Thank you.