Task

Calculate the value of   e.



(e   is also known as   Euler's number   and   Napier's constant.)



See details: Calculating the value of e

 
  [Calculate e]
  [EDSAC program, Initial Orders 2]
 
  [Library subroutine M3. Prints header and is then overwritten]
  [Here, last character sets teleprinter to figures]
   PFGKIFAFRDLFUFOFE@A6FG@E8FEZPF
   @&*CALCULATION!OF!E@&#
     ..PZ  [blank tape, needed to mark end of header text]
 
  [Library subroutine D6. Division, accurate, fast.
  Closed, 36 locations, working positions 6D and 8D.
  C(0D) := C(0D)/C(4D), where C(4D) <> 0, -1.]
     T56K  [define load address for subroutine]
     GKA3FT34@S4DE13@T4DSDTDE2@T4DADLDTDA4DLDE8@RDU4DLDA35@
     T6DE25@U8DN8DA6DT6DH6DS6DN4DA4DYFG21@SDVDTDEFW1526D
 
  [Library subroutine P1.
  Prints a single positive number (without layout or round-off).
  Prints number in 0D to n places of decimals, where
  n is specified by 'P n F' pseudo-order after subroutine call.
  Closed, 21 locations.]
    T92K  [define load address for subroutine]
   GKA18@U17@S20@T5@H19@PFT5@VDUFOFFFSFL4FTDA5@A2FG6@EFU3FJFM1F
    ..PZ
 
               [Main routine]
        T120K  [Define load address for main program.
                Must be even, because of double values at start.]
        GK     [set @ (theta) for relative addresses]
    [0] PF PF  [build sum 4*(1/3! + 1/4! + 1/5! + ...)]
    [2] PF PF  [term in sum]
    [4] PD PF  [2^-34, stop when term < this]
    [6] PF     [divisor]
    [7] IF     [1/2]
    [8] QF     [1/16]
    [9] @F     [carriage return]
   [10] &F     [line feed]
   [11] WF     [digit '2']
   [12] MF     [full stop / decimal point]
   [13] K4096F [teleprinter null]
 
   [14] A8@    [load 1/16]
        LD     [shift, makes 1/8]
        UD     [to 0D for subroutine D6]
        T6@    [divisor := 1/8]
        T#@    [sum := 0]
 
               [loop, acc assumed to be 0 here]
   [19] A6@    [load divisor]
        A8@    [add 1/16]
        U6@    [update divisor]
        T4D    [to 4D for subroutine D6]
   [23] A23@   [for subroutine return]
        G56F   [call D6]
        AD     [load quotient]
        U2#@   [store as term]
        A#@    [add term into sum]
        T#@    [update sum]
        A2#@   [load term]
        S4#@   [test for convergence]
        G36@   [jump out if so]
        A4#@   [restore term after test]
        R4F    [divide by 16]
        TD     [to 0D for subroutine D6]
        E19@   [loop back]
 
               [here when converged]
   [36] TF     [clear acc]
        A#@    [load sum]
        R1F    [shift to divide by 4]
        A7@    [add 1/2, now have (e - 2)]
        YF     [round]
        TD     [to 0D for subroutine P1]
        O11@   [print '2.']
        O12@
   [44] A44@   [for subroutine return]
        G92F   [call P1 to print (e - 2)]
        P10F   [10 decimals]
        O9@    [print CR]
        O10@   [print LF]
        O13@   [null to flush print buffer]
        ZF     [stop]
        E14Z   [relative address of entry]
        PF     [enter with accumulator = 0]
 