home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Utilities / Calc / help / overview < prev    next >
Encoding:
Text File  |  1992-02-24  |  6.6 KB  |  128 lines  |  [TEXT/????]

  1.             CALC - An arbitrary precision calculator.
  2.                 by David I. Bell
  3.  
  4.  
  5.     This is a calculator program with arbitrary precision arithmetic.
  6.     All numbers are represented as fractions with arbitrarily large
  7.     numerators and denominators which are always reduced to lowest terms.
  8.     Real or exponential format numbers can be input and are converted
  9.     to the equivalent fraction.  Hex, binary, or octal numbers can be
  10.     input by using numbers with leading '0x', '0b' or '0' characters.
  11.     Complex numbers can be input using a trailing 'i', as in '2+3i'.
  12.     Strings and characters are input by using single or double quotes.
  13.  
  14.     Commands are statements in a C-like language, where each input
  15.     line is treated as the body of a procedure.  Thus the command
  16.     line can contain variable declarations, expressions, labels,
  17.     conditional tests, and loops.  Assignments to any variable name
  18.     will automatically define that name as a global variable.  The
  19.     other important thing to know is that all non-assignment expressions
  20.     which are evaluated are automatically printed.  Thus, you can evaluate 
  21.     an expression's value by simply typing it in.
  22.  
  23.     Many useful built-in mathematical functions are available.  Use
  24.     the 'show builtins' command to list them.  You can also define
  25.     your own functions by using the 'define' keyword, followed by a
  26.     function declaration very similar to C.  Functions which only
  27.     need to return a simple expression can be defined using an
  28.     equals sign, as in the example 'define sc(a,b) = a^3 + b^3'.
  29.     Variables in functions can be defined as either 'global' or
  30.     'local'.  Global variables are common to all functions and the
  31.     command line, whereas local variables are unique to each
  32.     function level, and are destroyed when the function returns.
  33.     Variables are not typed at definition time, but dynamically
  34.     change as they are used.  So you must supply the correct type
  35.     of variable to those functions and operators which only work
  36.     for a subset of types.
  37.  
  38.     By default, arguments to functions are passed by value (even
  39.     matrices).  For speed, you can put an ampersand before any
  40.     variable argument in a function call, and that variable will be
  41.     passed by reference instead.  However, if the function changes
  42.     its argument, the variable will change.  Arguments to built-in
  43.     functions and object manipulation functions are always called
  44.     by reference.  If a user-defined function takes more arguments
  45.     than are passed, the undefined arguments have the null value.
  46.     The 'param' function returns function arguments by argument
  47.     number, and also returns the number of arguments passed.  Thus
  48.     functions can be written to handle an arbitrary number of
  49.     arguments.
  50.  
  51.     The mat statement is used to create a matrix.  It takes a
  52.     variable name, followed by the bounds of the matrix in square
  53.     brackets.  The lower bounds are zero by default, but colons can
  54.     be used to change them.  For example 'mat foo[3, 1:10]' defines
  55.     a two dimensional matrix, with the first index ranging from 0
  56.     to 3, and the second index ranging from 1 to 10.  The bounds of
  57.     a matrix can be an expression calculated at runtime.
  58.  
  59.     Lists of values are created using the 'list' function, and values can
  60.     be inserted or removed from either the front or the end of the list.
  61.     List elements can be indexed directly using double square brackets.
  62.  
  63.     The obj statement is used to create an object.  Objects are
  64.     user-defined values for which user-defined routines are
  65.     implicitly called to perform simple actions such as add,
  66.     multiply, compare, and print. Objects types are defined as in
  67.     the example 'obj complex {real, imag}', where 'complex' is the
  68.     name of the object type, and 'real' and 'imag' are element
  69.     names used to define the value of the object (very much like
  70.     structures).  Variables of an object type are created as in the
  71.     example 'obj complex x,y', where 'x' and 'y' are variables.
  72.     The elements of an object are referenced using a dot, as in the
  73.     example 'x.real'. All user-defined routines have names composed
  74.     of the object type and the action to perform separated by an
  75.     underscore, as in the example 'complex_add'.  The command 'show
  76.     objfuncs' lists all the definable routines.  Object routines
  77.     which accept two arguments should be prepared to handle cases
  78.     in which either one of the arguments is not of the expected
  79.     object type.
  80.  
  81.     These are the differences between the normal C operators and
  82.     the ones defined by the calculator.  The '/' operator divides
  83.     fractions, so that '7 / 2' evaluates to 7/2. The '//' operator
  84.     is an integer divide, so that '7 // 2' evaluates to 3.  The '^'
  85.     operator is a integral power function, so that 3^4 evaluates to
  86.     81.  Matrices of any dimension can be treated as a zero based
  87.     linear array using double square brackets, as in 'foo[[3]]'.
  88.     Matrices can be indexed by using commas between the indices, as
  89.     in foo[3,4].  Object and list elements can be referenced by
  90.     using double square brackets.
  91.  
  92.     The print statement is used to print values of expressions.
  93.     Separating values by a comma puts one space between the output
  94.     values, whereas separating values by a colon concatenates the
  95.     output values.  A trailing colon suppresses printing of the end
  96.     of line.  An example of printing is 'print \"The square of\",
  97.     x, \"is\", x^2\'.
  98.  
  99.     The 'config' function is used to modify certain parameters that
  100.     affect calculations or the display of values.  For example, the
  101.     output display mode can be set using 'config(\"mode\", type)',
  102.     where 'type' is one of 'frac', 'int', 'real', 'exp', 'hex',
  103.     'oct', or 'bin'.  The default output mode is real.  For the
  104.     integer, real, or exponential formats, a leading '~' indicates
  105.     that the number was truncated to the number of decimal places
  106.     specified by the default precision.  If the '~' does not
  107.     appear, then the displayed number is the exact value.
  108.  
  109.     The number of decimal places printed is set by using
  110.     'config(\"display\", n)'.  The default precision for
  111.     real-valued functions can be set by using 'epsilon(x)', where x
  112.     is the required precision (such as 1e-50).
  113.  
  114.     There is a command stack feature so that you can easily
  115.     re-execute previous commands and expressions from the terminal.
  116.     Each command is labeled with a two digit number. To execute a
  117.     command again, type '`n', where n is the number for the command
  118.     to be executed.  Using '`-n' re-execute the command which is
  119.     the n'th command back.  Using '``' re-executes the previous
  120.     command, and is a shortcut for typing '`-1'.  The '`h n'
  121.     command just displays the previous n commands (20 if n is not
  122.     given).
  123.  
  124.     Files can be read in by using the 'read filename' command.
  125.     These can contain both functions to be defined, and expressions
  126.     to be calculated.  Global variables which are numbers can be
  127.     saved to a file by using the 'write filename' command.
  128.