Scroll to navigation

QALC(1) General Commands Manual QALC(1)

NAME

qalc - Powerful and easy to use command line calculator

SYNOPSIS

qalc [options] [expression]

DESCRIPTION

Qalculate! is a multi-purpose cross-platform desktop calculator. It is simple to use but provides power and versatility normally reserved for complicated math packages, as well as useful tools for everyday needs (such as currency conversion and percent calculation). Features include a large library of customizable functions, unit calculations and conversion, physical constants, symbolic calculations (including integrals and equations), arbitrary precision, uncertainty propagation, interval arithmetic, plotting, and a user-friendly interface. qalc is the command line interface of Qalculate!.

OPTIONS

set the number base for results and, optionally, expressions
use colors to highlight different elements of expressions and results
update exchange rates
execute commands from a file first
display this help and exits
start in interactive mode
displays a list of all user-defined or matching variables, functions, units, and prefixes.
displays a list of all or matching functions.
displays a list of all or matching prefixes.
displays a list of all or matching units.
displays a list of all or matching variables.
terminate calculation and display of result after specified amount of time
do not load any functions, units, or variables from file
do not load any global currencies from file
do not load any global data sets from file
do not load any global functions from file
do not load any global units from file
do not load any global variables from file
start in programming mode (same as -b "base base" -s "xor^", with base conversion)
as set command in interactive program session (ex. --set "base 16")
reduce output to just the result of the input expression
-/+u8
switch unicode support on/off
show application version and exit

The program will start in interactive mode if no expression and no file is specified (or interactive mode is explicitly selected).

COMMANDS

Equivalent to set approximation try exact.
Set default assumptions for unknown variables (unknown, non-zero, positive, negative, non-positive, non-negative + number, real, rational, integer, boolean).
Sets the result number base (equivalent to set base).
Removes the user-defined variable or function with the specified name.
Example: delete var1.
Equivalent to set approximation exact.
Expands the current result.
Downloads current exchange rates from the Internet.
Factorizes the current result.
Displays a list of variables, functions and units. Enter with argument 'currencies', 'functions', 'variables', 'units', or 'prefixes' to show a list of all currencies, functions, variables, units, or prefixes. Enter a search term to find matching variables, functions, units, and/or prefixes. If command is called with no argument all user-definied objects are listed.
Example: list functions.
Example: find dinar.
Example: find variables planck.
Creates a function with the specified name and expression. Use '\x', '\y', '\z', '\a', etc. for arguments in the expression.
Example: function func1 5*\x.
Displays information about a function, variable, unit, or prefix.
Example: info sin.
Memory operations (memory clear, memory store, memory plus, memory minus). Recall the memory using the MR/MRC variable.
Displays the current mode.
Applies partial fraction decomposition to the current result.
Saves the current result in a variable with the specified name. You may optionally also provide a category (default "Temporary") and a title. If name equals "mode" or "definitions", the current mode and definitions, respectively, will be saved.
Example: store var1.
Converts the previous result. Equivalent to using "to" at the end of an expression. Example: to m/s
Example: to bin
Create a variable with the specified name and expression.
Example: variable var1 pi / 2.
Terminates the program.

Commands for RPN mode:

(De)activates the Reverse Polish Notation stack and syntax. "syntax" activates only the RPN syntax and "stack" enables the RPN stack.
Displays the RPN stack.
Clears the entire RPN stack.
Duplicates a value on the RPN stack to the top of the stack. If no index is specified, the top of the stack is duplicated. Index 1 is the top of stack and negative index values count from the bottom of the stack.
Changes the position of a value on the RPN stack. Index 1 is the top of stack and negative index values count from the bottom of the stack.
Example: move 2 4
Removes the top of the RPN stack or the value at the specified index. Index 1 is the top of stack and negative index values count from the bottom of the stack.
Rotates the RPN stack up (default) or down.
Swaps position of values on the RPN stack. If no index is specified, the values on the top of the stack (index 1 and index 2) will be swapped and if only one index is specified, the value at this index will be swapped with the top value. Index 1 is the top of stack and negative index values count from the bottom of the stack.
Example: swap 2 4

When a line begins with '/', the text that follows is always interpreted as a command.

KEYBINDINGS

shows a list of functions, variables, and units that matches the last object in the current expression
terminates the program
switches between approximation modes (exact, try exact, auto)
switches between fraction modes (simple, decimal, auto)
saves the current result in a temporary variable

SETTINGS

