-- -*-ada-*- -- ===================================================================== -- 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, and reaches it (to -- machine precision) at 41 terms: the fourth item on each line is -- the difference from the golden ratio). -- ===================================================================== with Ada.Text_IO; use Ada.Text_IO; with Ada.Long_Long_Integer_Text_IO; use Ada.Long_Long_Integer_Text_IO; with Ada.Long_Long_Float_Text_IO; use Ada.Long_Long_Float_Text_IO; with Ada.Numerics.Long_Long_Elementary_Functions; use Ada.Numerics.Long_Long_Elementary_Functions; procedure Fibonacci3 is Golden_Ratio : Long_Long_Float := (1.0 + Sqrt(5.0))/2.0; Lo : Long_Long_Integer := 1; Hi : Long_Long_Integer := 1; N : Long_Long_Integer := 1; Ratio : Long_Long_Float; begin Put(N, Width => 2); Put(Lo); New_Line; while Hi > 0 loop N := N + 1; Ratio := Long_Long_Float(Hi)/Long_Long_Float(Lo); Put(N, Width => 2); Put(ASCII.HT); Put(Hi, Width => 19); Put(ASCII.HT); Put(Ratio, Fore => 2, Aft => 15, Exp => 0); Put(ASCII.HT); Put(Ratio - Golden_Ratio, Fore => 2, Aft => 15, Exp => 0); New_Line; Hi := Lo + Hi; Lo := Hi - Lo; end loop; end Fibonacci3;