Cl Calc is an open-source, lightweight, command-line style online calculator. While it has clean and simple interface, it can perform some advanced calculations because it is based on powerful MathJS library.

Some of the Cl Calc features include:

- Arbitrary precision (long arithmetic) math expression evaluation.
- Variety of built-in mathematical, scientific, programming and utility functions. This includes algebra, arithmetic, combinatorics, probability, matrix, statistics, trigonometry, logical, encoding functions and more.
- User defined variables and functions.
- Many built-in datatypes, including complex numbers, fractions, vectors, matrices and colors.
- Base64 Encoding, Unicode, hexadecimal, octal and binary numbers support.
- Persistent links to store or share your calculations.
- Pretty-printing expressions with TeX.
- Simple 2d functions plotting.

Cl Calc is written purely in JavaScript and it evaluates all expressions directly in your browser. This means that your data is never sent to the server for processing or storage. Cl Calc can be installed as a progressive web application (PWA) and can work fully offline.

Cl Calc is completely open-source (source is available on GitHub) and licensed under MIT license. It is hosted in transparent manner through GitHub Pages.

**DISCLAIMER:** Since Cl Calc uses floating-point arithmetic rounding errors and other errors that lead to precision loss are inevitable. Never use Cl Calc for scientific, financial and any other calculations that need precise results. Also remember that as any software product Cl Calc and libraries it uses may have bugs and may produce incorrect results. Always double-check your calculations using multiple tools.

Simply type an expression and hit enter to calculate the result:

`Try It!(2 + 3) * 517`

You can use some of the built-in constants:

`Try It!e^(i*pi)-1 + 1.2246467991473532e-16i`

or you can define your own:

`Try It!meaning_of_life = 4242meaning_of_life > 0true`

You can also use some of the built-in functions:

`Try It!sin(pi/2) + cos(pi/2)1`

or define your own as well

`Try It!tax_percent = 1313full_price(price) = price * (1 + tax_percent / 100)full_price(99.99)112.9887`

You can work with vectors (aka lists):

`Try It!x = 1:5[1, 2, 3, 4, 5]x = x * 2[2, 4, 6, 8, 10]mean(x)6`

matrices:

`Try It!x = [[1, 2], [3, 4]] * inv([[1, 2], [3, 4]])[[1, 0], [0, 1]]det(x)1`

units:

`Try It!90 km/h to m/s25 m / s110 V * 20 A * 30 days to kWh1584 kWh`

colors:

`Try It!hsl(#ffff0000 + #ff0000ff)[300, 100, 50]colorHsl(300, 100, 50)#FFFF00FF`

and much more!

To get general help inside the calculator you can use help command:

`Try It!help`

Or to get help on a specific function or constant you can use help as a function with one argument, for example:

`Try It!help(sin)`

Cl Calc user interface is designed to resemble the interface of a traditional UNIX terminal. You type expression or command into the command line and press Enter key to evaluate it.

Terminal user interface is based on jQuery Terminal library. It supports a variety of key combinations that are described in the documentation section. Below is a brief overview of these key combinations:

Key Combination | Action |
---|---|

Tab | Autocomplete current keyword. If multiple options are available hit Tab to show the list of available completion options. |

Up/Down | Navigate through command history. |

Ctrl+R | Reverse search through command history. |

Ctrl+G | Cancel reverse search. |

Ctrl+U | Remove the text before the cursor. |

Ctrl+K | Remove the text after the cursor. |

Ctrl+L | Clear terminal. Alternatively, you can type clear to achieve the same result. |

Shift+Enter | Insert a new line. |

Ctrl+A, Home | Move cursor to the beginning of the line. |

Ctrl+E, End | Move cursor to the end of the line. |

If you need to save your Cl Calc session for later use, or to share it with someone else you can click create link button () in the top left corner of the window. It will open a pop-up with the generated link that you can copy. If you open this link later, the whole content of your Cl Calc window will be restored.

Alternatively, you can create link that will only contain a single command from Cl Calc, by clicking on corresponding create expression link button () on the right side of the window. When you open this link, it will only restore its command and not the whole command log.

Please note that since Cl Calc doesn't store or send your commands to the server, all information required to restore your session is encoded directly in the link itself. This means that these links can get quite long.

You can view "pretty-printed" version of your calculations logs by clicking on the Toggle TeX Panel button (). Pretty-printing can be especially useful if you work with matrices or vectors as they will be displayed in more recognizable form compared to what terminal displays.

Cl Calc settings are configured through the settings dialog which can be accessed by pressing () button. Settings are saved in the browser local storage. The available settings are: thousands separator, precision and color theme.

Enabling thousands separator will group digits in thousands (i.e. by three digits) and use empty space as a delimiter. Selection and copying behavior is unchanged, so the delimiters won't be copied into the clipboard.