These settings are changed using the set command (e.g. set base 16) or the -s, --set command line option (e.g. qalc -s "base 16"). Possible values are shown in parenthesis. 1 and 0 can be used instead of on and off. If the value is left out, a value of 1 is generally assumed. The default value is marked with '*'.

Algebraic mode:

Determines if the expression is factorized or not after calculation.
Determines if unknown values will be assumed non-zero (x/x=1).
Display a message after a value has been assumed non-zero.
Default assumptions for unknown variables.

Calculation:

Default angle unit for trigonometric functions.
How approximate variables and calculations are handled. In exact mode approximate values will not be calculated.
If activated, interval arithmetic determines the final precision of calculations (avoids wrong results after loss of significance) with approximate functions and/or irrational numbers.
Determines the method used for interval calculation / uncertainty propagation.
Specifies the default number of significant digits displayed and determines the precision used for approximate calculations.

Enabled objects:

Interpret undefined symbols in expressions as unknown variables.
If activated physical constants include units (e.g. c = 299 792 458 m∕s).

Generic display options:

Use abbreviated names for units and variables.
Use colors to highlight different elements of expressions and results.
Always place negative values last.
Add extra space around operators.
Display Unicode characters.

Numerical display:

Determines the default decimal separator.
Determines how rational numbers are displayed (e.g. 5/4 = 1 + 1/4 = 1.25). 'long' removes limits on the size of the numerator and denonimator.
Enables two's complement representation for display of negative hexadecimal numbers.
Use 'j' (instead of 'i') as default symbol for the imaginary unit.
Use lowercase e for E-notation (5e2 = 5 * 10^2).
Use lowercase letters for number bases > 10.
Determines whether halfway numbers are rounded upwards or towards the nearest even integer.
Determines how scientific notation is used (e.g. 5 543 000 = 5.543E6).
If actived, zeroes are kept at the end of approximate numbers.
Enables two's complement representation for display of negative binary numbers.

Parsing:

Use ^ as bitwise exclusive OR operator.
Determines the default decimal separator.
Allows use of ',' as thousands separator.
Allows use of '.' as thousands separator.
Use 'j' (instead of 'i') as default symbol for the imaginary unit.
See syntax section.
If activated, numbers are interpreted as approximate with precision equal to the number of significant digits (3.20 = 3.20+/-0.005).

Units:

Enables automatic use of hecto, deca, deci, and centi.
Controls automatic unit conversion of the result. 'optimalsi' always converts non-SI units, while 'optimal' only converts to more optimal unit expressions, with less units and exponents.
If activated, binary prefixes are used by default for information units.
Enables automatic conversion to the local currency when optimal unit conversion is enabled.
Enables automatic use of prefixes in the denominator of unit expressions.
If activated, units are separated from variables at the end of the result.
Enables automatic use of prefixes in the result.
Use negative exponents instead of division for units in result (m/s = m*s^-1).
Determines how expressions with temperature units are calculated (hybrid acts as absolute if the expression contains different temperature units, otherwise as relative).

Other:

Ignore system language and use English (requires restart).
Activates the Reverse Polish Notation stack.
Save functions, units, and variables on exit.
Save settings on exit.

SYNTAX

Mathematical entities:

Numbers
These are the regular numbers composed by digits 0-9 and a decimal sign — a dot, or a comma if it is the default decimal point in the locale/language used. If comma is used as decimal sign, the dot is still kept as an alternative decimal sign, if not explicitly deactivated. Numbers include integers, real numbers, and complex numbers. The imaginary part of complex numbers are written with as regular number followed by the special variable "i" (can be changed to a "j"), which represents the square root of -1. Spaces between digits are ignored ("5 5 = 55"). "E" (or "e") can be considered as a shortcut for writing many zeroes and is equivalent to multiplication by 10 raised to the power of the right-hand value (e.g. "5E3 = 5000"). Sexagesimal numbers (and time) can be entered directly using colons (e.g. "5:30 = 5.5"). A number immediately preceded "0b", "0o", "0d" or "0x" are interpreted as a number with base 2, 8, 12 or 16, respectively (e.g. "0x3f = 63").

Intervals
A number interval can be entered using the interval() function, the uncertainty() function, or using "±" or "+/-" (e.g. 5±1 = uncertainty(5, 0.2) = interval(4, 6)). If the read precision option is activated, decimal numbers are interpreted as an interval between the numbers that are normally rounded to the entered number (e.g. 1.1 = 1.1±0.05). If interval calculation using variance formula is activated (default), the interval represents the standard uncertainty (deviation) of the value.

