#! /bin/ksh93 ### ====================================================================== ### Print a table of representable Fibonacci sequence values. Among ### the various common UNIX shells in the Bourne and C shell families, ### only ksh93 (or later) provides floating-point arithmetic. ### ### Usage: ### ./Fibonacci3.ksh93 >outfile ### or ### ksh93 Fibonacci3.ksh93 >outfile ### ### [17-Aug-2005] ### ====================================================================== Fibonacci() { typeset -E golden_ratio ratio typeset -i lo hi n lo=hi=n=1 ## golden_ratio=$(((1 + sqrt(5)) / 2)) golden_ratio=1.61803398874989484820458683436563816 printf "%2d\t%11d\n" $n $lo while [[ $hi -gt 0 ]] do n=$n+1 ratio=$hi ratio=$((ratio / lo)) printf "%2d\t%11d\t%19.15f\t%19.15f\n" $n $hi $ratio $(($ratio - $golden_ratio)) hi=$lo+$hi lo=$hi-$lo done } Fibonacci