TECHNIQUE: BEFOREHAND COMPUTED CONSTANTS

Often used constants, for example LN(2), number Pi, number e, we can compute only once and put away its value into the code of the function. I describe the program for the automatic creating functions returning the value of a certain constant.

Example:
For computation of the Fibonacci numbers we can use the general formula including the value of SQRT(5). The following program computes the value SQRT(5) with maximum - say 2100 - significant digits and then creates the external SQRT5 function.

 Constant = SQRT(5, 2100) Output = "C:\REGINA\SQRT5.REX" call LINEOUT Output, "SQRT5: procedure; V = '' " do while Constant > 0   parse var Constant String 60 Constant   call LINEOUT Output, "V = V ||" String end call LINEOUT Output, "return V" exit SQRT: procedure ...

The result of program is the file C:\REGINA\SQRT5.REX that follows. We can use it as the internal or external function. It saves time about 35 seconds. The "trimmed" part of code of the SQRT5 function follows.

 SQRT5: procedure; V = '' V = V || 2.2360679774997896964091736687 V = V || 31276235440618359611525724270 V = V || 89724541052092563780489941441 V = V || 44083787822749695081761507737 V = V || 83504253267724447073863586360 V = V || 12153345270886677817319187916 V = V || 58112766453226398565805357613 V = V || 50417533785003423392414064442 V = V || 08643253909725259262722887629 V = V || 95174024406816117759089094984 V = V || 92371390729728898482088641542 V = V || 68989409913169357701974867888 V = V || 54420897541329561831769214999 V = V || 77424801530434115035957668332 V = V || 51249881517813940800056242085 V = V || 52435422355561063063428202340 V = V || 93331982933959746352271201341 V = V || 74961420263590473788550438968 ... return V

The following program

 P = 25 numeric digits P say SQRT(5, P) say SQRT5() + 0 exit ...

displays on the screen

 2.236067977499789696409174 2.236067977499789696409174

CONNECTIONS

 cover contents index main page