packages icon



 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



 NAME
      calc - arbitrary precision calculator

 SYNOPSIS
      calc [-c] [-C] [-d] [-D calc_debug[:lib_debug:[user_debug]]]
           [-e] [-h] [-i] [-m mode] [-n] [-p] [-q] [-u] [-v]
           [calc_cmd ...]

 DESCRIPTION

      CALC COMMAND LINE

      -c   Continue reading command lines even after an execution error has
           caused the abandonment of a line.

           For example:

                calc read many_errors.cal

           will cause calc to abort on the first error, whereas:

                calc -c read many_errors.cal

           will cause calc to try to process each line being read despite
           the errors that it encounters.

           By default, calc startup scripts ($CALCRC) are silently ignored
           if not found.  This flag will report missing startup scripts
           unless -d is also given.


      -C   Permit the execution of custom builtin functions.  Without this
           flag, calling the custom() builtin function will simply generate
           an error.

           Use if this flag may cause calc to execute functions that are
           non-standard and that are not portable.  Custom builtin functions
           are disabled by default for this reason.


      -d   Disable the printing of the opening title.  The printing of
           library debug and informational messages is also disabled as if
           config("lib_debug", 0) had been executed.

           For example:

                calc 'read qtime; qtime(2)'

           will output something like:

                qtime(utc_hr_offset) defined



                                    - 1 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



                It's nearly ten past six.

           whereas:

                calc -d 'read qtime; qtime(2)'

           will just say:

                It's nearly ten past six.

           This flag disables the reporting of missing calc startup scripts
           ($CALCRC).


      -D calc_debug[:lib_debug:[user_debug]]
           Force the initial value of config("calc_debug"),
           config("lib_debug") and config("user_debug").

           The : separated strings are interpreted as signed 32 bit values.
           After an optional leading sign a leading zero indicates octal
           conversion, and a leading ``0x'' or ``0X'' hexadecimal
           conversion.  Otherwise, decimal conversion is assumed.

           By default, calc_debug is 0, lib_debug is 3 and lib_debug is 0.

           For more information use the following calc command:

                help config


      -e   Ignore any environment variables on startup.  The getenv()
           builtin will still return values, however.


      -h   Print a help message.  This option implies -q.  This is
           equivalent to the calc command help help.  The help facility is
           disabled unless the mode is 5 or 7.  See -m.


      -i   Become interactive if possible.  Be default, if calc_cmd args are
           given, calc will execute them and exit.  This flag args are
           given, calc will execute them and exit.  This flag will cause
           calc to drop into interactive mode after the commands are
           executed.

           For example:

                calc 2+5

           will print the value 7 and exit whereas:




                                    - 2 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



                calc -i 2+5

           will print the value 7 and prompt the user for more calc
           commands.


      -m mode
           This flag sets the permission mode of calc.  It controls the
           ability for calc to open files and execute programs.  Mode may be
           a number from 0 to 7.

           The mode value is interpreted in a way similar to that of the
           chmod(1) octal mode:

                0  do not open any file, do not execute progs
                1  do not open any file
                2  do not open files for reading, do not execute progs
                3  do not open files for reading
                4  do not open files for writing, do not execute progs
                5  do not open files for writing
                6  do not execute any program
                7  allow everything (default mode)

           If one wished to run calc from a privileged user, one might want
           to use -m 0 in an effort to make calc somewhat more secure.

           Mode bits for reading and writing apply only on an open.  Files
           already open are not effected.  Thus if one wanted to use the -m
           0 in an effort to make calc somewhat more secure, but still
           wanted to read and write a specific file, one might want to do in
           sh(1), ksh(1), bash(1)-like shells:

                calc -m 0 3<a.file

           Files presented to calc in this way are opened in an unknown
           mode.  Calc will attempt to read or write them if directed.

           If the mode disables opening of files for reading, then the
           startup library scripts are disabled as of -q was given.  The
           reading of key bindings is also disabled when the mode disables
           opening of files for reading.


      -n   Use the new configuration defaults instead of the old default
           classic defaults.  This flag as the same effect as executing
           config("all", "newcfg") at startup time.


      -p   Pipe processing is enabled by use of -p.  For example:

                calc -p '2^21701-1' | fizzbin



                                    - 3 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



           In pipe mode, calc does not prompt, does not print leading tabs
           and does not print the initial header.  The -p flag overrides -i.


      -q   Disable the use of the $CALCRC startup scripts.


      -u   Disable buffering of stdin and stdout.


      -v   Print the calc version number and exit.

      Without calc_cmd, calc operates interactively.  If one or more
      calc_cmd are given on the command line, calc will execute them and
      exit.  If -i is given, calc will attempt to become interactive even of
      one or more calc_cmd are given on the command line.

      Normally on startup, calc attempts to execute a collection of library
      scripts.  The environment variable $CALCRC (if non-existent then a
      compiled in value) contains a :  separated list of startup library
      scripts.  No error conditions are produced if these startup library
      scripts are not found.

      If the mode disables opening of files for reading, then the startup
      library scripts are disabled as of -q was given and $CALCRC as well as
      the default compiled in value are ignored.

      Filenames are subject to ``~'' expansion (see below).  The environment
      variable $CALCPATH (if non-existent then a compiled in value) contains
      a : separated list of search directories.  If a file does not begin
      with /, ~ or ./, then it is searched for under each directory listed
      in the $CALCPATH.  It is an error if no such readable file is found.

      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:

           calc 3<open_file 4<open_file2

      For more information use the following calc commands:

           help help
           help overview
           help usage
           help environment
           help config


      DATA TYPES





                                    - 4 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



      Fundamental 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:

           help types
           help obj
           show objfuncs

      VARIABLES

      Variables 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:

           help variable
           help mat
           help list
           show globals

      INPUT/OUTPUT

      A 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:

           ~/.calcrc
           ~chongo/lib/fft_multiply.cal



                                    - 5 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



      For more information use the following calc command:

           help file

      CALC LANGUAGE

      The 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 library scripts, dump files to a file, error notification,
      configuration control and status.

      For more information use the following calc command:

           help command
           help statement
           help expression
           help operator
           help config

 FILES

      /opt/tmp/calc/lib/calc/*.cal
                          library scripts shipped with calc

      /opt/tmp/calc/lib/calc/help/*
                          help files

      /opt/tmp/calc/lib/calc/bindings
                          command line editor bindings

 ENVIRONMENT

      CALCPATH
           A :-separated list of directories used to search for scripts
           filenames that do not begin with /, ./ or ~.

           Default value:
           .:./lib:~/lib:/opt/tmp/calc/lib/calc:/opt/tmp/calc/lib/calc/custom

      CALCRC
           On startup (unless -h or -q was given on the command line), calc
           searches for files along this :-separated environment variable.

           Default value: /opt/tmp/calc/lib/calc/startup:~/.calcrc





                                    - 6 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



      CALCBINDINGS
           On startup (unless -h or -q was given on the command line, or -m
           disallows opening files for reading), calc reads key bindings
           from the filename specified by this environment variable.

           Default value: bindings

           This variable is not used if calc was compiled with GNU-readline
           support.  In that case, the standard readline mechanisms (see
           readline(3)) are used.

 CREDIT

      The majority of calc was written by David I. Bell.

      Calc The Calc primary mirror, calc mailing list 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.

      Most of this source and binary has one of the following copyrights:

           Copyright (c) 19xx David I. Bell
           Copyright (c) 19xx David I. Bell and Landon Curt Noll
           Copyright (c) 19xx Landon Curt Noll
           Copyright (c) 19xx Ernest Bowen and Landon Curt Noll

      Permission is granted to use, distribute, or modify this source,
      provided that this copyright notice remains intact.

      Send comments, suggestions, bug fixes, enhancements and interesting
      calc scripts that you would like you see included in future
      distributions to:




                                    - 7 -      Formatted:  November 14, 2024






 calc(1)                          15Oct1999                          calc(1)
                                    ^..^



           calc-tester at postofc dot corp dot sgi dot com

           [[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]

      Bug reports are sent to:
           calc-bugs at postofc dot corp dot sgi dot com

           [[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]

      See the BUGS source file or use the calc command:

           help bugs

      for more information about bug reporting.

      Landon Noll maintains the the calc web site is located at:

           http://reality.sgi.com/chongo/tech/comp/calc/

      One may join the calc testing group by sending a request to:

           calc-tester-request at postofc dot corp dot sgi dot com

           [[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]

      Your message body (not the subject) should consist of:

           subscribe calc-tester address
           end
           name your_full_name

      where "address" is your EMail address and "your_full_name" is your
      full name.

      Share and Enjoy! :-)



















                                    - 8 -      Formatted:  November 14, 2024