|
NAMEcalc - arbitrary precision calculatorSYNOPSIScalc [-c] [-C] [-d][-D calc_debug[:resource_debug[:user_debug]]] [-e] [-f filename] [-h] [-i] [-m mode] [-O] [-p] [-q] [-s] [-u] [-v] [[--] calc_cmd ...] #!/usr/local/bin/calc [optional_other_flags ...] -f DESCRIPTION
CALC COMMAND LINEWith no calc_cmd arguments, calc operates interactively. If one or more arguments are given on the command line and -s is NOT given, then calc will read and execute them and either attempt to go interactive according as the -i flag was present or absent.If -s is given, calc will not evaluate any calc_cmd arguments but instead make them available as strings to the argv() builtin function. Sufficiently simple commands with no no characters like parentheses, brackets, semicolons, '*', which have special interpretations in UNIX shells may be entered, possibly with spaces, until the terminating newline. For example:
calc 23 + 47 will print 70. However, command lines will have problems:
calc 23 * 47 calc -23 + 47 The first example above fails because the shell interprets the '*' as a file glob. The second example fails because '-23' is viewed as a calc option (which it is not) and do calc objects to that it thinks of as an unknown option. These cases can usually be made to work as expected by enclosing the command between quotes:
calc '23 * 47' calc "print sqrt(2), exp(1)" or in parentheses and quotes to avoid leading -'s as in:
calc '(-23 + 47)' One may also use a double dash to denote that calc options have ended as in:
calc -- -23 + 47 calc -q -- -23 + 47 If '!' is to be used to indicate the factorial function, for shells like csh(1) for which '!' followed by a non-space character is used for history substitution, it may be necessary to include a space or use a backslash to escape the special meaning of '!'. For example, the command:
print 27!^2 may have to be replaced by:
print 27! ^2 or print 27^2 Reading from standard input when calc is part of a pipe works as long as the -p flag is given to calc. For example, this will print chongo was here:
echo chongo was here | calc -p 'print fgetline(files(0));' while this does not:
echo chongo was here | calc 'print fgetline(files(0));' nor will this print chongo was here:
echo chongo was here | calc -i 'print fgetline(files(0));' This is because without -p, the interactive parser, in an effort to parse interactive commands, flushes data on standard input. CALC STARTUP FILESNormally on startup, if the environment variable $CALCRC is undefined and calc is invoked without the -q flag, or if $CALCRC is defined and calc is invoked with -e, calc looks for a file "startup" in the calc resource directory .calcrc in the user's home directory, and .calcinit in the current directory. If one or more of these are found, they are read in succession as calc scripts and their commands executed. When defined, $CALCRC is to contain a ':' separated list of names of files, and if calc is then invoked without either the -q or -e flags, these files are read in succession and their commands executed. No error condition is produced if a listed file is not found.If the mode specified by -m disables opening of files for reading, then the reading of startup files is also disabled as if -q was given. CALC FILE SEARCH PATHIf the environment variable $CALCPATH is undefined, or if it is defined and calc is invoked with the -e flag, when a file name not beginning with /, ~ or ./, is specified as in:
calc read myfile calc searches in succession:
./myfile ./myfile.cal /usr/local/lib/myfile /usr/local/lib/myfile.cal /usr/local/share/calc/custom/myfile /usr/local/share/calc/custom/myfile.cal If the file is found, the search stops and the commands in the file are executed. It is an error if no readable file with the specified name is found. An alternative search path can be specified by defining $CALCPATH in the same way as PATH is defined, as a ':' separated list of directories, and then invoking calc without the -e flag. Calc treats all open files, other than stdin, stdout and stderr as files available for reading and writing. One may present calc with an already open file using sh(1), ksh(1), bash(1)-like shells is to:
For more information use the following calc commands:
help help help overview help usage help environment help config SHELL SCRIPT MODEIf the first line of an executable file begins #! followed by the absolute pathname of the calc program and the first line ends with the flag -f as in:
#!/usr/local/bin/calc [optional_other_flags ...] -f the rest of the file will be processed in shell script mode. Note that -s -f must at the end of the initial ``#!'' line. Any other optional optional_other_flags must come before the -f flag. In shell script mode the contents of the file are read and executed as if they were in a file being processed by a read command, except that a "command" beginning with '#' followed by whitespace and ending at the next newline is treated as a comment. Any optional optional_other_flags will be parsed first followed by the later lines within the script itself. In shell script mode, -s is always assumed. In addition, -d and -p are automatically set if -i is not given. For example, if the file /tmp/mersenne:
#!/usr/local/bin/calc -q -f /* setup */ argc = argv(); program = argv(0); stderr = files(2); /* parse args */ if (argc != 2) { fprintf(stderr, "usage: %s exp0, program); abort "must give one exponent arg"; } exp = eval(argv(1)); if (!isint(exp) || exp < 0) { fprintf(stderr, "%s: exp must be non-negative integer0, program); abort "must give one exponent arg"; } /* print the mersenne number */ print "2^": exp : "-1 =", 2^exp-1; is made an executable file by:
chmod +x /tmp/mersenne then the command line:
/tmp/mersenne 127 will print:
2^127-1 = 170141183460469231731687303715884105727 Note that because -s is required in shell script mode non-dashed args are made available as strings via the argv() builtin function. Therefore:
2^eval(argv(1))-1 will print the decimal value of 2^n-1 whereas
2^argv(1)-1 will not. DATA TYPESFundamental builtin data types include integers, real numbers, rational numbers, complex numbers and strings.By use of an object, one may define an arbitrarily complex data types. One may define how such objects behave a wide range of operations such as addition, subtraction, multiplication, division, negation, squaring, modulus, rounding, exponentiation, equality, comparison, printing and so on. For more information use the following calc commands:
VARIABLESVariables in calc are typeless. In other words, the fundamental type of a variable is determined by its content. Before a variable is assigned a value it has the value of zero.The scope of a variable may be global, local to a file, or local to a procedure. Values may be grouped together in a matrix, or into a a list that permits stack and queue style operations. For more information use the following calc commands:
INPUT/OUTPUTA leading ``0x'' implies a hexadecimal value, a leading ``0b'' implies a binary value, and a ``0'' followed by a digit implies an octal value. Complex numbers are indicated by a trailing ``i'' such as in ``3+4i''. Strings may be delimited by either a pair of single or double quotes. By default, calc prints values as if they were floating point numbers. One may change the default to print values in a number of modes including fractions, integers and exponentials.A number of stdio-like file I/O operations are provided. One may open, read, write, seek and close files. Filenames are subject to `` '' expansion to home directories in a way similar to that of the Korn or C-Shell. For example:
For more information use the following calc command:
CALC LANGUAGEThe calc language is a C-like language. The language includes commands such as variable declarations, expressions, tests, labels, loops, file operations, function calls. These commands are very similar to their counterparts in C.The language also include a number of commands particular to calc itself. These include commands such as function definition, help, reading in resource files, dump files to a file, error notification, configuration control and status. For more information use the following calc command:
FILES
ENVIRONMENT
CREDITThe main chunk of calc was written by David I. Bell.The calc primary mirror, and calc bug report processing is performed by Landon Curt Noll. Landon Curt Noll maintains the master reference source, performs release control functions as well as other calc maintenance functions. Thanks for suggestions and encouragement from Peter Miller, Neil Justusson, and Landon Noll. Thanks to Stephen Rothwell for writing the original version of hist.c which is used to do the command line editing. Thanks to Ernest W. Bowen for supplying many improvements in accuracy and generality for some numeric functions. Much of this was in terms of actual code which I gratefully accepted. Ernest also supplied the original text for many of the help files. Portions of this program are derived from an earlier set of public domain arbitrarily precision routines which was posted to the net around 1984. By now, there is almost no recognizable code left from that original source. COPYING / CALC GNU LESSER GENERAL PUBLIC LICENSECalc is open software, and is covered under version 2.1 of the GNU Lesser General Public License. You are welcome to change it and/or distribute copies of it under certain conditions. The calc commands:
help copyright help copying help copying-lgpl should display the contents of the COPYING and COPYING-LGPL files. Those files contain information about the calc's GNU Lesser General Public License, and in particular the conditions under which you are allowed to change it and/or distribute copies of it. You should have received a copy of the version 2.1 of the GNU Lesser General Public License. If you do not have these files, write to:
Free Software Foundation, Inc. 51 Franklin Street Fifth Floor Boston, MA 02110-1301 USA Calc is copyrighted in several different ways. These ways include:
Copyright (C) year David I. Bell Copyright (C) year David I. Bell and Landon Curt Noll Copyright (C) year David I. Bell and Ernest Bowen Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen Copyright (C) year Landon Curt Noll Copyright (C) year Ernest Bowen and Landon Curt Noll Copyright (C) year Ernest Bowen This man page is:
Copyright (C) 1999-2021 Landon Curt Noll and is covered under version 2.1 GNU Lesser General Public License. CALC QUESTIONSIf you have a simple general question about calc, send Email to:
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
You may add additional words to your subject line. IMPORTANT: If your Email doesn't contain the above phrase, then we WILL NOT SEE your Email. PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line! Suggestion:
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html Please limit your questions to general questions about calc. We cannot go into great detail in our answers, nor can we do your homework, nor can we do much more than answer short general questions about calc. Please be patient as we cannot always respond to Email messages quickly. BUG REPORTS / BUG FIXESSend bug reports and bug fixes to:
calc-bugrept at asthe dot com NOTE: Remove spaces and replace 'at' with @, 'dot' with . NOTE: Yes, the Email address uses 'asthe', while the web site uses
'isthe'.
You MUST use following SPECIAL PHRASE in your Email Subject line:
You may add additional words to your subject line. Suggestion:
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html IMPORTANT: If your Email doesn't contain the above phrase, then we WILL NOT SEE your Email. PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line! See the BUGS source file or use the calc command:
help bugs for more information about bug reporting. Please be patient as we cannot always respond to Email messages quickly. CONTRIBUTING CODE TO CALCCalc is open source. Contributions of code are welcome.We welcome and encourage you to send us:
* calc resource files (cal/*.cal) * calc shell scripts (cscript/*.calc) * builtin functions that you have modified or written, i.e.: assocfunc.c comfunc.c func.c func.h listfunc.c matfunc.c qfunc.c zfunc.c * custom functions that you have modified or written (custom/*) * help files modified or written (help/*) * brief description of you added, fixed, improved in CHANGES * regression test cases (cal/regress.cal) * Makefile improvements (Makefile, */Makefile) * other source code modifications (*.c, *.h) * etc. (* */* :) ) If you add functionality to calc, please be sure to modify/patch/add Makefiles, help files, cal/regress.cal test code as well. Regression test cases are vital to maintaining calc's level of correctness and helps us avoid code bug regression. In order to consider integrating your code, we need:
The best way to send us new code, if your changes are small, is via a patch (diff -c from the latest alpha code to your code). If your change is large, you should send entire files (either as a diff -c /dev/null your-file patch, or as a uuencoded and gziped (or compressed) tar file). Please try to generate a patch against the most recent version of calc, and if you use GitHub, the top of the master branch:
The best way contribute to calc bug is to generate calc GitHub pull request:
Your code needs to be contributed under either the 2.1 of the GNU Lesser General Public License (LGPL 2.1) or be in the public domain. If you do not want to use calc GitHub, then send Email to:
calc-contrib at asthe dot com NOTE: Remove spaces and replace 'at' with @, 'dot' with . NOTE: Yes, the Email address uses 'asthe', while the web site uses
'isthe'.
You MUST use following SPECIAL PHRASE in your Email Subject line:
You may add additional words to your subject line. Suggestion:
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html IMPORTANT: If your Email doesn't contain the above phrase, then we WILL NOT SEE your Email. PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line! Please be patient as we cannot always respond to Email messages quickly. CALC WEB SITELandon Noll maintains the calc web site is located at:
Share and Enjoy! :-)
Visit the GSP FreeBSD Man Page Interface. |