ccalc
ccalc is a fast, lightweight, and cross-platform command-line calculator, ideal for performing quick calculations from the terminal. This is often faster and easier than invoking an interactive or graphical program.
ccalc takes an arithmetic expression as an argument, it evaluates this expression, and then it prints the result. If no expression is given, ccalc will read lines from standard input. ccalc supports a number of options for formatting output, including options for base conversion.
Examples
Here are a few example calculations using ccalc. For detailed usage information, see the Program Usage section below.
Basic operations:
$ ccalc 2 + 2
4
$ ccalc "21 - 3 * 5"
6
$ ccalc "8146 % 7"
5
Built-in functions and constants:
$ ccalc "1.4 * E"
3.805595
$ ccalc "max(12, 15)"
15
$ ccalc "sin(PI / 3)"
0.866025
$ ccalc "exp(3.2)"
24.532530
Base conversion:
$ ccalc --radix=13 "54"
42
$ ccalc --binary "0x4a"
1001010
$ ccalc --radix=60 "82709"
22:58:29
Boolean tests:
$ ccalc --bool "10 > 5"
true
$ ccalc --bool "PI == 3"
false
Downloading ccalc
Select an option below to download ccalc. The source code is also available on GitHub.
ccalc 1.02 (2017-05-25)
- Source code: ccalc-1.02.tar.gz
- Windows: ccalc-1.02_w32.zip
ccalc 1.01 (2017-01-17)
- Source code: ccalc-1.01.tar.gz
- Windows: ccalc-1.01_w32.zip
Documentation
Run man ccalc
or ccalc --help
for
detailed usage information. Alternatively, see the
Program Usage section below.
Copyright and Licensing
ccalc is copyright © 2015-2017 Gregory Kikola. License GPLv3+: GNU GPL version 3 or later.
ccalc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
ccalc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Program Usage
ccalc [OPTION...] [EXPRESSION]
EXPRESSION should be a mathematical expression conforming to the syntax of the C programming language. OPTION can be any combination of the options in the table below. ccalc will evaluate EXPRESSION and print the result to standard output. If EXPRESSION is not provided, ccalc will read expressions from standard input. Any program options must be specified before the start of an expression.
Option | Long name | Description |
---|---|---|
-b | --binary | Print integer results in binary (base 2) |
--bool | Interpret the result as a boolean value and print true or false | |
-c | --caret-exp | Use caret ^ for exponentiation rather than for bitwise XOR |
-d | --degrees | Use degrees instead of radians for trigonometric functions |
-g | --grouping=DIGITS | Group each set of DIGITS digits and separate each group with spaces (use 0 for no grouping) |
-o | --octal | Print integer results in octal (base 8) |
-p | --precision=DIGITS | Print floating-point results with DIGITS digits after the decimal point (default 6) |
-r | --radix=RADIX | Print integer results in base RADIX |
-s | --scientific-notation | Always print floating-point results in scientific notation, [-]d.ddde±dd |
-t | --time | Show how much time the computation took |
-u | --uppercase | Use uppercase rather than lowercase letters for digits in bases greater than 10 |
-x | --hexadecimal | Print integer results in hexadecimal (base 16) |
-? | --help | Give detailed usage information |
--usage | Give a short usage message | |
--version | Display version information and exit |
Mandatory arguments to long options are also mandatory for the corresponding short options.
All C operators are supported except for those with side-effects
(namely assignment, increment, and decrement). In addition, an
exponentiation operator **
and an integer division
operator //
are provided. Both integer and
floating-point values may be used in the input expression:
ccalc will perform conversions where necessary.
Note that ccalc treats the ^
operator as C does, as the bitwise XOR operator and not as
exponentiation. This behavior can be changed with the --caret-exp
option. Otherwise you may use the
pow
function or the **
operator.
Note also that, unlike in C, the division operator
/
may produce a floating-point result even when both
operands are integers. To force integer division, the
//
operator may be used.
A few mathematical constants like PI
and
E
are defined, and most of the math functions in the
C standard library are available.
Integer values may also be specified in binary, octal, or
hexadecimal. Binary values should be prefixed with
0b
, octal values with 0
, and hexadecimal
values with 0x
.