C-style arbitrary precision calculator
Clone or download
Permalink
Failed to load latest commit information.
cal Improvements to %g pull request Sep 30, 2018
cscript Remove all RCS @(#) lines and RCS strings May 23, 2017
custom Release 2.12.6.10 Oct 20, 2018
help Improvements to %g pull request Sep 30, 2018
.gitignore Added comments & common excluded to .gitignore May 24, 2017
BUGS Remove all RCS @(#) lines and RCS strings May 23, 2017
CHANGES Release 2.12.6.10 Oct 20, 2018
COPYING Remove all RCS @(#) lines and RCS strings May 23, 2017
COPYING-LGPL Release calc version 2.12.4.11 May 21, 2017
HOWTO.INSTALL Release 2.12.6.9 Oct 16, 2018
LIBRARY Remove all RCS @(#) lines and RCS strings May 23, 2017
Makefile Undo always enabling clang sanitize May 23, 2017
Makefile.ship Fix Makefile lines that picky complains about Oct 20, 2018
README.FIRST Setup for README.md and improved calc overview May 24, 2017
README.WINDOWS Release calc version 2.12.6.5 Jan 29, 2018
README.md Improve GitHub readme and fix typos May 24, 2017
addop.c Remove all RCS @(#) lines and RCS strings May 23, 2017
align32.c Remove all RCS @(#) lines and RCS strings May 23, 2017
alloc.h Remove all RCS @(#) lines and RCS strings May 23, 2017
assocfunc.c Remove all RCS @(#) lines and RCS strings May 23, 2017
blkcpy.c Remove all RCS @(#) lines and RCS strings May 23, 2017
blkcpy.h Remove all RCS @(#) lines and RCS strings May 23, 2017
block.c Remove all RCS @(#) lines and RCS strings May 23, 2017
block.h Remove all RCS @(#) lines and RCS strings May 23, 2017
byteswap.c Remove all RCS @(#) lines and RCS strings May 23, 2017
byteswap.h Remove all RCS @(#) lines and RCS strings May 23, 2017
calc.c Release calc 2.12.6.8 Sep 30, 2018
calc.h Released calc 2.12.6.7 with help and input fixes Mar 4, 2018
calc.man Release calc 2.12.6.8 Sep 30, 2018
calc.spec.in Remove all RCS @(#) lines and RCS strings May 23, 2017
calcerr.tbl Fixed trigonometric and hyperbolic core dumps Sep 30, 2018
calcerr_c.awk Remove all RCS @(#) lines and RCS strings May 23, 2017
calcerr_c.sed Remove all RCS @(#) lines and RCS strings May 23, 2017
calcerr_h.awk Remove all RCS @(#) lines and RCS strings May 23, 2017
calcerr_h.sed Remove all RCS @(#) lines and RCS strings May 23, 2017
check.awk Remove all RCS @(#) lines and RCS strings May 23, 2017
cmath.h Remove all RCS @(#) lines and RCS strings May 23, 2017
codegen.c Remove all RCS @(#) lines and RCS strings May 23, 2017
comfunc.c Release 2.12.6.10 Oct 20, 2018
commath.c Remove all RCS @(#) lines and RCS strings May 23, 2017
config.c Implement %g format for printf Jun 30, 2018
config.h Remove all RCS @(#) lines and RCS strings May 23, 2017
const.c Remove all RCS @(#) lines and RCS strings May 23, 2017
custom.c Release calc 2.12.6.8 Sep 30, 2018
custom.h Remove all RCS @(#) lines and RCS strings May 23, 2017
decl.h Remove all RCS @(#) lines and RCS strings May 23, 2017
endian.c Remove all RCS @(#) lines and RCS strings May 23, 2017
file.c Merge branch 'master' of https://github.com/10110111/calc into 101101… Sep 30, 2018
file.h Remove all RCS @(#) lines and RCS strings May 23, 2017
fposval.c Remove all RCS @(#) lines and RCS strings May 23, 2017
func.c Release 2.12.6.10 Oct 20, 2018
func.h Remove all RCS @(#) lines and RCS strings May 23, 2017
hash.c Remove all RCS @(#) lines and RCS strings May 23, 2017
hash.h Remove all RCS @(#) lines and RCS strings May 23, 2017
have_const.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_fpos.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_fpos_pos.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_getpgid.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_getprid.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_getsid.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_gettime.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_memmv.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_newstr.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_offscl.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_posscl.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_rusage.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_stdvs.c Release calc 2.12.6.8 Sep 30, 2018
have_strdup.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_uid_t.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_unused.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_ustat.c Remove all RCS @(#) lines and RCS strings May 23, 2017
have_varvs.c Release calc 2.12.6.8 Sep 30, 2018
help.c Release calc 2.12.6.8 Sep 30, 2018
hist.c Remove all RCS @(#) lines and RCS strings May 23, 2017
hist.h Released calc 2.12.6.7 with help and input fixes Mar 4, 2018
input.c Release calc 2.12.6.8 Sep 30, 2018
jump.c Remove all RCS @(#) lines and RCS strings May 23, 2017
jump.h Remove all RCS @(#) lines and RCS strings May 23, 2017
label.c Remove all RCS @(#) lines and RCS strings May 23, 2017
label.h Remove all RCS @(#) lines and RCS strings May 23, 2017
lib_calc.c Remove all RCS @(#) lines and RCS strings May 23, 2017
lib_calc.h Remove all RCS @(#) lines and RCS strings May 23, 2017
lib_util.c Remove all RCS @(#) lines and RCS strings May 23, 2017
lib_util.h Remove all RCS @(#) lines and RCS strings May 23, 2017
listfunc.c Remove all RCS @(#) lines and RCS strings May 23, 2017
longbits.c Remove all RCS @(#) lines and RCS strings May 23, 2017
matfunc.c Remove all RCS @(#) lines and RCS strings May 23, 2017
math_error.c Release calc 2.12.6.8 Sep 30, 2018
nametype.h Remove all RCS @(#) lines and RCS strings May 23, 2017
obj.c Remove all RCS @(#) lines and RCS strings May 23, 2017
opcodes.c Remove all RCS @(#) lines and RCS strings May 23, 2017
opcodes.h Remove all RCS @(#) lines and RCS strings May 23, 2017
pix.c Remove all RCS @(#) lines and RCS strings May 23, 2017
poly.c Remove all RCS @(#) lines and RCS strings May 23, 2017
prime.c Remove all RCS @(#) lines and RCS strings May 23, 2017
prime.h Remove all RCS @(#) lines and RCS strings May 23, 2017
qfunc.c Remove all RCS @(#) lines and RCS strings May 23, 2017
qio.c Release 2.12.6.10 Oct 20, 2018
qmath.c Remove all RCS @(#) lines and RCS strings May 23, 2017
qmath.h Release 2.12.6.10 Oct 20, 2018
qmod.c Release 2.12.6.10 Oct 20, 2018
qtrans.c Remove all RCS @(#) lines and RCS strings May 23, 2017
quickhash.c Remove all RCS @(#) lines and RCS strings May 23, 2017
rpm.mk Remove all RCS @(#) lines and RCS strings May 23, 2017
sample.README Remove all RCS @(#) lines and RCS strings May 23, 2017
sample_many.c Remove all RCS @(#) lines and RCS strings May 23, 2017
sample_rand.c Remove all RCS @(#) lines and RCS strings May 23, 2017
seed.c Remove all RCS @(#) lines and RCS strings May 23, 2017
sha1.c Release calc 2.12.6.8 Sep 30, 2018
sha1.h Remove all RCS @(#) lines and RCS strings May 23, 2017
size.c Remove all RCS @(#) lines and RCS strings May 23, 2017
str.c Remove all RCS @(#) lines and RCS strings May 23, 2017
str.h Remove all RCS @(#) lines and RCS strings May 23, 2017
symbol.c Remove all RCS @(#) lines and RCS strings May 23, 2017
symbol.h Remove all RCS @(#) lines and RCS strings May 23, 2017
token.c Release calc 2.12.6.8 Sep 30, 2018
token.h Remove all RCS @(#) lines and RCS strings May 23, 2017
value.c Release 2.12.6.10 Oct 20, 2018
value.h Remove all RCS @(#) lines and RCS strings May 23, 2017
version.c Release 2.12.6.10 Oct 20, 2018
win32.mkdef Release calc 2.12.6.8 Sep 30, 2018
zfunc.c Fixed a misleading indent reported by Thomas Walter Sep 7, 2017
zio.c Release calc 2.12.6.8 Sep 30, 2018
zmath.c Remove all RCS @(#) lines and RCS strings May 23, 2017
zmath.h Improvements to %g pull request Sep 30, 2018
zmod.c Remove all RCS @(#) lines and RCS strings May 23, 2017
zmul.c Remove all RCS @(#) lines and RCS strings May 23, 2017
zprime.c Remove all RCS @(#) lines and RCS strings May 23, 2017
zrand.c Remove all RCS @(#) lines and RCS strings May 23, 2017
zrand.h Remove all RCS @(#) lines and RCS strings May 23, 2017
zrandom.c Remove all RCS @(#) lines and RCS strings May 23, 2017
zrandom.h Remove all RCS @(#) lines and RCS strings May 23, 2017

README.md

What is calc?

Calc is an interactive calculator which provides for easy large Otherwise, it enters interactive mode. In this mode, it accepts commands one at a time, processes them, and displays the answers. In the simplest case, commands are simply expressions which are evaluated. For example, the following line can be input:

3 * (4 + 1)

and the calculator will print:

15

Calc as the usual collection of arithmetic operators +, -, /, * as well as ^ (exponentiation), % (modulus) and // (integer divide). For example:

3 * 19^43 - 1

will produce:

29075426613099201338473141505176993450849249622191102976

Notice that calc values can be very large. For example:

2^23209-1

will print:

402874115778988778181873329071 ... many digits ... 3779264511

The special '.' symbol (called dot), represents the result of the last command expression, if any. This is of great use when a series of partial results are calculated, or when the output mode is changed and the last result needs to be redisplayed. For example, the above result can be modified by typing:

. % (2^127-1)

and the calculator will print:

47385033654019111249345128555354223304

For more complex calculations, variables can be used to save the intermediate results. For example, the result of adding 7 to the previous result can be saved by typing:

curds = 15
whey = 7 + 2*curds

Functions can be used in expressions. There are a great number of pre-defined functions. For example, the following will calculate the factorial of the value of 'whey':

fact(whey)

and the calculator prints:

13763753091226345046315979581580902400000000

The calculator also knows about complex numbers, so that typing:

(2+3i) * (4-3i)
cos(.)

will print:

17+6i
-55.50474777265624667147+193.9265235748927986537i

The calculator can calculate transcendental functions, and accept and display numbers in real or exponential format. For example, typing:

config("display", 70),
epsilon(1e-70),
sin(1)

prints:

0.8414709848078965066525023216302989996225630607983710656727517099919104

Calc can output values in terms of fractions, octal or hexadecimal. For example:

config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

will print:

19967568900859523802559065713/257829627945307727248226067259

0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1

0x17b5164ac24ee836bf/0xc7b7a8e3ef5fcf752+0x883eaf5adadd26be3/0xc7b7a8e3ef5fcf752i

All numbers are represented as fractions with arbitrarily large numerators and denominators which are always reduced to lowest terms. Real or exponential format numbers can be input and are converted to the equivalent fraction. Hex, binary, or octal numbers can be input by using numbers with leading '0x', '0b' or '0' characters. Complex numbers can be input using a trailing 'i', as in '2+3i'. Strings and characters are input by using single or double quotes.

Commands are statements in a C-like language, where each input line is treated as the body of a procedure. Thus the command line can contain variable declarations, expressions, labels, conditional tests, and loops. Assignments to any variable name will automatically define that name as a global variable. The other important thing to know is that all non-assignment expressions which are evaluated are automatically printed. Thus, you can evaluate an expression's value by simply typing it in.

Many useful built-in mathematical functions are available. Use the:

help builtin

command to list them.

You can also define your own functions by using the 'define' keyword, followed by a function declaration very similar to C.

define f2(n)
{
	local ans;

	ans = 1;
	while (n > 1)
		ans *= (n -= 2);
	return ans;
}

Thus the input:

f2(79)

will produce:

1009847364737869270905302433221592504062302663202724609375

Functions which only need to return a simple expression can be defined using an equals sign, as in the example:

define sc(a,b) = a^3 + b^3

Thus the input:

sc(31, 61)

will produce:

256772

Variables in functions can be defined as either 'global', 'local', or 'static'. Global variables are common to all functions and the command line, whereas local variables are unique to each function level, and are destroyed when the function returns. Static variables are scoped within single input files, or within functions, and are never destroyed. Variables are not typed at definition time, but dynamically change as they are used.

For more information about the calc language and features, try:

help overview

Calc has a help command that will produce information about every builtin function, command as well as a number of other aspects of calc usage. Try the command:

help help

for and overview of the help system. The command:

help builtin

provides information on built-in mathematical functions, whereas:

help asinh

will provides information a specific function. The following help files:

help command
help define
help operator
help statement
help variable

provide a good overview of the calc language. If you are familiar with C, you should also try:

help unexpected

It contains information about differences between C and calc that may surprize C programmers.