Cl Calc is an open-source, lightweight, command-line style online calculator. While it has clean and simple interface, it is quite powerful due to the fact that its core is based on the MathJS library.
Some of the Cl Calc features include:
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
Try It!x = [[1, 2], [3, 4]] * inv([[1, 2], [3, 4]])[[1, 0], [0, 1]]det(x)1
Try It!90 km/h to m/s25 m / s110 V * 20 A * 30 days to kWh1584 kWh
Try It!hsl(#ffff0000 + #ff0000ff)[300, 100, 50]colorHsl(300, 100, 50)#FFFF00FF
and much more!
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:
|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||Search in command history.|
|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. So far there are two settings available: toggle thousands separator and precision.
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.
The data types suported by MathJS are:
Try It!(2+3i)^2-5 + 12i
Try It!fraction("2/3") + fraction("3/4")17/12
Try It!3 > 2 and 3 < 5true
Try It!concat("Hello, ", "World")"Hello, World"
Try It![1, 2, 3] + 10[11, 12, 13]
Try It!det([[1, 0], [0, 1]])1
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.
|PI/pi||The number pi|
|tau||2 * pi|
|phi||The golden ratio|
|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 most common built-in functions. For the complete list please refer to MathJS Documentation.
|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||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")|
|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]])|
|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])|
|var||Calculate variance of a matrix or a list||var([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.
|+, -, *, /||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]]'|
|&, |, ~, ^|||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|
|? :||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
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:
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 note 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 and binary numeric literals and provides functions to convert numbers to hexadecimal or binary representation.
Hexadecimal literals are prefixed with '0x' or '0X' and binary literals are prefixed with '0b' or '0B'. Both can include decimal point. On evaluation hex and binary literals are automatically converted to decimal numbers. For example:
To convert numbers to hexadecimal or binary representation you can use hex(...) and bin(...) functions respectively. These functions accept either individual numbers or lists and matrices:
Try It!hex(255)"0xff"bin(13.75)"0b1101.11"hex([16, 200, 128])["0x10", "0xc8", "0x80"]
Hexadecimal 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"
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:
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:
|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:
|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 ])
Try It!plot2d(sin(1/x), x, [-5, 5])
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:
For convenience, Cl Calc stores value of the last evaluated expression in the built-in variable '$'. It can then be used in the same manner as a regular variable. However, it doesn't work with a function assignment.
Be extra careful with '$' variable, since its value updated after every expression evaluation. It is nothing more then just a shortcut to quickly access the value of the previous expression.
For contributing, reporting bugs or suggesting features please visit issues page.
Current version: 1.0.0.
Third party libraries: