LinuxCommandLibrary

calc

Perform arithmetic calculations

TLDR

Start calc in interactive mode

$ calc
copy

Perform a calculation in non-interactive mode
$ calc '[85 * (36 / 4)]'
copy

Don't format the output (for use with [p]ipes)
$ calc -p '[4/3 * pi() * 5^3]'
copy

Perform a calculation and then switch to [i]nteractive mode
$ calc -i '[sqrt(2)]'
copy

Start calc in a specific permission [m]ode (0 to 7, defaults to 7)
$ calc -m [mode]
copy

View an introduction to calc
$ calc help intro
copy

View an overview of calc
$ calc help overview
copy

Open the calc manual
$ calc help
copy

SYNOPSIS

calc [-d | -D | -e | -E | -h | -i | -r | -R] [-s prec] [-t tabstop] [file]

PARAMETERS

-d
    Enable debugging mode

-D
    Enable extended debugging mode

-e
    End immediately after processing file

-E
    Execute stdin as calc statements

-h
    Display help message and exit

-i
    Force interactive mode after file

-r
    Recover from system crash (advanced)

-R
    Use Reverse Polish Notation (RPN) mode

-s prec
    Set default precision to prec digits

-t tabstop
    Set tabstop width to tabstop columns

DESCRIPTION

Calc is a sophisticated command-line calculator designed for arbitrary precision arithmetic. It offers a C-like syntax for expressions, making it intuitive for programmers, while supporting variables, built-in functions (including trig, logs, and financial), conditionals, loops, and custom functions.

Users can perform simple calculations or write scripts for complex tasks. It emulates spreadsheet-like functionality with matrices and polynomials. Interactive mode allows immediate evaluation, and RPN mode caters to stack-based preferences.

Precision is user-configurable, ideal for scientific computing or big integers. Calc reads commands from files or stdin, with output formatting options. It's extensible via a Forth-like interpreter for advanced scripting. Widely used on Unix-like systems, it's lightweight yet powerful for math-heavy workflows.

CAVEATS

Not installed by default; requires calc package. Complex syntax may overwhelm beginners. High precision slows performance.

BASIC USAGE EXAMPLES

calc '2 + 3 * sin(PI/4)'
calc -s 50 -e 'print sqrt(2)'
echo 'x=5; print x^2' | calc -E

INTERACTIVE MODE

Run calc without args for prompt (>). Type expressions directly, use quit to exit. Supports ? for help.

HISTORY

Developed by Landon Curt Noll starting in 1986, with contributions from Jonathan Payne and others. Evolved from earlier Unix calculators; maintained for decades with precision and feature enhancements.

SEE ALSO

bc(1), dc(1), expr(1)

Copied to clipboard