1calc(1)                     General Commands Manual                    calc(1)
2
3
4

NAME

6       calc - arbitrary precision calculator
7

SYNOPSIS

9       calc [-c] [-C] [-d]
10            [-D calc_debug[:resource_debug[:user_debug]]]
11            [-e] [-h] [-i] [-m mode] [-O]
12            [-p] [-q] [-s] [-u] [-v] [[--] calc_cmd ...]
13
14       #!/usr/bin/calc [other_flags ...] -f
15

DESCRIPTION

17
18       CALC OPTIONS
19
20       -c     Continue reading command lines even after a scan/parse error has
21              caused the abandonment of a line.  Note that  this  option  only
22              deals  with  scanning and parsing of the calc language.  It does
23              not deal with execution or run-time errors.
24
25              For example:
26
27                   calc read many_errors.cal
28
29              will cause calc to abort on the first syntax error, whereas:
30
31                   calc -c read many_errors.cal
32
33              will cause calc to try to process each line being  read  despite
34              the scan/parse errors that it encounters.
35
36              By  default, calc startup resource files are silently ignored if
37              not found.  This flag will report missing startup resource files
38              unless -d is also given.
39
40
41       -C     Permit  the execution of custom builtin functions.  Without this
42              flag, calling the custom() builtin function will simply generate
43              an error.
44
45              Use  of  this  flag may cause calc to execute functions that are
46              non-standard and that are not portable.   Custom  builtin  func‐
47              tions are disabled by default for this reason.
48
49
50       -d     Disable  the  printing  of  the  opening title.  The printing of
51              resource file debug and informational messages is also  disabled
52              as if config("resource_debug", 0) had been executed.
53
54              For example:
55
56                   calc "read qtime; qtime(2)"
57
58              will output something like:
59
60                   qtime(utc_hr_offset) defined
61                   It's nearly ten past six.
62
63              whereas:
64
65                   calc -d "read qtime; qtime(2)"
66
67              will just print:
68
69                   It's nearly ten past six.
70
71              This  flag  disables  the  reporting  of  missing  calc  startup
72              resource files.
73
74
75              This flag also disables the  printing  the  leading  tilde.  For
76              example:
77
78                   calc 2/3
79
80              will print:
81
82                   ~0.66666666666666666667
83
84
85              whereas:
86
87                   calc -d 2/3
88
89              will just print:
90
91                   0.66666666666666666667
92
93
94
95       -D calc_debug[:resource_debug[:user_debug]]
96              Force   the   initial   value   of   config("calc_debug"),  con‐
97              fig("resource_debug") and config("user_debug").
98
99              The : separated strings are interpreted as signed 32  bit  inte‐
100              gers.   After  an optional leading sign a leading zero indicates
101              octal conversion, and a leading  ``0x''  or  ``0X''  hexadecimal
102              conversion.  Otherwise, decimal conversion is assumed.
103
104              By  default, calc_debug is 0, resource_debug is 3 and user_debug
105              is 0.
106
107              For more information use the following calc command:
108
109                   help config
110
111
112       -e     Ignore any  environment  variables  on  startup.   The  getenv()
113              builtin will still return values, however.
114
115
116       -f     This  flag is required when using calc in shell script mode.  It
117              must be at the end of the initial #!  line of the script.
118
119              This flag is normally only at the end of a  calc  shell  script.
120              If  the  first line of an executable file begins #!  followed by
121              the absolute pathname of the calc program and the flag -f as in:
122
123                   #!/usr/bin/calc [other_flags ...] -f
124
125              the rest of the file will be processed  in  shell  script  mode.
126              See  SHELL  SCRIPT  MODE  section  of  this  man  page below for
127              details.
128
129              The actual form of this flag is:
130
131                   -f filename
132
133              On systems that treat an executable that begins with  #!   as  a
134              script,  the path of the executable is appended by the kernel as
135              the final argument to the exec() system call.  This is  why  the
136              -f flag at the very end of the #!  line.
137
138              It is possible use -f filename on the command line:
139
140                   calc [other_flags ...] -f filename
141
142              This  will  cause  calc  to  process  lines in filename in shell
143              script mode.
144
145              Use of -f implies -s.  In addition, -d and -p are implied if  -i
146              is not given.
147
148
149       -h     Print  a help message.  This option implies -q.  This is equiva‐
150              lent to the calc command help help.  The help facility  is  dis‐
151              abled unless the mode is 5 or 7.  See -m.
152
153
154       -i     Become  interactive  if  possible.  This flag will cause calc to
155              drop into interactive mode after the calc_cmd arguments  on  the
156              command  line  are evaluated.  Without this flag, calc will exit
157              after they are evaluated.
158
159              For example:
160
161                   calc 2+5
162
163              will print the value 7 and exit whereas:
164
165                   calc -i 2+5
166
167              will print the value 7 and prompt the user for  more  calc  com‐
168              mands.
169
170
171       -m mode
172              This  flag  sets  the  permission mode of calc.  It controls the
173              ability for calc to open files and execute programs.   Mode  may
174              be a number from 0 to 7.
175
176              The  mode  value  is interpreted in a way similar to that of the
177              chmod(1) octal mode:
178
179                   0  do not open any file, do not execute progs
180                   1  do not open any file
181                   2  do not open files for reading, do not execute progs
182                   3  do not open files for reading
183                   4  do not open files for writing, do not execute progs
184                   5  do not open files for writing
185                   6  do not execute any program
186                   7  allow everything (default mode)
187
188              If one wished to run calc from a privileged user, one might want
189              to use -m 0 in an effort to make calc somewhat more secure.
190
191              Mode  bits for reading and writing apply only on an open.  Files
192              already open are not effected.  Thus if one wanted to use the -m
193              0  in  an  effort  to  make calc somewhat more secure, but still
194              wanted to read and write a specific file, one might want  to  do
195              in sh(1), ksh(1), bash(1)-like shells:
196
197                   calc -m 0 3<a.file
198
199              Files  presented  to  calc  in this way are opened in an unknown
200              mode.  Calc will attempt to read or write them if directed.
201
202              If the mode disables opening of  files  for  reading,  then  the
203              startup  resource  files  are  disabled as if -q was given.  The
204              reading of key bindings is also disabled when the mode  disables
205              opening of files for reading.
206
207
208       -O     Use  the  old classic defaults instead of the default configura‐
209              tion.  This flag as the same effect as  executing  config("all",
210              "oldcfg") at startup time.
211
212              NOTE: Older versions of calc used -n to setup a modified form of
213              the default calc configuration.   The  -n  flag  currently  does
214              nothing.   Use  of the -n flag is now deprecated and may be used
215              for something else in the future.
216
217
218       -p     Pipe processing is enabled by use of -p.  For example:
219
220                   calc -p "2^21701-1" | fizzbin
221
222              In pipe mode, calc does not prompt, does not print leading  tabs
223              and  does  not  print the initial header.  The -p flag overrides
224              -i.
225
226
227       -q     Disable the reading of the startup scripts.
228
229
230       -s     By default, all calc_cmd args are evaluated and executed.   This
231              flag  will disable their evaluation and instead make them avail‐
232              able as strings for the argv() builtin function.
233
234
235       -u     Disable buffering of stdin and stdout.
236
237
238       -v     Print the calc version number and exit.
239
240
241       --     The double dash indicates to calc that no  more  option  follow.
242              Thus  calc will ignore a later argument on the command line even
243              if it starts with a dash.  This is useful when entering negative
244              values on the command line as in:
245
246                   calc -p -- -1 - -7
247
248
249
250
251       CALC COMMAND LINE
252
253       With  no  calc_cmd  arguments,  calc operates interactively.  If one or
254       more arguments are given on the command line and -s is NOT given,  then
255       calc  will  read  and execute them and either attempt to go interactive
256       according as the -i flag was present or absent.
257
258       If -s is given, calc will  not  evaluate  any  calc_cmd  arguments  but
259       instead make them available as strings to the argv() builtin function.
260
261       Sufficiently  simple  commands  with no no characters like parentheses,
262       brackets, semicolons, '*', which have special interpretations  in  UNIX
263       shells may be entered, possibly with spaces, until the terminating new‐
264       line.  For example:
265
266            calc 23 + 47
267
268       will print 70.  However, command lines will have problems:
269
270            calc 23 * 47
271
272            calc -23 + 47
273
274       The first example above fails because the shell interprets the '*' as a
275       file  glob.  The second example fails because '-23' is viewed as a calc
276       option (which it is not) and do calc objects to that it thinks of as an
277       unknown option.  These cases can usually be made to work as expected by
278       enclosing the command between quotes:
279
280            calc '23 * 47'
281
282            calc "print sqrt(2), exp(1)"
283
284       or in parentheses and quotes to avoid leading -'s as in:
285
286            calc '(-23 + 47)'
287
288       One may also use a double dash to denote that calc options  have  ended
289       as in:
290
291            calc -- -23 + 47
292
293            calc -q -- -23 + 47
294
295       If  '!'  is  to  be used to indicate the factorial function, for shells
296       like csh(1) for which '!' followed by a non-space character is used for
297       history  substitution,  it may be necessary to include a space or use a
298       backslash to escape the special meaning of '!'.  For example, the  com‐
299       mand:
300
301            print 27!^2
302
303       may have to be replaced by:
304
305            print 27! ^2   or   print 27^2
306
307       Reading  from  standard input when calc is part of a pipe works as long
308       as the -p flag is given to calc.  For example, this will  print  chongo
309       was here:
310
311            echo chongo was here | calc -p 'print fgetline(files(0));'
312
313
314       while this does not:
315
316            echo chongo was here | calc 'print fgetline(files(0));'
317
318
319       nor will this print chongo was here:
320
321            echo chongo was here | calc -i 'print fgetline(files(0));'
322
323
324       This  is  because  without  -p, the interactive parser, in an effort to
325       parse interactive commands, flushes data on standard input.
326
327
328
329       CALC STARTUP FILES
330
331       Normally on startup, if the environment variable $CALCRC  is  undefined
332       and  calc  is invoked without the -q flag, or if $CALCRC is defined and
333       calc is invoked with -e, calc looks for a file "startup"  in  the  calc
334       resource  directory .calcrc in the user's home directory, and .calcinit
335       in the current directory.  If one or more of these are found, they  are
336       read  in  succession as calc scripts and their commands executed.  When
337       defined, $CALCRC is to contain a ':' separated list of names of  files,
338       and  if  calc  is then invoked without either the -q or -e flags, these
339       files are read in succession and their  commands  executed.   No  error
340       condition is produced if a listed file is not found.
341
342       If the mode specified by -m disables opening of files for reading, then
343       the reading of startup files is also disabled as if -q was given.
344
345
346       CALC FILE SEARCH PATH
347
348       If the environment variable $CALCPATH is undefined, or if it is defined
349       and  calc  is  invoked with the -e flag, when a file name not beginning
350       with /, ~ or ./, is specified as in:
351
352            calc read myfile
353
354       calc searches in succession:
355
356            ./myfile
357            ./myfile.cal
358            /usr/lib64/myfile
359            /usr/lib64/myfile.cal
360            /usr/share/calc/custom/myfile
361            /usr/share/calc/custom/myfile.cal
362
363       If the file is found, the search stops and the commands in the file are
364       executed.   It  is an error if no readable file with the specified name
365       is found.  An alternative search path  can  be  specified  by  defining
366       $CALCPATH  in  the same way as PATH is defined, as a ':' separated list
367       of directories, and then invoking calc without the -e flag.
368
369       Calc treats all open files, other than  stdin,  stdout  and  stderr  as
370       files  available for reading and writing.  One may present calc with an
371       already open file using sh(1), ksh(1), bash(1)-like shells is to:
372
373            calc 3<open_file 4<open_file2
374
375       For more information use the following calc commands:
376
377            help help
378            help overview
379            help usage
380            help environment
381            help config
382
383
384
385       SHELL SCRIPT MODE
386
387       If the first line of an executable file  begins  #!   followed  by  the
388       absolute pathname of the calc program and the flag -f as in:
389
390            #!/usr/bin/calc [other_flags ...] -f
391
392       the rest of the file will be processed in shell script mode.  Note that
393       -f must at the end of the initial  ``#!''  line.   Any  other  optional
394       other_flags must come before the -f.
395
396       In  shell script mode the contents of the file are read and executed as
397       if they were in a file being processed by a read command, except that a
398       "command"  beginning  with '#' followed by whitespace and ending at the
399       next newline is treated as a comment.  Any optional other_flags will be
400       parsed first followed by the later lines within the script itself.
401
402       In shell script mode, -s is always assumed.  In addition, -d and -p are
403       automatically set if -i is not given.
404
405       For example, if the file /tmp/mersenne:
406
407            #!/usr/bin/calc -q -f
408            #
409            # mersenne - an example of a calc shell script file
410
411            /* parse args */
412            if (argv() != 1) {
413                fprintf(files(2), "usage: %s exp\n", config("program"));
414                abort "must give one exponent arg";
415            }
416
417            /* print the mersenne number */
418            print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1;
419
420       is made an executable file by:
421
422            chmod +x /tmp/mersenne
423
424       then the command line:
425
426            /tmp/mersenne 127
427
428       will print:
429
430            2^127-1 = 170141183460469231731687303715884105727
431
432       Note that because -s is assumed in shell  script  mode  and  non-dashed
433       args  are  made  available  as strings via the argv() builtin function.
434       Therefore:
435
436            2^eval(argv(0))-1
437
438       will print the decimal value of 2^n-1 but
439
440            2^argv(0)-1
441
442       will not.
443
444
445       DATA TYPES
446
447       Fundamental builtin data types include integers, real numbers, rational
448       numbers, complex numbers and strings.
449
450       By  use of an object, one may define an arbitrarily complex data types.
451       One may define how such objects behave a wide range of operations  such
452       as addition, subtraction, multiplication, division, negation, squaring,
453       modulus, rounding, exponentiation, equality, comparison,  printing  and
454       so on.
455
456       For more information use the following calc commands:
457
458          help types
459          help obj
460          show objfuncs
461
462
463       VARIABLES
464
465       Variables  in  calc are typeless.  In other words, the fundamental type
466       of a variable is determined by  its  content.   Before  a  variable  is
467       assigned a value it has the value of zero.
468
469       The  scope  of a variable may be global, local to a file, or local to a
470       procedure.  Values may be grouped together in a matrix,  or  into  a  a
471       list that permits stack and queue style operations.
472
473       For more information use the following calc commands:
474
475          help variable
476          help mat
477          help list
478          show globals
479
480
481       INPUT/OUTPUT
482
483       A  leading ``0x'' implies a hexadecimal value, a leading ``0b'' implies
484       a binary value, and a ``0'' followed by a digit implies an octal value.
485       Complex  numbers are indicated by a trailing ``i'' such as in ``3+4i''.
486       Strings may be delimited by either a pair of single or  double  quotes.
487       By  default, calc prints values as if they were floating point numbers.
488       One may change the default to print values in a number of modes includ‐
489       ing fractions, integers and exponentials.
490
491       A number of stdio-like file I/O operations are provided.  One may open,
492       read, write, seek and close files.  Filenames  are  subject  to  ``  ''
493       expansion  to  home directories in a way similar to that of the Korn or
494       C-Shell.
495
496       For example:
497
498          ~/.calcrc
499          ~chongo/lib/fft_multiply.cal
500
501       For more information use the following calc command:
502
503          help file
504
505
506       CALC LANGUAGE
507
508       The calc language is a C-like language.  The language includes commands
509       such  as variable declarations, expressions, tests, labels, loops, file
510       operations, function calls.  These commands are very similar  to  their
511       counterparts in C.
512
513       The  language  also  include  a  number  of commands particular to calc
514       itself.  These include commands  such  as  function  definition,  help,
515       reading  in  resource  files, dump files to a file, error notification,
516       configuration control and status.
517
518       For more information use the following calc command:
519
520          help command
521          help statement
522          help expression
523          help operator
524          help config
525

