Built-in function reference
This page lists every function built into Varlig Calc. Call a function by name, with its
arguments in parentheses separated by commas: sqrt(16), round(17.46, 0.05).
- Names ignore case, so
SQRT(16)works too. - The number of arguments is checked.
sqrt(4, 9)shows an error rather than ignoring the 9. - Numbers can keep their thousands separators. A comma followed by three digits groups
thousands and a comma followed by a space separates arguments, so
max(1,000, 2,000)is 2,000 andsqrt(1,024)is 32. - Round or convert a function’s answer on the same line, as in
sqrt(2) to 4 dporabs(-5 km) in m. - Find a name in the table below, then see its section for details and examples.
Many functions also have an English phrase, such as square root of 16; see
Word-based mathematics. To write your own, see
Your own functions.
All functions
| Function | Meaning |
|---|---|
abs(x) |
Absolute value; keeps units; magnitude of a complex number |
sign(x) |
−1, 0 or 1 |
int(x), trunc(x) |
Integer part, toward zero |
round(x), round(x, step) |
Nearest integer, or nearest multiple of step |
floor(x), floor(x, step) |
Round down, toward negative infinity |
ceil(x), ceil(x, step) |
Round up, toward positive infinity |
sqrt(x), cbrt(x) |
Square and cube root; roots keep units that divide evenly |
exp(x), ln(x) |
Natural exponential and logarithm |
log(x), log10(x), log2(x), logbase(x, b) |
Logarithms |
sin, cos, tan |
Trigonometry in radians, or of an angle such as 30° |
sind, cosd, tand |
Trigonometry in degrees |
asin, acos, atan |
Inverse trigonometry, result in radians |
asind, acosd, atand |
Inverse trigonometry, result in degrees |
atan2(y, x) |
Quadrant-aware angle in radians |
sinh, cosh, tanh, asinh, acosh, atanh |
Hyperbolic functions |
factorial(n), fact(n) |
Factorial; also written n! |
gcd(a, b), lcm(a, b) |
Greatest common divisor and least common multiple; exact, also for fractions |
combination(n, k), permutation(n, k) |
Number of selections |
clamp(x, low, high) |
Keep a value within limits |
hex(n), bin(n) |
Show a number in hexadecimal or binary |
random(), rand(), random(a, b), rand(a, b) |
Random numbers |
complex(re, im), real, imag, conj, arg |
Complex numbers |
sum, total, product, average, mean, avg, median, min, max, count, length, variance, stddev, stdev |
Totals and statistics of a list (several also accept separate arguments) |
sum(expr, var, lo, hi), summation(...), product(expr, var, lo, hi) |
Sums and products over a counter |
range(a, b), range(a, b, step) |
List of numbers, including both ends |
sort, reverse, unique, slice(list, start, end) |
Reorder or pick from a list |
map(expr, var, list), filter(cond, var, list) |
Work out or test each item of a list |
dot, cross, identity(n), shape, transpose, det, inverse, trace, rank |
Vectors and matrices |
solve_system(A, b), eigenvalues, qr, lu, svd |
Linear systems and matrix decompositions |
solve(equation, var, lo, hi) |
Solve an equation numerically between two bounds |
differentiate(expr, var), derivative(expr, var) |
Derivative as a formula |
differentiate(expr, var, point), derivative(expr, var, point) |
Derivative at a point, as a number |
integrate(expr, var, lo, hi) |
Definite integral, worked out numerically |
easter(year) |
Western Easter Sunday |
tyre_speed(width, aspect, rim, rotation) |
Road speed from a tyre size and wheel rotation |
Numbers and counting
| Function | Arguments and meaning |
|---|---|
abs(x) |
Absolute value; keeps a quantity’s unit; magnitude for a complex number |
sign(x) |
Sign of a plain real number: -1, 0 or 1 |
int(x), trunc(x) |
Integer part, toward zero |
sqrt(x) |
Square root; for a negative number, ask for a complex root: sqrt(-16 + 0i) |
cbrt(x) |
Cube root, including of negative numbers |
factorial(n), fact(n) |
Factorial of a whole number, 0 or more; also written n! |
gcd(a, b) |
Greatest common divisor of two exact numbers, never negative |
lcm(a, b) |
Least common multiple of two exact numbers, never negative |
clamp(x, low, high) |
Keep a value between low and high, all of the same kind; lower bound first |
permutation(n, k) |
Ordered selections of k items from n |
combination(n, k) |
Unordered selections of k items from n |
hex(x), bin(x) |
Show a number in hexadecimal or binary |
abs(-£45.20) gives £45.20sign(-5) gives -1int(7.8) gives 7sqrt(144 m^2) gives 12 mcbrt(-27) gives -3factorial(5) gives 120gcd(1920, 1080) gives 120lcm(4, 6) gives 12clamp(115, 0, 100) gives 100clamp(£120, £0, £100) gives £100.00combination(10, 2) gives 45permutation(8, 3) gives 336hex(255) gives 0xFFbin(10) gives 0b1010A few everyday readings: gcd(1920, 1080) shows that a 1920 × 1080 screen is 16:9 (1920 ÷ 120
by 1080 ÷ 120). combination(10, 2) is the number of different pairs in a group of ten, and
permutation(8, 3) the number of ways to fill gold, silver and bronze from eight runners.
clamp keeps money, quantities and durations in their units when the value and both limits
measure the same thing, so clamp(£120, £0, £100) caps a refund at £100.00. For factorials and
selections, use whole numbers with k no bigger than n. 5! is a shorter
way to write factorial(5). For other roots, use the phrase root 3 of 27; there’s no general
root(...) function.
Rounding
round, floor and ceil take an optional step to round to:
round(17.46, 0.05) gives 17.45ceil(23, 6) gives 24floor(7.8) gives 7ceil(23, 6) rounds 23 eggs up to whole boxes of six. The step isn’t a number of decimal
places: round(17.456, 2) rounds to the nearest 2 and gives 18, and a hint on round suggests
17.456 to 2 dp instead. For significant figures, write to 3 sf. See
Rounding for halves, negative numbers and money.
Trigonometry and angles
| Function family | Meaning |
|---|---|
sin, cos, tan |
Trigonometry; a plain number is in radians |
sind, cosd, tand |
Trigonometry of a plain number in degrees |
asin, acos, atan |
Inverse trigonometry; the result carries a radian unit |
asind, acosd, atand |
Inverse trigonometry, returning degrees |
atan2(y, x) |
Quadrant-aware angle, as a plain number of radians |
sinh, cosh, tanh |
Hyperbolic functions |
asinh, acosh, atanh |
Inverse hyperbolic functions |
sin(30°) gives 0.5cosd(60) gives 0.5tan(45°) gives 1sin(pi/2) gives 1asind(0.5) gives 30°asin(1) gives 1.5707963268 radasin(0.5) in degrees gives 30°atan2(-1, -1) * 180 / pi gives -135cosh(0) gives 1sin, cos and tan accept an angle in any angle unit, such as 30° or 30 degrees. To see
the result of asin, acos or atan in degrees, add in degrees, as above, or use the degree
forms.
atan2 takes the y value first and works out which quadrant the angle is in, so
atan2(-1, -1) points down and to the left (−135°), where atan(1) alone can’t tell.
Hyperbolic functions take plain numbers. Inverse functions only accept values in their real
range; for example, asin(2) shows Error: imaginary number. For complex results, see
Complex numbers.
Logarithms and exponentials
| Function | Meaning |
|---|---|
ln(x) |
Natural logarithm |
log(x), log10(x) |
Base-10 logarithm |
log2(x) |
Base-2 logarithm |
logbase(x, b) |
Logarithm of x in base b |
exp(x) |
Natural exponential |
log(1000) gives 3log10(1000000) gives 6log2(1024) gives 10logbase(81, 3) gives 4ln(exp(2)) gives 2exp(0) gives 1A logarithm needs a positive number: log(0) shows Error: ∞, and log(-100) shows
Error: imaginary number. For the complex logarithm, write the number as a complex one, as in
ln(-1 + 0i). The base must be positive and not 1. Logarithms, exponentials and hyperbolic functions don’t accept units or money.
Random values
random number between 1 and 6 gives 4random(1, 6) gives 2rand(1, 100) gives 57random() gives 0.4381930527rand() gives 0.9102746385random(0, 1) gives 0.2373052626random(a, b)and the phraserandom number between a and bgive a whole number fromatob, including both ends.random()gives a fraction from 0 up to, but not including, 1.random(0, 1)is a special case that does the same.randis another name forrandom.- Bounds must be plain whole numbers, lowest first, within the range of 64-bit integers. One argument, more than two, fractions or reversed bounds show an error.
- Varlig can draw a new number whenever the note recalculates. Store a draw in a variable, such
as
roll = random(1, 6), when later lines should use the same number.
Lists and statistics
average([12, 18, 9, 21]) gives 15median([3, 9, 4, 7, 5]) gives 5sum([£12.50, £8, £4.25]) gives £24.75max(4, 9, 2) gives 9stddev([2, 4, 6]) gives 2sum(k, k, 1, 100) gives 5,050range(0, 20, 5) gives [0, 5, 10, 15, 20]sort([3, 1, 2]) gives [1, 2, 3]slice([10, 20, 30, 40], 1, 3) gives [20, 30]map(x * 1.2, x, [£10, £25]) gives [£12.00, £30.00]filter(x > 10, x, [4, 12, 18]) gives [12, 18]sum (also total), product, average (also mean and avg), median, min, max,
count, length, variance and stddev (also stdev) work on a list, and several accept
separate arguments too. There’s no percentile function. sum,
summation and product with four arguments add or multiply an expression while a counter
runs from lo to hi. reverse and unique also take a list. See
Lists and statistics for positions in slice, sample and
population statistics, and more.
Vectors, matrices and calculus
dot([1, 2, 3], [4, 5, 6]) gives 32det([[2, 1], [1, 3]]) gives 5solve_system([[1, 1], [1, -1]], [10, 2]) gives [6, 4]solve(x * 1.2 = 60, x, 0, 100) gives 50differentiate(x^2, x, 3) gives 6integrate(x^2, x, 0, 3) gives 9solve_system([[1, 1], [1, -1]], [10, 2]) finds two numbers that add up to 10 and differ by
2. solve(x * 1.2 = 60, x, 0, 100) finds the price before 20% VAT that comes to 60, searching
between 0 and 100. For cross, identity, shape, transpose, inverse, trace, rank,
eigenvalues, qr, lu and svd, see Vectors and matrices. For
derivatives as formulas and the limits of the solver and integrator, see
Summation, equation solving and calculus and
Advanced mathematics.
Complex numbers
abs(3 + 4i) gives 5complex(3, 4) gives 3 + 4iconj(3 + 4i) gives 3 - 4ireal(3 + 4i) gives 3imag(3 + 4i) gives 4arg(z) gives the angle of a complex number in radians. See
Complex numbers.
Dates and vehicles
easter(2030) gives April 21, 2030tyre_speed(205, 55, 16, 1000 rpm) in km/h gives 119.1103438682 km/heaster(year) gives Western Easter Sunday for a year, the same date as the phrase
Easter 2030. Count days from it directly, as in easter(2030) + 1 day. See Dates. tyre_speed takes the tyre width in millimetres, the aspect ratio
as a percentage, the rim size in inches and the wheel’s rotation speed; see
Cooking, sound, screens and mechanics.