Precision setting allows to configure maximum number of significant digits for calculations using big numbers. It can be set in a range of 8 - 4096. Be careful with using high precision as it may decrease responsiveness of Cl Calc. See Precision for more information about precision.

Color theme can be changed by selecting Light (default) or Dark color theme in the settings dialog.

Cl Calc uses MathJS library for expression parsing and evaluation. It is an extensive math library for JavaScript with a rich set of features and active community. Since Cl Calc only extends MathJS with some additional features, everything that is available in MathJS is available in Cl Calc.

You can find exhaustive MathJS Documentation and Examples on the MathJS website. Below is just a brief overview of its main features.

The data types suported by MathJS are:

Number/BigNumber:

`Try It!42!1405006117752879898543142606244511569936384000000000`

Complex:

`Try It!(2+3i)^2-5 + 12i`

Fraction:

`Try It!fraction("2/3") + fraction("3/4")17/12`

Boolean:

`Try It!3 > 2 and 3 < 5true`

String:

`Try It!concat("Hello, ", "World")"Hello, World"`

Array (vector):

`Try It![1, 2, 3] + 10[11, 12, 13]`

Matrix:

`Try It!det([[1, 0], [0, 1]])1`

Unit:

`Try It!10 km to ft32808.3989501312335958005249343832020997375328083989501312335958 ft`

Below are some of the built-in constants. For the complete list please refer to MathJS Documentation.

Constant | Description |
---|---|

PI/pi | The number pi |

tau | 2 * pi |

E/e | Euler's number |

phi | The golden ratio |

i | Imaginary unit |

SQRT2 | Square root of 2 |

LN2 | Natural logarithm of 2 |

LN10 | Natural logarithm of 10 |

LOG2E | Base-2 logarithm of e |

LOG10E | Base-10 logarithm of e |

Below are some of the more common built-in functions. For the complete list please refer to MathJS Documentation.

Function | Description | Examples |
---|---|---|

sin, cos, tan, cot, asin, acos, atan, atan2, acot, ... | Basic trigonometry functions | sin(pi) + cos(90 deg) |

abs | Calculate the absolute value of a number | abs(-3) |

log, log10, log2 | Calculate the logarithm of a value | log(16, 2) |

sqrt | Calculate the square root of a value | sqrt(16) |

simplify | Simplify an expression | simplify("2x^2+(5-3x)*x+x-x^2") |

derivative | Take the derivative of an expression | derivative("2x^2 + 3x + 4", "x") |

and, or, not, xor | Basic logical functions | true and false or true and (not false) |

det | Calculate determinant of a matrix | det([[1, 0], [0, 1]]) |

inv | Calculate inverse of a square matrix | inv([[1, 0], [0, 1]]) |

eigs | Calculate the eigenvalues and eigenvectors of a symmetric matrix | eigs([[1, 2], [2, 1]]) |

combinations(n, k) | Calculate number of ways of picking k unordered outcomes from n possibilities | combinations(10, 2) |

min, max | Calculate minimum/maximum value of a matrix or a list | min([1, -3, 5, 7]) |

mean | Calculate mean value of matrix or a list | mean([1, -3, 5, 7]) |

variance | Calculate variance of a matrix or a list | variance([1, -3, 5, 7]) |

std | Calculate standard deviation of a matrix or a list | std([1, -3, 5, 7]) |

sum | Calculate sum of a matrix or a list | sum([1, -3, 5, 7]) |

distance, intersect | Basic geometry functions | distance([0, 0, 0], [1, 2, 3]), intersect([0, 0], [10, 10], [10, 0], [0, 10]) |

Below are some of the MathJS operators, for the complete list please see MathJS Documentation.

Operator | Description | Example |
---|---|---|

+, -, *, / | Basic arithmetic operations | 1 + 2 - 3 * 4 / 5 |

^ | Power | 2 ^ 3 |

.*, ./, .^ | Element-wise multiplication, division and power | [1, 2] .* [3, 4] |

%, mod | Modulus | 10 % 3 |

' | Transpose | [[1, 2], [3, 4]]' |

! | Factorial | 5! |

&, |, ~, ^| | Bitwise operations: and, or, not, xor | (7 & ~5) | 8 ^| 1 |

<<, >> | Arithmetic shifts: left, right | 8 >> 2 |

>>> | Logical shift right | -1 >>> 1 |

and, or, not, xor | Logical operators | true and not false |

==, !=, <, <=, >, >= | Comparison operators | 1 > 2 |

to, in | Unit conversion operators | 6 ft to cm |

: | Range | 1:10 |

? : | Ternary operator (conditional expression) | 1 > 2 ? 0 : -1 |

; | Statement separator | x = 1; y = 2 |

Variables can be defined using assignment operator and used in the same way as constants:

`Try It!x = 4242myvar = [1, 2, 3][1, 2, 3]x * myvar[42, 84, 126]`