FILES

527
528       /usr/bin/calc
529            calc binary
530
531       /usr/share/calc/cscript/*
532            calc shell scripts
533
534       /usr/lib64/*.cal
535            calc standard resource files
536
537       /usr/lib64/help/*
538            help files
539
540       /usr/lib64/bindings
541            non-GNU-readline command line editor bindings
542
543       /usr/include/calc/*.h
544            include files for C interface use
545
546       /usr/lib64/libcalc.a
547            calc binary link library
548
549       /usr/lib64/libcustcalc.a
550            custom binary link library
551
552       /usr/share/calc/custom/*.cal
553            custom resource files
554
555       /usr/share/calc/custhelp/*
556            custom help files
557

ENVIRONMENT

559
560       CALCPATH
561            A :-separated list of directories used to search for calc resource
562            filenames that do not begin with /, ./ or ~.
563
564            Default value: .:./cal:~/.cal:/usr/share/calc
565
566       CALCRC
567            On  startup  (unless -h or -q was given on the command line), calc
568            searches for files along this :-separated environment variable.
569
570            Default value: /usr/share/calc/startup:~/.calcrc:./.calcinit
571
572       CALCBINDINGS
573            On startup (unless -h or -q was given on the command line,  or  -m
574            disallows opening files for reading), calc reads key bindings from
575            the filename specified by  this  environment  variable.   The  key
576            binding  file is searched for along the $CALCPATH list of directo‐
577            ries.
578
579            Default value: binding
580
581            This variable is not used if calc was compiled  with  GNU-readline
582            support.   In  that  case,  the  standard readline mechanisms (see
583            readline(3)) are used.
584

CREDIT

586
587       The main chunk of calc was written by David I. Bell.
588
589       The calc primary mirror, calc mailing list and calc bug report process‐
590       ing is performed by Landon Curt Noll.
591
592       Landon  Curt  Noll  maintains  the  master  reference  source, performs
593       release control functions as well as other calc maintenance functions.
594
595       Thanks for suggestions and encouragement from Peter Miller,  Neil  Jus‐
596       tusson, and Landon Noll.
597
598       Thanks  to  Stephen Rothwell for writing the original version of hist.c
599       which is used to do the command line editing.
600
601       Thanks to Ernest W. Bowen for supplying many improvements  in  accuracy
602       and  generality  for some numeric functions.  Much of this was in terms
603       of actual code which I gratefully accepted.  Ernest also  supplied  the
604       original text for many of the help files.
605
606       Portions  of  this  program  are  derived from an earlier set of public
607       domain arbitrarily precision routines  which  was  posted  to  the  net
608       around  1984.   By  now, there is almost no recognizable code left from
609       that original source.
610

COPYING / CALC GNU LESSER GENERAL PUBLIC LICENSE

612
613
614       Calc is open software, and is covered under version 2 of the  GNU  Gen‐
615       eral  Public  License.   You are welcome to change it and/or distribute
616       copies of it under certain conditions.  The calc commands:
617
618            help copyright
619            help copying
620            help copying-gpl
621
622       should display the contents  of  the  COPYING  and  COPYING-GPL  files.
623       Those  files  contain  information  about the calc's GNU General Public
624       License, and in particular the conditions under which you  are  allowed
625       to change it and/or distribute copies of it.
626
627       You  should  have  received  a copy of the version 2 of the GNU General
628       Public License.  If you do not have these files, write to:
629
630            Free Software Foundation, Inc.
631            51 Franklin Street
632            Fifth Floor
633            Boston, MA  02110-1301
634            USA
635
636       Calc is copyrighted in several different ways.  These ways include:
637
638            Copyright (C) year  David I. Bell
639            Copyright (C) year  David I. Bell and Landon Curt Noll
640            Copyright (C) year  David I. Bell and Ernest Bowen
641            Copyright (C) year  David I. Bell, Landon Curt Noll and Ernest Bowen
642            Copyright (C) year  Landon Curt Noll
643            Copyright (C) year  Ernest Bowen and Landon Curt Noll
644            Copyright (C) year  Ernest Bowen
645
646       This man page is:
647
648            Copyright (C) 1999  Landon Curt Noll
649
650       and is covered under version 2 GNU General Public License.
651

CALC MAILING LIST / CALC UPDATES / ENHANCEMENTS

653
654
655       To contribute comments, suggestions, enhancements and interesting  calc
656       resource  files, and shell scripts please join the calc-tester low vol‐
657       ume moderated calc mailing list.
658
659       To the calc-tester mailing list, visit the following URL:
660
661            https://www.listbox.com/subscribe/?list_id=239342
662
663       To help determine you are a human and not just a spam bot, you will  be
664       required to provide the following additional information:
665
666            Your Name
667
668            Calc Version
669               For example, the current version is: 2.12.7.2
670
671            Operating System
672               If you don't know your operating system, enter: unknown
673
674            The date 7 days ago
675               Consult a calendar :-)
676
677       If you need a human to help you with your mailing list subscription, or
678       if you have problems with the above procedure, please send EMail to our
679       special address:
680
681            calc-tester-maillist-help at asthe dot com
682
683            NOTE: Remove spaces and replace 'at' with @, 'dot' with .
684
685            NOTE: Yes, the EMail address uses 'asthe',
686                  while the web site uses 'isthe'.
687
688       To  be  sure  we  see your EMail asking for help with your mailing list
689       subscription, please use the following phase in your EMail Subject line
690       your subject must contain the words:
691
692            calc tester mailing list help
693
694       You may have additional words in your subject line.
695

BUG REPORTS / BUG FIXES

697
698
699       Send bug reports and bug fixes to:
700
701            calc-bug-report at asthe dot com
702
703            NOTE: Remove spaces and replace 'at' with @, 'dot' with .
704
705            NOTE: Yes, the EMail address uses 'asthe',
706                  while the web site uses 'isthe'.
707
708       Your subject must contain the words:
709
710            calc bug report
711
712       You may have additional words in your subject line.
713            However,  you  may find it more helpful to simply subscribe to the
714            calc-tester mailing list (see above) and then to send your  report
715            to  that  mailing  list as a wider set calc testers may be able to
716            help you.
717
718            See the BUGS source file or use the calc command:
719
720                 help bugs
721
722            for more information about bug reporting.
723

CALC WEB SITE

725
726       Landon Noll maintains the calc web site is located at:
727
728            www.isthe.com/chongo/tech/comp/calc/
729
730       Share and Enjoy! :-)
731
732
733
7342007-02-06                           ^..^                              calc(1)
Impressum