/* NetRexx version of Nelson H. F. Beebe's Fibonacci example. */ /* See: http://www.math.utah.edu/~beebe/software/java/fibonacci/ */ /* Adapted from Fibonacci3.rex which was written by mfc 2002.06.10 */ /* ----------------------------------------------------------------- */ /* Print ascending members of the Fibonacci sequence that are */ /* representable as 64-bit signed integers, prefixed by their term */ /* numbers, and followed by the ratio of successive terms, to */ /* demonstrate the 1.618...^n growth (the ratio approaches the */ /* golden ratio, (1 + sqrt(5))/2 = 1.6180339887498949. The fourth */ /* item on each line is the difference from the golden ratio). */ /* ------------------------------------------------------------------ */ /* NetRexx supports arbitrary precision floating-point arithmetic. */ /* For comparison with other programming languages, we limit it to */ /* work with 20 digits of precision. */ numeric digits 20 /* set working precision */ golden_ratio = (1 + Math.sqrt(5))/2 limit = 2**63 - 1 /* when to stop */ hi = 1 /* the integers */ lo = 1 /* .. */ n = 1 /* counter */ tab = '\x09' /* for output like the other samples */ say n tab lo loop while hi < limit n = n + 1 ratio = hi/lo say n tab hi tab ratio tab ratio-golden_ratio hi = lo + hi lo = hi - lo end