Variable value can also be changed using the assignment operator:

`Try It!myvar = "Hello""Hello"myvar = "World""World"myvar"World"`

Please note that inside a function, function arguments take precedence over global variables:

`Try It!x = "global""global"f(x) = concat("I am ", x)f("argument")"I am argument"`

Functions can be defined using following format:

`name(arg1, arg2, ..., argN) = body`

where

**name**is the name of the function**arg1, arg2, ..., argN**are the function arguments**body**is an expression used to calculate the result of the function for given arguments

For example:

`Try It!f(x) = x^2 + sin(x)f(pi)9.869604401089358618834490999876151135313699407240790626413349374`

All global variables (including user-defined variables), functions and constants can be accessed in the function body:

`Try It!density = 4242sphere_weight(radius) = density * (4 / 3 * pi * radius ^ 3)sphere_weight(5)21991.14857512855266923850368295652018938018579562574074682461214density = 1.51.5sphere_weight(5)785.3981633974483096156608458198757210492923498437764552437361479`

You can use built-in function help(...) to get information about built-in functions and constants. For examply, try:

`Try It!help(sin)`

`Try It!help(phi)`

To calculate linear interpolation between two values (a, b) for a parameter (t) in the closed unit interval [0, 1] you can use lerp(...) function:

`lerp(a, b, t)`

Resulting value is calculated as

`(1 - t) * a + t * b`

a, b - can be numbers or colors, while t must always be a number:

`Try It!lerp(1, 5, 0.25)2lerp(#000000, #ffffff, 0.5)#FF808080`

Please note that ARGB representation is used for colors interpolation. If this is not desirable, you can define your own color interpolation based on HSV or HSL color representation. Please refer to Colors section for more information.

Cl Calc supports hexadecimal, octal and binary numeric literals and provides functions to convert numbers to/from these representations.

Hexadecimal literals are prefixed with '0x', octal literal are prefixed with '0o' and binary literals are prefixed with '0b'. The literals can include decimal point. On evaluation hex and binary literals are automatically converted to decimal numbers. For example:

`Try It!0xff2550xab.cd171.800781250o6444200b1101.1113.75`

To convert numbers to hexadecimal, octal or binary representation use hex(...), oct(...) and bin(...) functions respectively.

`Try It!hex(255)"0xff"bin(13.75)"0b1101.11"oct(420)0o644`

By default, hexadecimal, octal and binary numbers maintain the same precision as regular numbers (i.e. they are BigNumbers as well):

`Try It!hex(42! + 0.5)"0x3c1581d491b28f523c23abdf35b689c908000000000.8"bin(pi)"0b11.00100100001111110110101010001000100001011010001100001000110101"`

