2 .\" Copyright (C) 1999-2007 Landon Curt Noll
4 .\" Calc is open software; you can redistribute it and/or modify it under
5 .\" the terms of the version 2.1 of the GNU Lesser General Public License
6 .\" as published by the Free Software Foundation.
8 .\" Calc is distributed in the hope that it will be useful, but WITHOUT
9 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 .\" or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
11 .\" Public License for more details.
13 .\" A copy of version 2.1 of the GNU Lesser General Public License is
14 .\" distributed with calc under the filename COPYING-LGPL. You should have
15 .\" received a copy with calc; if not, write to Free Software Foundation, Inc.
16 .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 .\" @(#) $Revision: 30.5 $
19 .\" @(#) $Id: calc.man,v 30.5 2013/08/11 08:41:38 chongo Exp $
20 .\" @(#) $Source: /usr/local/src/bin/calc/RCS/calc.man,v $
22 .\" Under source code control: 1991/07/23 05:48:26
23 .\" File existed as early as: 1991
25 .\" chongo <was here> /\oo/\ http://www.isthe.com/chongo/
26 .\" Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
28 .\" calculator by David I. Bell
29 .\" man page by Landon Noll
31 .TH calc 1 "^..^" "2007-02-06"
33 calc \- arbitrary precision calculator
41 .RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
54 .RB [ [\-\-]\ calc_cmd\ \&.\|.\|. ]
57 \fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP
66 Continue reading command lines even after a scan/parse
67 error has caused the abandonment of a line.
68 Note that this option only deals with scanning and
69 parsing of the calc language.
70 It does not deal with execution or run-time errors.
76 calc read many_errors.cal
82 to abort on the first syntax error, whereas:
86 calc -c read many_errors.cal
93 to try to process each line being read
94 despite the scan/parse errors that it encounters.
96 By default, calc startup resource files are silently
98 This flag will report missing
99 startup resource files unless
105 Permit the execution of custom builtin functions.
107 this flag, calling the custom() builtin function will
108 simply generate an error.
110 Use of this flag may cause
113 that are non-standard and that are not portable. Custom builtin
114 functions are disabled by default for this reason.
118 Disable the printing of the opening title. The printing
119 of resource file debug and informational messages is also disabled
120 as if \fBconfig("resource_debug", 0)\fP had been executed.
125 calc "read qtime; qtime(2)"
128 will output something like:
132 qtime(utc_hr_offset) defined
133 It's nearly ten past six.
141 calc -d "read qtime; qtime(2)"
149 It's nearly ten past six.
153 This flag disables the reporting of missing calc
154 startup resource files.
157 .BR -D " calc_debug[:resource_debug[:user_debug]]"
158 Force the initial value of config("calc_debug"),
159 config("resource_debug") and config("user_debug").
161 The : separated strings are interpreted as signed 32 bit integers.
162 After an optional leading sign a leading zero indicates octal
163 conversion, and a leading ``0x'' or ``0X'' hexadecimal
164 conversion. Otherwise, decimal conversion is assumed.
174 For more information use the following
186 Ignore any environment variables on startup.
187 The getenv() builtin will still return values, however.
191 This flag is required when using calc in
192 .BR "shell script mode" .
193 It must be at the end of the initial
197 This flag is normally only at the end of a calc shell script.
198 If the first line of an executable file begins
200 followed by the absolute pathname of the
208 \fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP
212 the rest of the file will be processed in
213 .BR "shell script mode" .
215 .B "SHELL SCRIPT MODE"
216 section of this man page
219 The actual form of this flag is:
226 On systems that treat an executable that begins with
228 as a script, the path of the executable is appended by the kernel
229 as the final argument to the exec() system call.
232 flag at the very end of the
242 \fIcalc\fP\ [other_flags\ \&...] \fB\-f\fP filename
246 This will cause calc to process lines in
249 .BR "shell script mode" .
265 Print a help message. This option implies
271 The help facility is disabled unless the mode is 5 or 7.
277 Become interactive if possible.
280 to drop into interactive mode after the
282 arguments on the command line are evaluated.
285 will exit after they are evaluated.
295 will print the value 7 and exit whereas:
303 will print the value 7 and prompt the user for more
309 This flag sets the permission mode of
311 It controls the ability for
313 to open files and execute programs.
315 may be a number from 0 to 7.
317 The mode value is interpreted in a way similar to that
324 0 do not open any file, do not execute progs
325 1 do not open any file
326 2 do not open files for reading, do not execute progs
327 3 do not open files for reading
328 4 do not open files for writing, do not execute progs
329 5 do not open files for writing
330 6 do not execute any program
331 7 allow everything (default mode)
337 from a privileged user, one might want to use
341 somewhat more secure.
343 Mode bits for reading and writing apply only on an
345 Files already open are not effected.
346 Thus if one wanted to use the
350 somewhat more secure, but still wanted to read and write a specific
351 file, one might want to do in
365 in this way are opened in an
368 will attempt to read or write them if directed.
370 If the mode disables opening of files for reading, then
371 the startup resource files are disabled as if
374 The reading of key bindings is also disabled
375 when the mode disables opening of files for reading.
379 Use the old classic defaults instead of the
380 default configuration.
381 This flag as the same effect
382 as executing \fBconfig("all", "oldcfg")\fP at startup time.
384 NOTE: Older versions of calc used
386 to setup a modified form of the default calc configuration.
389 flag currently does nothing.
392 flag is now deprecated and may be used for
393 something else in the future.
397 Pipe processing is enabled by use of
403 calc -p "2^21701-1" | fizzbin
409 does not prompt, does not print leading
410 tabs and does not print the initial header.
418 Disable the reading of the startup scripts.
424 args are evaluated and executed.
425 This flag will disable their evaluation and instead make
426 them available as strings for the argv() builtin function.
430 Disable buffering of stdin and stdout.
436 version number and exit.
440 The double dash indicates to calc that no more option follow.
441 Thus calc will ignore a later argument on the command line
442 even if it starts with a dash.
443 This is useful when entering negative values on the command line as in:
447 calc \-p \-\- \-1 - -7
462 operates interactively.
464 arguments are given on the command line and
468 will read and execute them and either attempt
469 to go interactive according as the
471 flag was present or absent.
477 will not evaluate any
479 arguments but instead make them available
480 as strings to the argv() builtin function.
482 Sufficiently simple commands with no no characters like
483 parentheses, brackets, semicolons, '*', which have special
484 interpretations in UNIX shells may be entered, possibly with
485 spaces, until the terminating newline.
495 However, command lines will have problems:
505 The first example above fails because the shell interprets the '*'
507 The second example fails because '\-23' is viewed as a calc option
508 (which it is not) and do calc objects to that it thinks of as an unknown option.
509 These cases can usually be made to work as expected by
510 enclosing the command between quotes:
516 calc "print sqrt(2), exp(1)"
520 or in parentheses and quotes to avoid leading \-'s as in:
528 One may also use a double dash to denote that calc options have ended as in:
538 If '!' is to be used to indicate the factorial function, for
541 for which '!' followed by a non-space character
542 is used for history substitution, it may be necessary to
543 include a space or use a backslash to escape the special
545 For example, the command:
553 may have to be replaced by:
557 print 27! ^2 or print 27\!^2
566 if the environment variable
570 is invoked without the
574 is defined and calc is invoked with
577 looks for a file "startup" in the calc resource directory
579 in the user's home directory, and
580 .B .calcinit in the current directory.
581 If one or more of these are found, they are read in succession as
583 scripts and their commands executed.
586 is to contain a ':' separated list of names of files,
587 and if calc is then invoked without either the
591 flags, these files are read in succession and their commands executed.
592 No error condition is produced if a listed file is not found.
594 If the mode specified by
596 disables opening of files for reading, then the reading of startup
597 files is also disabled as if
603 CALC FILE SEARCH PATH
605 If the environment variable
607 is undefined, or if it
612 flag, when a file name not beginning with
626 searches in succession:
634 ${CUSTOMCALDIR}/myfile
635 ${CUSTOMCALDIR}/myfile.cal
639 If the file is found, the
640 search stops and the commands in the file are executed.
641 It is an error if no readable file with the specified name is found.
642 An alternative search path can be specified by defining
644 in the same way as PATH is defined, as a ':' separated
645 list of directories, and then invoking
652 treats all open files, other than stdin, stdout and
653 stderr as files available for reading and writing.
657 with an already open file using
664 calc 3<open_file 4<open_file2
667 For more information use the following
687 If the first line of an executable file begins
689 followed by the absolute pathname of the
697 \fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP
701 the rest of the file will be processed in
702 .BR "shell script mode" .
705 must at the end of the initial ``#!'' line.
713 .B "shell script mode"
714 the contents of the file are read and
715 executed as if they were in a file being processed by a read
716 command, except that a "command" beginning with '#' followed by
717 whitespace and ending at the next newline is treated as a comment.
720 will be parsed first followed by
721 the later lines within the script itself.
724 .BR "shell script mode" ,
731 are automatically set if
741 \fI#!${BINDIR}/calc\fP\ \&\fB\-q\fP \fB\-f\fP
743 # mersenne - an example of a calc \fBshell script file\fP
747 fprintf(files(2), "usage: %s exp\\n", config("program"));
748 abort "must give one exponent arg";
751 /* print the mersenne number */
752 print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1;
756 is made an executable file by:
760 chmod +x /tmp/mersenne
764 then the command line:
776 2^127-1 = 170141183460469231731687303715884105727
783 .B "shell script mode"
784 and non-dashed args are made available as
796 will print the decimal value of 2^n-1
812 Fundamental builtin data types include integers, real numbers,
813 rational numbers, complex numbers and strings.
815 By use of an object, one may define an arbitrarily complex
817 One may define how such objects behave a wide range of
818 operations such as addition, subtraction,
819 multiplication, division, negation, squaring, modulus,
820 rounding, exponentiation, equality, comparison, printing
823 For more information use the following
840 Variables in \fIcalc\fP are typeless.
841 In other words, the fundamental type of a variable is determined by its content.
842 Before a variable is assigned a value it has the value of zero.
844 The scope of a variable may be global, local to a file, or local to a
846 Values may be grouped together in a matrix, or into a
847 a list that permits stack and queue style operations.
849 For more information use the following
868 A leading ``0x'' implies a hexadecimal value,
869 a leading ``0b'' implies a binary value,
870 and a ``0'' followed by a digit implies an octal value.
871 Complex numbers are indicated by a trailing ``i'' such as in ``3+4i''.
872 Strings may be delimited by either a pair of single or double quotes.
873 By default, \fIcalc\fP prints values as if they were floating point numbers.
874 One may change the default to print values in a number of modes
875 including fractions, integers and exponentials.
877 A number of stdio-like file I/O operations are provided.
878 One may open, read, write, seek and close files.
879 Filenames are subject to ``\~'' expansion to home directories
880 in a way similar to that of the Korn or C-Shell.
887 ~chongo/lib/fft_multiply.cal
890 For more information use the following
903 The \fIcalc\fP language is a C-like language.
904 The language includes commands such as variable declarations,
905 expressions, tests, labels, loops, file operations, function calls.
906 These commands are very similar to their counterparts in C.
908 The language also include a number of commands particular
909 to \fIcalc\fP itself.
910 These include commands such as function definition, help,
911 reading in resource files, dump files to a file, error notification,
912 configuration control and status.
914 For more information use the following
944 calc standard resource files
952 non-GNU-readline command line editor bindings
956 include files for C interface use
960 calc binary link library
963 ${LIBDIR}/libcustcalc.a
964 custom binary link library
967 ${CUSTOMCALDIR}/*.cal
968 custom resource files
980 A :-separated list of directories used to search for calc
981 resource filenames that do not begin with /, ./ or ~.
984 Default value: ${CALCPATH}
989 On startup (unless \-h or \-q was given on the command
992 searches for files along this :-separated
993 environment variable.
996 Default value: ${CALCRC}
1001 On startup (unless \fI\-h\fP or \fI\-q\fP was given on the command
1002 line, or \fI\-m\fP disallows opening files for reading),
1005 key bindings from the filename specified
1006 by this environment variable.
1007 The key binding file is searched for along the $CALCPATH list
1010 Default value: binding
1012 This variable is not used if calc was compiled with GNU-readline support.
1013 In that case, the standard readline mechanisms (see readline(3)) are used.
1020 was written by David I. Bell.
1024 primary mirror, calc mailing list and calc bug report
1025 processing is performed by Landon Curt Noll.
1027 Landon Curt Noll maintains the master reference source, performs
1028 release control functions as well as other calc maintenance functions.
1030 Thanks for suggestions and encouragement from Peter Miller,
1031 Neil Justusson, and Landon Noll.
1033 Thanks to Stephen Rothwell for writing the original version of
1034 hist.c which is used to do the command line editing.
1036 Thanks to Ernest W. Bowen for supplying many improvements in
1037 accuracy and generality for some numeric functions. Much of
1038 this was in terms of actual code which I gratefully accepted.
1039 Ernest also supplied the original text for many of the help files.
1041 Portions of this program are derived from an earlier set of
1042 public domain arbitrarily precision routines which was posted
1043 to the net around 1984.
1044 By now, there is almost no recognizable
1045 code left from that original source.
1047 .SH "COPYING / CALC GNU LESSER GENERAL PUBLIC LICENSE"
1050 Calc is open software, and is
1051 covered under version 2.1 of the GNU Lesser General Public License.
1053 welcome to change it and/or distribute copies of it under certain
1065 should display the contents of the COPYING and COPYING-LGPL files.
1066 Those files contain information about the calc's GNU Lesser General
1067 Public License, and in particular the conditions under which you
1068 are allowed to change it and/or distribute copies of it.
1070 You should have received a copy of the version 2.1 of the GNU Lesser General
1072 If you do not have these files, write to:
1076 Free Software Foundation, Inc.
1079 Boston, MA 02110-1301
1084 Calc is copyrighted in several different ways.
1089 Copyright (C) year David I. Bell
1090 Copyright (C) year David I. Bell and Landon Curt Noll
1091 Copyright (C) year David I. Bell and Ernest Bowen
1092 Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen
1093 Copyright (C) year Landon Curt Noll
1094 Copyright (C) year Ernest Bowen and Landon Curt Noll
1095 Copyright (C) year Ernest Bowen
1103 Copyright (C) 1999 Landon Curt Noll
1107 and is covered under version 2.1 GNU Lesser General
1110 .SH "CALC MAILING LIST / CALC UPDATES / ENHANCEMENTS"
1114 To contribute comments, suggestions, enhancements
1118 shell scripts please join the low volume calc mailing list.
1120 To join the low volume calc mailing list, send EMail to:
1124 calc-tester-request at asthe dot com
1128 Your subject must contain the words:
1132 calc mailing list subscription
1136 You may have additional words in your subject line.
1138 Your message body must contain:
1142 subscribe calc-tester address
1150 s your EMail address and
1153 Feel free to follow the
1155 line with additional EMail text as desired.
1157 .SH "BUG REPORTS / BUG FIXES"
1161 Send bug reports and bug fixes to:
1165 calc-bugs at asthe dot com
1167 [[ NOTE: Replace 'at' with @, 'dot' is with . ]]
1168 [[ and remove the spaces ]]
1169 [[ NOTE: The EMail address uses 'asthe' and
1170 [[ the web site URL uses 'isthe' ]]
1174 Your subject must contain the words:
1182 You may have additional words in your subject line.
1186 source file or use the
1196 for more information about bug reporting.
1201 Landon Noll maintains the
1203 web site is located at:
1206 www.isthe.com/chongo/tech/comp/calc/
1209 Share and Enjoy! :\-)