calc

calc
Login

Tiny RPN calculator

Usage

$ calc -h
Tiny RPN calculator
Usage: calc

Example

In interactive mode:

$ calc
> 123
  123
> 22
  123
  22
> 33
  123
  22
  33
> sum
  178
> neg
  -178
> dup
  -178
  -178
> 

In piped mode:

$ calc <<EOF
234
4
/
EOF
58.5
# compute sum of user's uid
$ (awk -F: '{print $3}' /etc/passwd; echo sum) | calc
75683

Commands

| Command      | Description                      |
|--------------+----------------------------------|
| +            | add                              |
| -            | substract                        |
| *            | multiply                         |
| /            | divide                           |
| _            | minus sign                       |
| ^            | pow operator                     |
| avg          | average of stack items           |
| clear        | clear stack                      |
| drop         | discard top stack item           |
| dup          | duplicate top stack item         |
| neg          | negate top stack item            |
| round        | round top stack item             |
| sqrt         | square root top stack item       |
| sum          | sum the whole stack              |
| swap / <tab> | reverses the top two stack items |