1 CALC - An arbitrary precision calculator.
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.
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.
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', 'local',
30 or 'static'. Global variables are common to all functions and the
31 command line, whereas local variables are unique to each function
32 level, and are destroyed when the function returns. Static variables
33 are scoped within single input files, or within functions, and are
34 never destroyed. Variables are not typed at definition time, but
35 dynamically change as they are used. So you must supply the correct
36 type of variable to those functions and operators which only work
37 for a subset of types.
39 Calc has a help command that will produce information about
40 every builtin function, command as well as a number of other
41 aspects of calc usage. Try the command:
45 for and overview of the help system. The command:
49 provides information on built-in mathematical functions, whereas:
53 will provides information a specific function. The following
62 provide a good overview of the calc language. If you are familiar
63 with C, you should also try:
67 It contains information about differences between C and calc
68 that may surprize you.
70 To learn about calc standard resource files, try:
74 To learn how to invoke the calc command and about calc -flags, try:
78 To learn about calc shell scripts, try:
82 A full and extensive overview of calc may be obtained by:
86 By default, arguments to functions are passed by value (even
87 matrices). For speed, you can put an ampersand before any
88 variable argument in a function call, and that variable will be
89 passed by reference instead. However, if the function changes
90 its argument, the variable will change. Arguments to built-in
91 functions and object manipulation functions are always called
92 by reference. If a user-defined function takes more arguments
93 than are passed, the undefined arguments have the null value.
94 The 'param' function returns function arguments by argument
95 number, and also returns the number of arguments passed. Thus
96 functions can be written to handle an arbitrary number of
99 The mat statement is used to create a matrix. It takes a
100 variable name, followed by the bounds of the matrix in square
101 brackets. The lower bounds are zero by default, but colons can
102 be used to change them. For example 'mat foo[3, 1:10]' defines
103 a two dimensional matrix, with the first index ranging from 0
104 to 3, and the second index ranging from 1 to 10. The bounds of
105 a matrix can be an expression calculated at runtime.
107 Lists of values are created using the 'list' function, and values can
108 be inserted or removed from either the front or the end of the list.
109 List elements can be indexed directly using double square brackets.
111 The obj statement is used to create an object. Objects are
112 user-defined values for which user-defined routines are
113 implicitly called to perform simple actions such as add,
114 multiply, compare, and print. Objects types are defined as in
115 the example 'obj complex {real, imag}', where 'complex' is the
116 name of the object type, and 'real' and 'imag' are element
117 names used to define the value of the object (very much like
118 structures). Variables of an object type are created as in the
119 example 'obj complex x,y', where 'x' and 'y' are variables.
120 The elements of an object are referenced using a dot, as in the
121 example 'x.real'. All user-defined routines have names composed
122 of the object type and the action to perform separated by an
123 underscore, as in the example 'complex_add'. The command 'show
124 objfuncs' lists all the definable routines. Object routines
125 which accept two arguments should be prepared to handle cases
126 in which either one of the arguments is not of the expected
129 These are the differences between the normal C operators and
130 the ones defined by the calculator. The '/' operator divides
131 fractions, so that '7 / 2' evaluates to 7/2. The '//' operator
132 is an integer divide, so that '7 // 2' evaluates to 3. The '^'
133 operator is a integral power function, so that 3^4 evaluates to
134 81. Matrices of any dimension can be treated as a zero based
135 linear array using double square brackets, as in 'foo[[3]]'.
136 Matrices can be indexed by using commas between the indices, as
137 in foo[3,4]. Object and list elements can be referenced by
138 using double square brackets.
140 The print statement is used to print values of expressions.
141 Separating values by a comma puts one space between the output
142 values, whereas separating values by a colon concatenates the
143 output values. A trailing colon suppresses printing of the end
144 of line. An example of printing is 'print \"The square of\",
147 The 'config' function is used to modify certain parameters that
148 affect calculations or the display of values. For example, the
149 output display mode can be set using 'config(\"mode\", type)',
150 where 'type' is one of 'frac', 'int', 'real', 'exp', 'hex',
151 'oct', or 'bin'. The default output mode is real. For the
152 integer, real, or exponential formats, a leading '~' indicates
153 that the number was truncated to the number of decimal places
154 specified by the default precision. If the '~' does not
155 appear, then the displayed number is the exact value.
157 The number of decimal places printed is set by using
158 'config(\"display\", n)'. The default precision for
159 real-valued functions can be set by using 'epsilon(x)', where x
160 is the required precision (such as 1e-50).
162 There is a command stack feature so that you can easily
163 re-execute previous commands and expressions from the terminal.
164 You can also edit the current command before it is completed.
165 Both of these features use emacs-like commands.
167 Files can be read in by using the 'read filename' command.
168 These can contain both functions to be defined, and expressions
169 to be calculated. Global variables which are numbers can be
170 saved to a file by using the 'write filename' command.
172 ## Copyright (C) 1999 Landon Curt Noll
174 ## Calc is open software; you can redistribute it and/or modify it under
175 ## the terms of the version 2.1 of the GNU Lesser General Public License
176 ## as published by the Free Software Foundation.
178 ## Calc is distributed in the hope that it will be useful, but WITHOUT
179 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
180 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
181 ## Public License for more details.
183 ## A copy of version 2.1 of the GNU Lesser General Public License is
184 ## distributed with calc under the filename COPYING-LGPL. You should have
185 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
186 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
188 ## @(#) $Revision: 30.1 $
189 ## @(#) $Id: overview,v 30.1 2007/03/16 11:10:42 chongo Exp $
190 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/overview,v $
192 ## Under source code control: 1991/07/21 04:37:23
193 ## File existed as early as: 1991
195 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
196 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/