home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 216.lha / RexxArpLib_v2.1 / rexx / Calc.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-02-15  |  2.8 KB  |  99 lines

  1. /* 
  2. USING CALC
  3.  
  4. CALC is a simple quite sophisticated calculator program which
  5. allows you to carry out all sorts of numerical calculations
  6. using algebraic format.  If you type a line like
  7.       2**4
  8. then CALC will define a variable ans and set it equal to the
  9. result of the calculation.  If however you type
  10.       X = 2**4*SIN(14)
  11. then the variable X will become defined and will be set
  12. equal to the numerical result of the computation.
  13. All of the special functions in the ieee library can be called
  14. from inside of calc; e.g., sin(), cos(), tan(), asin(), acos(),
  15. exp(), sinh(), etc.
  16. If you call a function (i.e. use sin()) then CALC recognizes
  17. the () and doesn't set ans equal to the result of the call.
  18. In this case it will return the value and give an error message.
  19. To avoid the message always set the result of a function call
  20. equal to something; e.g.,
  21.        PI = 2*ACOS(0)
  22.  
  23. By default calc echos all commands typed.  If you want to turn 
  24. this feature off say ECHO OFF.  To restore it type ECHO ON.
  25. To define a rexx function which can be called from CALC say
  26. EDIT (synonym PROGRAM) and you will be thrown into TxEd Plus.
  27. Type the rexx program and file it under the name you want;
  28. for example, rexx:foo.rexx .
  29. When you exit the editor you will be back in CALC.
  30.  
  31. To leave CALC type QUIT.
  32. */
  33. arg x
  34.  
  35. if x = ? then do
  36.    y = sourceline(2)
  37.    line = ""
  38.      do i = 3 until y = "*/"||'0a'x
  39.         line = line||y
  40.         y = sourceline(i)
  41.      end
  42.    say line
  43.    exit
  44. end 
  45.  
  46.  
  47. START:
  48. SIGNAL ON ERROR
  49. SIGNAL ON SYNTAX
  50. address command
  51.  
  52. OPTIONS FAILAT 30
  53. echo = 1
  54. do i = 1
  55.   call open('CALCWIN','con:0/0/400/400//')
  56.   call writech(CALCWIN,"?  ")
  57.   equation = readln(CALCWIN)
  58.   equalloc = index(equation,"=")
  59.   parloc = index(equation,"(")
  60.   ifloc = index(equation, "IF ")
  61.   select
  62.  
  63.     when equation = "QUIT" | equation = "quit" then exit 0
  64.     when ifloc ~=0 then interpret equation
  65.     when equation = "EDIT" | equation = "edit" then "runwsh e"
  66.     when equation = "" then iterate
  67.     when equalloc = 0 then do
  68.        if equation = "ECHO OFF" then do
  69.              echo = 0
  70.              iterate
  71.              end
  72.        if equation = "ECHO ON" then do
  73.              echo = 1
  74.              iterate
  75.              end
  76.        if parloc ~=0 then do
  77.              interpret equation
  78.              iterate
  79.              end
  80.        interpret "ans = "equation
  81.        ansstring = equation" = "ans
  82.        call writeln(CALCWIN,"    "ansstring)
  83.        end
  84.     otherwise do
  85.      parse var equation leftside "=" rightside
  86.      INTERPRET "ans = "rightside
  87.      if echo = 1 then call writeln(CALCWIN,"     "leftside" = "ans)
  88.      INTERPRET leftside" = "rightside
  89.      end
  90.   end 
  91. end
  92. exit
  93. ERROR:
  94.    if rc > 0 then call writeln(CALCWIN,"you made a mistake")
  95.    SIGNAL VALUE START
  96. SYNTAX:
  97.    call writeln(CALCWIN,"you made a syntax error, bubbalah!")
  98.    SIGNAL VALUE START
  99.