Vectors and Matrices
A matrix is a two-dimensional rectangular array of mathematical objects. Vectors are matrices with only one row or column, and thus one-dimensional sequences of objects. Vectors and matrices are generated by various functions, or using syntax in the form of [1, 2, 3, 4] and [[1, 2], [3, 4]].

Variables/Constants
See the list of variables in the GUI manual or using the command .I list variables

Functions
See the list of functions in the GUI manual or using the command .I list functions

Units and Prefixes
See the list of units and prefixes in the GUI manual or using the command .I list units. Abbreviated, plural and singular forms of unit names and prefixes are generally allowed. Prefixes must be put immediately before the unit to be interpreted as prefixes (eg. 5 mm = 0.005 m, but 5 m m = 5 m^2). For convenience units allow the power operator to be left out (e.g. 5 m2 = 5 m^2), with currencies excluded.

Unknowns
Unknowns are text strings without any associated value. These are temporary unknown variables with default assumptions. Unknowns can also be explicitly entered by placing a backslash (\) before a single character (e.g. 5\a + 2\b) or using quotation mark before and after a text string (e.g. 5 "apples" + 2 "bananas"). If unknowns are activated characters without any associated variable, function or unit in an expression, will be regarded as an unknown variable.

Date and Time
Date/time values are specified using quoted text string (quotation marks are not needed for function arguments), using standard date and time format (YYYY-MM-DDTHH:MM:SS). Some local formats are also supported, but not recommended. The local time zone are used, unless a time zone is specified at the end of the time string (Z/UTC/GMT or +/-HH:MM). Date/time supports a small subset of arithmetic operations. The time units represents calendar time, instead of average values, when added or subtracted to a date.

Text
This category represent a number of different function argument types, such as regular text and file names. They can, but do not need to be put in quotes except when containing the argument separator.