To restrict hexadecimal, octal or binary literal to a specific signed (2's complement) integer and a specific word size append i suffix and a desired word size in bits.

`Try It!0xffi8-10xabcdef12i32-14125672780b1100011i899`

To covert a decimal number to hexadecimal, octal or binary representation as a signed integer with a given word size use a second parameter with the desired word size (in bits) to hex, oct and bin functions.

`Try It!hex(-1, number(8))0xffi8bin(-42, number(8))0b11010110i8`

Cl Calc provides a few functions to work with Unicode encoding.

To convert a string to list of Unicode code points corresponding to each character use toCodePoints(...) function:

`Try It!toCodePoints("I ♡ Cl Calc")[73, 32, 9825, 32, 67, 108, 32, 67, 97, 108, 99]`

To convert back from code points list to string use fromCodePoints(...) function:

`Try It!fromCodePoints([73, 32, 9825, 32, 67, 108, 32, 67, 97, 108, 99])"I ♡ Cl Calc"`

Similarly, to convert a string to UTF8 you can use toUtf8(...) function:

`Try It!toUtf8("I ♡ Cl Calc")[73, 32, 226, 153, 161, 32, 67, 108, 32, 67, 97, 108, 99]`

To convert from UTF8 to string use fromUtf8(...) function:

`Try It!fromUtf8([73, 32, 226, 153, 161, 32, 67, 108, 32, 67, 97, 108, 99])"I ♡ Cl Calc"`

To encode array of bytes to string using Base64 Encoding use base64Encode(...) function:

`Try It!base64Encode([ 1, 2, 3, 4, 5 ])"AQIDBAU="`

To decode Base64 encoded string back to byte array use base64Decode(...) function:

`Try It!base64Decode("AQIDBAU=")[1, 2, 3, 4, 5]`

You can encode string to Base64 by encoding it to UTF8 first:

`Try It!base64Encode(toUtf8("Hello World"))"SGVsbG8gV29ybGQ="fromUtf8(base64Decode("SGVsbG8gV29ybGQ="))"Hello World"`

Cl Calc supports the following hash functions: md5, sha1, sha224, sha256. Each hash function accepts an array of bytes as its argument and produces hash string as the result. Below are some examples:

`Try It!data = toUtf8("Hello World")[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]md5(data)"b10a8db164e0754105b7a99be72e3fe5"sha1(data)"0a4d55a8d778e5022fab701977c5d840bbc486d0"sha224(data)"c4890faffdb0105d991a461e668e276685401b02eab1ef4372795047"sha256(data)"a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"`

Cl Calc supports some operations with colors by introducing Color data type, color literals and some functions that work with colors.

There are few ways to construct a Color. The easiest one is to use color literals. Color literals resemble web color format, where literal starts with hash character '#' followed by three bytes in hex representing RGB components, or four bytes in hex representing ARGB components (where A is an alpha component). If RGB format is used, alpha component is set to 255 (i.e. opaque). For example:

`Try It!#ABCDEF#FFABCDEF#80FF00FF#80FF00FF`

As you may notice, when Cl Calc outputs color as a result of an expression, it is displayed as a color preview square. You can click it to see color value. Checkerboard background used to preview opacity.

You can also construct color explicitly by calling any of the following functions:

Constructor | Description | Example |
---|---|---|

color4b(a, r, g, b) | Construct color from ARGB bytes. | color4b(255, 0, 0, 255) |

color3b(r, g, b) | Construct color from RGB bytes. Alpha is set to 255. | color3b(0, 0, 255) |

color4f(a, r, g, b) | Construct color from four floating-point numbers in a range [0, 1]. | color4f(1, 0, 0, 1) |

colorU32(number) | Construct color from unsigned 32-bit integer where each byte (higher to lower) represents ARGB components. | colorU32(0xFF0000FF) |

colorHsv(h, s, v) | Construct color from HSV (hue, saturation, value) components. | colorHsv(240, 100, 100) |

colorHsl(h, s, l) | Construct color from HSL (hue, saturation, lightness) components. | colorHsl(240, 100, 50) |

You can add, subtract, divide and multiply colors in the same way as regular numbers. For these operations ARGB representation is used, and operation performed on each component individually:

`Try It!#FF0000 + #00FF00#FFFFFF00#ffffff - #0080ff00#FF7F00FF`

You can also multiply and divide colors by a number:

`Try It!#808080 * 2#FFFFFFFF#808080 / 2#80404040`

You can convert color to different representations using following functions:

Function | Description | Example |
---|---|---|

rgb(color) | Convert color to RGB bytes. | rgb(#0000FF) |

argb(color) | Convert color to ARGB bytes. | argb(#0000FF) |

argbf(color) | Convert color to ARGB components, where each component is represented by a floating-point number in a range [0, 1]. | argbf(#0000FF) |

hsv(color) | Convert color to HSV representation. | hsv(#0000FF) |

hsl(color) | Convert color to HSL representation. | hsl(#0000FF) |

Cl Calc can plot a two-dimensional graph of a function with plot2d(...) function.

`plot2d(expression, variable, [ from, to ])`

where

**expression**an expression of a function to plot**variable**variable name that will be used as an 'x' variable (horizontal axis)**from, to**numbers representing begin and end of the interval that will be plotted

For example:

`Try It!plot2d(x^3 - 2x^2 + 1, x, [-3, 3])`

You can zoom function graph with a mouse wheel and drag it by holding left mouse button.

Please note that in its current implementation plot2d function doesn't detect vertical asymptotes. If you are plotting function that has vertical asymptotes you may see vertical lines appear where the function value "jumps".

Cl Calc is configured to use big numbers when possible with the default precision of 64 significant digits (you can read more about underlying long arithmetics library on Decimal.js GitHub Page). The precision can be adjusted in Settings.

While most of the MathJS functions and operators support big numbers, there are still some that don't and will degrade precision to 64-bit floating-point numbers. For example, complex numbers do not support long arithmetics and will degrade precision:

`Try It!abs(30!)265252859812191058636308480000000abs(30! + 0i)2.6525285981219107e+32`

For convenience, Cl Calc introduces some function aliases to built-in MathJS functions:

Alias | MathJS Function |
---|---|

nCr | combinations |

nPr | permutations |

ln | log |

For convenience, Cl Calc stores a reference to the result of the last evaluated expression in a special built-in variable '$'. It can then be used in the same manner as a regular variable.

`Try It!2+35$5$+27$7`

While it can be useful for simple calculations, the '$' variable should be avoided in more complex calculations and especially calculations with statements. Because it holds a reference to the last result and not a copy of the result, it can observe the modifications to the value, which may sometimes appear unexpected:

`Try It!x = { "a": 1 }{"a": 1}x.a = 42; $.a[42]`

Cl Calc is licensed under MIT license and its source code is available on the GitHub.

For contributing, reporting bugs or suggesting features please visit issues page.

Third party libraries: