Hi Madhivanan,
I populated temp table using methods you suggested and did some comparisons(see code below.)
drop table #t
select number,
ceiling((power(1.61803398874989,number )-POWER(-1/1.61803398874989,number))/SQRT(5)) as method1,
round(((power((1+SQRT(5))/2.0,number )-POWER(-1/(1+SQRT(5))/2.0,number))/SQRT(5)),0) as method2,
floor(power((1+SQRT(5))/2.0,number )/sqrt(5)+0.5) as method3,
cast(null as float) as QuirkyUpdate
into #t
from master..spt_values
where TYPE='p' and number between 0 and 100
--Implicit conversion to float happens to method1,method2 and method3 as we can see from
select typename(xtype),name
from syscolumns
where id=objectid('tempdb..#t')
declare @fib table(fibid float,fibval float)
declare @currentval float, @previousval float,@newval float
insert into @fib(fibid,fibval )
select cast(number as float),1
from master..sptvalues
where TYPE='p' and number between 1 and 100
select @currentval =0, @previousval=-1,@newval =1
update @fib
set fibval =@currentval,
@currentval =@newval +@previousval,
@previousval=@newval,
@newval=@currentval
update #t
set QuirkyUpdate=fibval
from @fib
where fibid=number+1
select * from #t
select min(number) from #t where method1<>QuirkyUpdate
--63
select min(number) from #t where method2<>QuirkyUpdate
--71
select min(number) from #t where method2!=method3
--77
It shows that method 1 is limited to the first 62 numbers and then gives incorrect results.
QuirkyUpdate is better but up to number 72.
Methods 2 and 3 appear more reliable, but because of the nature of float datatype it's hard to say if they are correct for higher numbers.
But calculating high values of fib numbers is more mental exersize than practical.
So we can use either of your methods(I prefer method3 as the shortest) if numbers of interest are under known limits.
Leonid