home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / calc_v22.zip / CALC.DOC < prev    next >
Text File  |  1991-01-22  |  19KB  |  513 lines

  1.                calc version 2.2
  2.  
  3. NAME
  4.  
  5.      calc - "infinite" precision calculator
  6.  
  7.  
  8. VERSION
  9.  
  10.      2.2  22-Jan-1991  (COPYRIGHT (c) 1991 Frenz)
  11.  
  12.  
  13. SYNOPSIS
  14.  
  15.      calc [-h] [file ...] [-q]
  16.  
  17.  
  18. DESCRIPTION
  19.  
  20.      calc is a processor for an arithmetic language which has most of 
  21.      the operators of C and some others and also provides "infinite" 
  22.      precision numbers.  calc executes "calc programs" from any files
  23.      given on the command line and then reads from the standard input.
  24.  
  25.      calc provides "infinite" precision integer and real operations.
  26.      The maximum integer to be expressed would constitute 68,719,476,735
  27.      bits, which is roughly equivalent to 20,686,623,783 decimal digits.
  28.      Assuming you printed this number on paper with 60 lines per page, 
  29.      80 digits per line and both sides of the paper, this would require 
  30.      2,154,856 sheets of paper.  Thus, if you put 1,000 sheets into 1
  31.      book, this would require 2,155 books for just this one number.
  32.  
  33.      One must realize that this number would also consume 8.2 gigabytes
  34.      of memory, just one number!  Thus, even though this is not infinite 
  35.      precision, most users will not actually reach this limit.
  36.  
  37.      Note however, that some operations only compute efficently for 
  38.      numbers less than 4,294,967,295 bits or 1,292,913,986 decimal digits. 
  39.      This number would require about 500MB of memory.
  40.  
  41.  
  42. OPTIONS
  43.  
  44.      -h   Print a help message
  45.  
  46.      -q   quit processing.  Useful if a file is known not to have a
  47.           'quit' in it.
  48.  
  49.      file process this file as if the user was typing it
  50.  
  51.  
  52. VARIABLES
  53.  
  54.      Variables are allowed and can be up to 512 characters long.  
  55.      Variables in a "calc program" begin with a letter and are followed
  56.      by letters, digits or underscores.  Also, note that variables will
  57.      be case sensitive, in the spirit of C.  Therefore, the variable
  58.      "a_" will be different than "A_".
  59.  
  60.      A variable can also be designated as an array by following the
  61.      variable name with '[', an expression, and ']'.
  62.  
  63.  
  64. PREDEFINED VARIABLES
  65.  
  66.      last holds the result of the evaluation of the last expression.  
  67.           This is useful if you type in an expression without storing 
  68.           it in a variable and decide that you wanted the result.  Now 
  69.           it can be retrieved with this variable.  Thus, you should 
  70.           assign this to another variable if you really want the result
  71.       of the last expression saved.
  72.  
  73.      ibase
  74.           specifies the default input base of your numbers
  75.  
  76.      obase
  77.           specifies the default output base of your numbers
  78.  
  79.      scale
  80.           specifies the precision that calculations will be performed 
  81.           to and written out in
  82.  
  83.      width
  84.           the number of digits to print on a line
  85.  
  86.      pi   the constant pi to 28 decimal places (3.1415 ...)
  87.  
  88.      exp  the constant exp to 28 decimal places (2.718 ...)
  89.  
  90.  
  91. PREDEFINED WORDS
  92.      
  93.      break
  94.           used in loops, same meaning as in C
  95.  
  96.      continue
  97.           used in loops, same meaning as in C
  98.  
  99.      return 
  100.           used in functions, same meaning as in C
  101.  
  102.      stats
  103.           gives a short message about the current use of internal memory
  104.           used in the program
  105.           
  106.      quit quits the program
  107.  
  108.      help prints a help message regarding operators, predefined
  109.       functions, and user defined functions.
  110.  
  111. PREDEFINED FUNCTIONS
  112.  
  113.      trunc( num )
  114.           performs a truncation on the real number num, trunc( 3.7 ) = 3
  115.  
  116.      round( num )
  117.           rounds the real number num, round( 3.7 ) = 4
  118.  
  119.      choose( n1, n2 )
  120.           performs the choose function, or combinations, i.e.
  121.           choose( 20, 5 ) = 20! / ( 5! * 15!) = 15504
  122.  
  123.      factorial( num )
  124.           performs a factorial on the argument num, for example,
  125.           factorial( 6 ) = 6! = 720
  126.           note that this function is also called via the ! operator.
  127.  
  128.      lg( num )
  129.           performs a logarithm base 2 on the argument num 
  130.  
  131.      log( num )
  132.           performs a logarithm base 10 on the argument num 
  133.  
  134.      ln( num )
  135.           performs the natural logarithm on the argument num, i.e.
  136.           base 2.718...
  137.  
  138.      sqrt( num )
  139.           performs the square root of the given number
  140.  
  141.      sin( num )
  142.           returns the sine of num, where num is in radians
  143.  
  144.      cos( num )
  145.           returns the cosine of num, where num is in radians
  146.  
  147.      tan( num )
  148.           returns the tangent of num, where num is in radians
  149.  
  150.      asin( num )
  151.           returns the arc-sine of num, where num is in radians
  152.  
  153.      acos( num )
  154.           returns the arc-cosine of num, where num is in radians
  155.  
  156.      atan( num )
  157.           returns the arc-tangent of num, where num is in radians
  158.  
  159.      print( str, arg [, arg] )
  160.           works like the printf() function in C, str is the format
  161.           string, and the arguments follow.  A maximum of nine
  162.           arguments are allowed.
  163.  
  164.      loan( loan_amount, months, interest, payment )
  165.           given three non-zero arguments, this function will
  166.       calculate the fourth argument. 
  167.  
  168.      show( arg )
  169.           will display the argument arg on the screen. If arg is a
  170.       user defined function name with the parentheses, the full
  171.       definition of the function is displayed on the screen.  If
  172.       arg is an array name with the brackets, the full array is
  173.       displayed.
  174.  
  175.      save( file_name )
  176.           will save all user defined functions, variables, and arrays
  177.       to the specified file.
  178.  
  179.      load( file_name )
  180.           will read in the contents of the specified file.  This is useful
  181.           for loading already defined functions.
  182.  
  183.      read( variable )
  184.            will wait for the user to enter an expression, which is
  185.       evaluated and stored into the specified variable
  186.  
  187.  
  188. USER DEFINED FUNCTIONS
  189.  
  190.      You may write your own functions by entering the word "define" 
  191.      followed by a function definition.  For example, here is the
  192.      abs() function:
  193.  
  194.           define abs( num ) {
  195.              if ( num < 0 ) return -num;
  196.              return num;
  197.           }
  198.  
  199.      The value returned by a function will be the return expression or the
  200.      result of the last statement evaluated.  The result will be printed
  201.      if the return is used.
  202.  
  203.      If you need to declare that a function exists and want to define it
  204.      later do this:
  205.  
  206.           define later()
  207.           define now( arg1, arg2 ) {
  208.              /* some statements */
  209.           }
  210.           define later( arg1, arg2 ) {
  211.              /* some statements */
  212.           }
  213.  
  214.  
  215. STATEMENTS
  216.  
  217.      An statement is evaluated once a semicolon is entered or a newline 
  218.      is entered and the statement does not end with an operator.  The
  219.      result of a statement is printed unless the last operator
  220.      evaluated was an assignment or the "_" operator.  Also, a 
  221.      statement is not immediately evaluated if it is enclosed within 
  222.      another statement or a function.
  223.  
  224.      Remember the result of the last statement is stored in the
  225.      variable "last".  But don't use this variable within an expression.
  226.  
  227.      A statement can be any of the following:
  228.           expression
  229.           { statement; ...; statement; }
  230.           if ( expression ) statement
  231.           if ( expression ) statement else statement
  232.           while ( expression ) statement
  233.           for ( expression; expression; expression ) statement
  234.           break               /* only in a for or while loop */
  235.           continue            /* only in a for or while loop */
  236.           return expression   /* only in a function */
  237.           quit                /* action is immediate */
  238.  
  239.  
  240. EXPRESSIONS
  241.  
  242.      An expression can be any of the following:
  243.           variable 
  244.           number
  245.           function_call( arguments )
  246.           expression operator expression
  247.           ( expression )
  248.       unary-operator expression
  249.       expression unary-operator
  250.  
  251.      Note that only one pre/post-unary operator is allowed per 
  252.      expression.  Thus, "- -8" is not allowed, but "-( -8 )" is.
  253.  
  254.  
  255. OPERATORS
  256.  
  257.      The allowed operators are like those found in the 'C' language in 
  258.      addition to some others.  Here are the allowed operators in order 
  259.      of precedence:
  260.  
  261.           ,     _     =     <<=   >>=   &=    ^=    |=
  262.           +=    -=    *=    /=    %=    **=   ||    &&
  263.           |     ^     &     ==    !=    <     >     <=
  264.           >=    <<    >>    +     -     *     /     %
  265.           **    ~     !     ++    --    !     -
  266.     
  267.      The only operators not found in C are:
  268.  
  269.           _    which means to print a number in that base.  For 
  270.                example, '13 _ 2' will print '1101', and '13 _ 16'
  271.                will print 'D'.  The allowed output bases are 2
  272.                through 36, if another base is tried, base 10 is used.
  273.                This operator is equivalent to setting the variable
  274.                "obase".  However, using this operator you can see the 
  275.                value of the current expression as it evaluates.
  276.  
  277.           **   is the exponentiation operator.  For example, '5 ** 3'
  278.                will print '125', '2 ** 3 ** 2' will print '512' because
  279.            this operaotr has precedence from right to left.
  280.  
  281.           **=  is the assign exponentiation operator.  For example,
  282.                if the variable a has the value 5, 'a **= 3' will
  283.                assign the number 125 to the variable a.
  284.  
  285.           !    the factorial operator, 6! = 720, note that !6 is 0.
  286.  
  287.      Here is a brief explanation of the other C operators. For a full
  288.      explanation of these operators, see a C programming text book.
  289.      
  290.           ,    sequential expression, returns the result of the rightmost
  291.            expression
  292.       =    assignment
  293.       <<=  assign left shift, for example if a is 25, then "a <<= 2"
  294.            assigns the value 100 to the variable a. Shifting left
  295.            once is equivalent to multiplying by two, but bit shifting
  296.            is faster.
  297.       >>=  assign right shift, for example is a is 25, then "a >>= 2"
  298.            assigns the value 6 to the variable a. Shifting right once
  299.            is equivalent to dividing by two. If a is an integer, this
  300.            operation is not reversible. However, for real numbers,
  301.            this operation is reversible, note that in C bit operators 
  302.            only work for integer values.
  303.       &=   assign bitwise AND
  304.       ^=   assign bitwise XOR
  305.       |=   assign bitwise OR
  306.           +=   assign sum
  307.       -=   assign difference
  308.       *=   assign product
  309.       /=   assign quotient
  310.       %=   assign remainder
  311.       ||   logical or
  312.       &&   logical and
  313.       |    bitwise OR
  314.       ^    bitwise XOR
  315.       &    bitwise AND
  316.       ==   equal
  317.       !=   not equal
  318.       <    less than
  319.       >    greater than
  320.       <=   less or equal
  321.           >=   greater or equal
  322.       <<   left shift
  323.       >>   right shift
  324.       +    addition
  325.       -    subtraction
  326.       *    multiplication
  327.       /    division
  328.       %    remainder
  329.           ~    bitwise negation
  330.       !    logical negation
  331.       ++   increment
  332.       --   decrement
  333.       -    unary minus
  334.  
  335.  
  336. NUMBERS
  337.  
  338.      Numbers can also have an embedded '_' within them, unlike C, and 
  339.      the presently allowed input bases are decimal (default), binary 
  340.      (0b), octal (0), and hexidecimal (0x).  However, by setting the
  341.      variable "ibase", a different base can be used.  Note that
  342.      regardless of what number "ibase" is set to, binary, octal, and
  343.      hexidecimal numbers can still be entered.
  344.  
  345.      Thus, if you type 'a = 0b1000', the number 8 will be assigned to
  346.      the variable a.  Also, if the backslash ('\') character is found 
  347.      in a number, the next character is read and skipped.  Thus, '12\34'
  348.      is interpreted as '124'.  This is useful for entering long numbers
  349.      that are several lines long.  Thus, a long number can be entered
  350.      by typing digits, a backslash, a return, and more digits.
  351.  
  352.      When numbers are printed, they are printed at 70 characters to a 
  353.      line.  You may change the variable "width" while running the program
  354.      to change the width.
  355.  
  356.      Both integers and reals are supported and are stored internally 
  357.      in binary.  Thus, there will be some loss of precision for real 
  358.      numbers that are not directly converted to binary.
  359.  
  360.  
  361. OTHER FILES IN DISTRIBUTION
  362.  
  363.      Along with this documentation and the CALC executable, are a set of
  364.      CALC programs which can be loaded either on the command line or via the
  365.      load() function after CALC begins.  The list of all files are:
  366.  
  367.           CALC.EXE    - the calculator executable
  368.           CALC.DOC    - this documentation
  369.       ABS.CLC    - an example defining an abs() function
  370.           LOAN.CLC    - an example using the print statements and loan()
  371.  
  372.           
  373. GENERAL INFORMATION
  374.    
  375.      calc also allows the use "/*" and "*/" as comment delimeters as 
  376.      in C.
  377.  
  378.      This program is not to be used in any way in another product to be 
  379.      sold in a commercial envrionment without the written consent of 
  380.      myself.  You may make any number of backup copies and distribute 
  381.      this program anywhere you want as long as no modifications 
  382.      are made to the documentation or binaries.  
  383.  
  384.      If you find this program to be useful, send $10 to:
  385.           Timothy C. Frenz 
  386.           5361 Amalfi Drive
  387.           Clay, NY 13041
  388.    
  389.      If you have any suggestions for improvements such as other 
  390.      functions to implement please send them to the above address.  If 
  391.      you find any errors, please send them to me also.
  392.  
  393. RELEASE HISTORY
  394.  
  395.      Version    Date and modifications
  396.  
  397.      2.2    22-Jan-1991
  398.         Added more functions ( read, loan ), enhanced others with
  399.         error messages, and improved efficiency of several functions
  400.         ( sqrt, ln, division, power ).  Allowed variables to be any
  401.         length up to 512 characters, previous limit was 12. User
  402.         defined functions allow any number of arguments, previous
  403.         limit was 6. 
  404.         
  405.      2.1    26-Jul-1990
  406.         Added more extra functions ( lg, ln, log, sqrt ), and 
  407.         added the functionality to raise a number to a real 
  408.         exponent.
  409.  
  410.      2.0    05-Apr-1990
  411.         Added while loops, for loops, if statements, and user 
  412.         defined functions to the capabilities of this program.
  413.         Added better error detection and corresponding messages.
  414.  
  415.      1.2    15-Feb-1990
  416.         Added some extra functions ( round, trunc, factorial, and
  417.         choose ), implemented REAL numbers converting all 
  418.         necessary functions, and added other predefined variables.
  419.  
  420.      1.1    02-Dec-1989
  421.         Added my own memory management functions to keep previously
  422.         used BIG_NUMs.  Overall efficiency of mathematical operations
  423.         is improved.
  424.  
  425.      1.0    23-Oct-1989
  426.         Initiall release of calc.
  427.  
  428.      
  429. DIAGNOSTICS
  430.  
  431.      If something is wrong with an expression an error message is 
  432.      printed and a '^' is placed under (or close to under) where the 
  433.      error occured.  Here is a list of error messages that could occur:
  434.           unmatched ')'
  435.           unmatched '('
  436.           unmatched '}'
  437.           unmatched '{'
  438.           unmatched ']'
  439.           unmatched '['
  440.           operator not valid at this point
  441.           only one pre-unary operator allowed
  442.           only one post-unary operator allowed
  443.           operator expected - parentheses not valid here
  444.           operator expected - variable not valid here
  445.           operator expected - number not valid here
  446.           illegal operator entered
  447.           operand expected
  448.           operator only valid for variables
  449.           the comma operator must be an expression separator.
  450.           only X arguments allowed in a function definition
  451.           a semicolon is expected here
  452.           return is only valid in a function
  453.           break and continue are only valid in loops
  454.    
  455.  
  456. LICENSE
  457.    
  458.      Copyright (C) 1991 Timothy Frenz, Clay, New York.
  459.      Everyone is permitted to copy and distribute verbatim copies of
  460.      this software and its corresponding documentation and license,
  461.      but modifying it in any form for someone other than yourself
  462.      is not allowed.  
  463.    
  464.                        COPYING POLICIES
  465.      
  466.      1. You may copy and distribute verbatim copies of the CALC program
  467.      as you receive it, in any medium, provided that you conspicuously and
  468.      appropriately publish on each copy a valid copyright notice
  469.      "Copyright (C) 1991 Timothy Frenz, Clay, New York"; keep intact the
  470.      notices on all files that refer to this License Agreement and to the
  471.      absence of any warranty; and give any other recipients of the CALC
  472.      program a copy of this License Agreement along with the program. You 
  473.      may charge a distribution fee for the physical act of transferring a 
  474.      copy, but not for the contents of the copy.
  475.  
  476.      2. Mere aggregation of another unrelated program with this program 
  477.      on a volume of a storage or distribution medium does not bring the
  478.      other program under the scope of these terms.
  479.      
  480.      3. You may not copy, sublicense, distribute or transfer the CALC
  481.      program except as expressly provided under this License Agreement.
  482.      Any attempt otherwise to copy, sublicense, distribute or transfer the
  483.      CALC program is void and your rights to use the CALC program under this
  484.      License agreement shall be automatically terminated.  However, parties
  485.      who have received computer software programs from you with this
  486.      License Agreement will not have their licenses terminated so long as
  487.      such parties remain in full compliance.
  488.      
  489.      4. If you wish to incorporate parts of the CALC program into other
  490.      programs whose distribution conditions are different, write to me.
  491.  
  492.      
  493.                                NO WARRANTY
  494.      
  495.      THE CALC PROGRAM DESCRIBED HEREIN IS PROVIDED WITH ABSOLUTELY NO 
  496.      WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT 
  497.      WHEN OTHERWISE STATED IN WRITING, THE CALC PROGRAM IS PROVIDED
  498.      "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  499.      INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  500.      MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE
  501.      RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
  502.      SHOULD THE CALC PROGAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
  503.      NECESSARY SERVICING, REPAIR OR CORRECTION.
  504.      
  505.      IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL I BE LIABLE TO 
  506.      YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER 
  507.      SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
  508.      OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR 
  509.      DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES
  510.      OR A FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED
  511.      BY MYSELF) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE 
  512.      POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  513.