Comments
All text after a hashtag (e.g. (5*2)/2 #calculating triangle area) is treated as a comment, which are added to the history.

Operations and operators (word operators such as AND must be surrounded by space):

Addition (+)

Subtraction (-)

Multiplication (*)

Division (/)

Remainder (%, rem) and modulo (%%, mod)
Returns the remainder after division.

Integer division (//, div)
Rounds the result of division towards zero.

Exponentiation (^, **)
Note that x^y^z equals x^(y^z), and not (x^y)^z. Note also that for non-integer exponents with negative bases, the principal root is returned and not the real root ((-8)^(1/3) equals 1 + 1.73i, and not -2). To calculate the real root for negative values, use the cbrt() and root() functions.

10^x (E)

Parenthesis ((, ))

Logical operators (!, NOT, ||, OR, &&, AND, XOR, NOR, NAND)

Bitwise operators (~, |, &, <<, >>, XOR)

Comparison operators (=, !=, <, <=, >, >=)
Returns 1 if expression is true and 0 if false. The x variable is isolated if the expression does not evaluate as true or false. Primarily used for equations and inequalities.

Dot product (.)

Element-wise operators (.*, ./, .^)

Save operator (:=)
Saves the expression to the right of the operator as a variable or function (e.g. var1:=5, func1():=x+y).

Evaluation priority order: parenthesis, 10^x, exponentiation, functions, bitwise NOT, logical NOT, multiplication/division/remainder, addition/subtraction, bitwise NOT, bitwise shift, comparisons, bitwise AND, bitwise XOR, bitwise OR, logical AND, logical OR.

The evaluation of short/implicit multiplication without any multiplication sign (e.g. 5x, 5(2+3)), differs depending on the parsing mode. In the conventional mode implicit multiplication does not differ from explicit multiplication (12/2(1+2) = 12/2*3 = 18, 5x/5y = 5 * x/5 * y = xy). In the parse implicit multiplication first mode, implicit multiplication is parsed before explicit multiplication (12/2(1+2) = 12/(2 * 3) = 2, 5x/5y = (5 * x)/(5 * y) = x/y). The default adaptive mode works as the parse implicit multiplication first mode, unless spaces are found (1/5x = 1/(5 * x), but 1/5 x = (1/5) * x). In the adaptive mode unit expressions are parsed separately (5 m/5 m/s = (5 * m)/(5 * (m/s)) = 1 s). Function arguments without parentheses are an exception, where implicit multiplication in front of variables and units is parsed first regardless of mode (sqrt 2x = sqrt(2x)).

In chain mode, expressions are calculated from left to right, ignoring standard order of operations, like the immediate execution mode of a traditional calculator (1+2*3 = (1+2)*3 = 9).

The "to"-operator is used for unit conversion and manipulation of how the result is presented. Place " to " or a right arrow (e.g. "->") followed by one of expressions/commands the below, at the end of an expression.

- a unit or unit expression (e.g. meter or km/h)
prepend with ? to request the optimal prefix
prepend with b? to request the optimal binary prefix
prepend with + or - to force/disable use of mixed units
- a variable or physical constant (e.g. c)
- base (convert to base units)
- optimal (convert to optimal unit)
- mixed (convert to mixed units, e.g. hours + minutes)
- bin, binary (show as binary number)
- bin# (show as binary number with specified number of bits)
- oct, octal (show as octal number)
- duo, duodecimal (show as duodecimal number)
- hex, hexadecimal (show as hexadecimal number)
- hex# (show as hexadecimal number with specified number of bits)
- sex, sexa2, sexa3, sexagesimal (show as sexagesimal number; sexa2 hides and sexa3 rounds arcseconds)
- latitude, latitude2, longitude, longitude2 (show as sexagesimal latitude/longitude; latitude2 and longitude2 hide arcseconds)
- bijective (shown in bijective base-26)
- fp16, fp32, fp64, fp80, fp128 (show in binary floating-point format)
- roman (show as roman numerals)
- time (show in time format)
- unicode
- base # (show in specified number base)
- bases (show as binary, octal, decimal and hexadecimal number)
- rectangular, cartesian (show complex numbers in rectangular form)
- exponential (show complex numbers in exponential form)
- polar (show complex numbers in polar form)
- cis (show complex numbers in cis form)
- angle, phasor (show complex numbers in angle/phasor notation)
- UTC (show date and time in UTC time zone)
- UTC+/-hh[:mm] (show date and time in specified time zone)
- calendars
- fraction (show result as mixed fraction)
- factors (factorize result)

Similarly where (or alternatively "/.") can be used at the end (but before "to"), for variable assignments, function replacements, etc. (e.g. "x+y where x=1 and y=2", "x^2=4 where x>0", and "sin(5) where sin()=cos()").

EXAMPLES

Note that semicolon can be replaced with comma, if comma is not used as decimal or thousands separator.

Basic functions and operators

= sqrt(4)
= 4^(0.5)
= 4^(1/2)
= 2
= [5; 4; 3; 2]
= 4 * sqrt(2) (in exact mode)
= root(-27; 3)
= -3 (real root)
(-27)^(1/3)
= 1.5 + 2.5980762i (principal root)
= log(25; e)
= 3.2188758
= log(4; 2)/log(100; 10)
= 1
5!
= 1 * 2 * 3 * 4 * 5
= 120
5\2 (integer division)
= 5//2
= trunc(5/2)
= 2
5 mod 3
= mod(5; 3)
= 2
52 to factors
= 2^2 * 13
25/4 * 3/5 to fraction
= 3 + 3/4
= 9
= sin(90 deg) - cos(180 deg)
= 2
= 1 + 2 + 3 + 4 + 5 = 15
= 1^2 + sin(1) + 2^2 + sin(2) + ... = 55.176162
= 1 * 2 * 3 * 4 * 5 = 120
store value 5 in variable var1
5^2 #this is a comment
= 25
= cosh(0.5) = 1.1276260
plots the function y=x^2 from -5 to 5

Units

5 dm3 to L
= 25 dm^3 to L
= 5 L
20 miles / 2h to km/h
= 16.09344 km/h
1.74 to ft = 1.74 m to ft
= 5 ft + 8.5039370 in
1.74 m to -ft
= 5.7086614 ft
100 lbf * 60 mph to hp
= 16 hp
50 Ω * 2 A
= 100 V
50 Ω * 2 A to base
= 100 kg*m^2*s^-3*A^-1
10 N / 5 Pa
= (10 N)/(5 Pa) = 2 m^2
5 m/s to s/m
= 0.2 s/m
500 EUR - 20% to USD
= 451.04 USD
500 megabit/s * 2 h to b?byte
= 419.09516 gibibytes

Physical constants

= (coulombs_constant / newtonian_constant) * bohr_radius
= 7.126e9 kg*H*m^-1
= 9.1093837e-31 kg
5 ns * rydberg to c
= 6.0793194E-8c
= 4.129e-22 g
(G * planet(earth; mass) * planet(mars; mass))/(54.6e6 km)^2
= 8.58e16 N (gravitational attraction between earth and mars)

Uncertainty and interval arithmetic
result with interval arithmetic activated is shown in parenthesis

= 0.460±0.088 (0.46+/-0.12)
(2+/-0.02 J)/(523+/-5 W)
= 3.824+/-0.053 ms (3.82+/-±0.075 ms)
= intervall(-8.2500000; 12.750000) (intervall(0; 25))

Algebra

(5x^2 + 2)/(x - 3)
= 5x + 15 + 47/(x - 3)
(\a + \b)(\a - \b) = ("a" + "b")("a" - "b")
= 'a'^2 - 'b'^2
(x + 2)(x - 3)^3
= x^4 - 7x^3 + 9x^2 + 27x - 54
= x^4 - 7x^3 + 9x^2 + 27x - 54 to factors
= (x + 2)(x - 3)^3
= 11
= 5x
1/(x^2+2x-3) to partial fraction
= 1/(4x - 4) - 1/(4x + 12)
x = 3 or x = -4
x = 7.1340411 m
x = (1 / (2pi)) m
x = 16 cm (height of 20 L cylinder with radius 20 cm)
x = sin(0.2)^2
x = 0.039469503
= x > 25 or x < 0
= lambertw(e^x)
= 32/5
= [-32/3; -128/3; -64/3]
= 6e^(2x) - 2x - 1

Calculus

= 12x
= (2/5) * cosh(x^2) - sinh(x^2)/(5x^2) + (3y)/(2 * sqrt(x))
= 2x^3 + C
= 248
= 2x * sqrt(x) * y + Shi(x^2) / 10 + C
= 3.6568542y + 0.87600760
= 4 / ln(3)

Matrices and vectors

((1; 2; 3); (4; 5; 6))
= [[1; 2; 3]; [4; 5; 6]] (2x3 matrix)
(1; 2; 3) * 2 - 2
= [1 * 2 - 2; 2 * 2 - 2; 3 * 2 - 2]
= [0; 2; 4]
(1; 2; 3).(4; 5; 6)
= dot((1; 2; 3); (4; 5; 6))
= 32 (dot product)
= [-3; 6; -3] (cross product)
= [[7; 16; 27]; [40; 55; 72]] (hadamard product)
((1; 2; 3); (4; 5; 6)) * ((7; 8); (9; 10); (11; 12))
= [[58; 64]; [139; 154]] (matrix multiplication)
((1; 2); (3; 4))^-1
= inverse([[1; 2]; [3; 4]])
= [[-2; 1]; [1.5; -0.5]]

Statistics

= 4.5
= 1.87
= percentile([5; 6; 4; 2; 3; 7]; 25)
= 2.9166667
= 0.053990967
= -0.33737388 (depends on the data in the CSV file)

Time and date

10:31 + 8:30 to time
= 19:01
10h 31min + 8h 30min to time
= 19:01
= "2020-07-10T07:50:40Z"
"2020-07-10T07:50CET" to utc+8
= "2020-07-10T14:50:00+08:00"
"2020-05-20" + 523d
= addDays(2020-05-20; 523)
= "2021-10-25"
= "2020-07-05"
"2020-10-05" - today
= days(today; 2020-10-05)
= 87
= 1 589 925 600
= "2020-05-20T00:00:00"
"2020-05-20" to calendars
returns date in Hebrew, Islamic, Persian, Indian, Chinese, Julian, Coptic, and Ethiopian calendars

Number bases

52 to bin
= 0011 0100
52 to bin16
= 0000 0000 0011 0100
52 to oct
= 064
52 to hex
= 0x34
0x34
= hex(34)
= base(34; 16)
= 52
523<<2&250 to bin
= 0010 1000
52.345 to float
= 0100 0010 0101 0001 0110 0001 0100 1000
= 1715241/32768
= 52.345001
= 1.2207031e-6
52.34 to sexa
= 52°20'24"
1978 to roman
= MCMLXXVIII
52 to base 32
= 1K
sqrt(32) to base sqrt(2)
= 100000

SEE ALSO

The manual of the graphical user interface at https://qalculate.github.io/manual/index.html (includes more details about the syntax and elements supported in mathematical expressions, and various options, and includes a complete list of functions, variables, and units)

BUGS

Please report any bugs at https://github.com/Qalculate/libqalculate/issues

AUTHORS

Hanna Knutsson <hanna.knutsson@protonmail.com>.

13 July 2020