Expressions

Most text fields in Skala can accept expressions as input.

Typing 1 + 2 into the width field of a rectangle results in a width of 3. Typing 20 / 2 results in a width of 10. Numbers can be placed directly next to constants and brackets to multiply them. 2gu is the same as 2 * gu, and 2(a + 1) is the same as 2 * (a + 1).

If an expression results in infinity or not a number (dividing by zero, for example), Skala will let you know and it won’t be used.

Persistent expressions #

If you’d like to keep the expression so it can be edited later, place := at the start. Typing :=20 / 2 still results in 10, but it lets you alter it to be :=20 / 4 some time in the future. If you’ve used calc() in CSS, this is very similar.

Typing := into a field opens a larger expression editor, with a button that inserts constants at the cursor. Press return to accept the expression, or tab to accept it and move to the next field.

Please note most text fields allow persistent expressions, but some do not. The document size fields and the fields in the transform properties tab calculate the result once, and the expression isn’t kept. This is to stop Skala exploding if you type :=width + 1 into the document width field. Font properties, like font size, only accept numbers.

Constants #

Number, boolean, unit, and vector constants can also be used in expressions, as can Skala’s built-in constants, like w, h, and pi. Please refer to the constants page for more information.

Arithmetic operators #

OperatorDefinition
+Addition between x and y. Example: x + y.
-Subtraction between x and y. Example: x - y.
*Multiplication between x and y. Example: x * y.
/Division between x and y. Example: x / y.
%Modulus of x with respect to y. Example: x % y.
^x to the power of y. Example: x ^ y.

Equalities and inequalities #

OperatorDefinition
== or =True only if x is strictly equal to y. Example: x == y.
<> or !=True only if x does not equal y. Example: x <> y or x != y.
<True only if x is less than y. Example: x < y.
<=True only if x is less than or equal to y. Example: x <= y.
>True only if x is greater than y. Example: x > y.
>=True only if x greater than or equal to y. Example: x >= y.

Boolean operations #

Comparisons and boolean operations return 1 for true and 0 for false. Any value other than zero counts as true.

OperatorDefinition
andLogical AND, true only if x and y are both true. Example: x and y.
mandMulti-input logical AND, true only if all inputs are true. Left to right short-circuiting of expressions. Example: mand(x > y, z < w, u or v, w and x).
morMulti-input logical OR, true if at least one of the inputs are true. Left to right short-circuiting of expressions. Example: mor(x > y, z < w, u or v, w and x).
nandLogical NAND, true only if either x or y is false. Example: x nand y.
norLogical NOR, true only if the result of x or y is false. Example: x nor y.
notLogical NOT, Negate the logical sense of the input. Example: not(x and y) == x nand y.
orLogical OR, true if either x or y is true. Example: x or y.
xorLogical XOR, true only if the logical states of x and y differ. Example: x xor y.
xnorLogical XNOR, true if the biconditional of x and y is satisfied. Example: x xnor y.
&Similar to AND but with left to right expression short circuiting optimisation. Example: (x & y) == (y and x).
|Similar to OR but with left to right expression short circuiting optimisation. Example: (x | y) == (y or x).

General purpose functions #

OperatorDefinition
absAbsolute value of x. Example: abs(x).
avgAverage of all the inputs. Example: avg(x, y, z, w, u, v) == (x + y + z + w + u + v) / 6.
ceilSmallest integer that is greater than or equal to x. Example: ceil(x).
clampClamp x in range between r0 and r1, where r0 < r1. Example: clamp(x, r0, r1).
clamp01Clamp x in range between 0 and 1. Example: clamp01(x).
equalEquality test between x and y using normalised epsilon. Example: equal(x, y).
erfError function of x. Example: erf(x).
erfcComplementary error function of x. Example: erfc(x).
expe to the power of x. Example: exp(x).
expm1e to the power of x minus 1, where x is very small. Example: expm1(x).
floorLargest integer that is less than or equal to x. Example: floor(x).
fracFractional portion of x. Example: frac(x).
hypotHypotenuse of x and y. Example: hypot(x, y) == sqrt(x * x + y * y).
iclampInverse-clamp x outside of the range r0 and r1, where r0 < r1. If x is within the range it will snap to a bound. Example: iclamp(x, r0, r1).
ifReturns y if x is true, otherwise returns z. Example: if(x, y, z).
inrangeIn-range returns 1 (true) when x is within the range r0 and r1, where r0 < r1. Example: inrange(x, r0, r1).
logNatural logarithm of x. Example: log(x).
log10Base 10 logarithm of x. Example: log10(x).
log1pNatural logarithm of 1 + x, where x is very small. Example: log1p(x).
log2Base 2 logarithm of x. Example: log2(x).
lognBase N logarithm of x, where n is a positive integer. Example: logn(x, 8).
maxLargest value of all the inputs. Example: max(x, y, z, w, u, v).
minSmallest value of all the inputs. Example: min(x, y, z, w, u).
modModulus of x with respect to y. Example: mod(x, y) == x % y.
mulProduct of all the inputs. Example: mul(x, y, z, w, u, v, t) == (x * y * z * w * u * v * t).
ncdfNormal cumulative distribution function. Example: ncdf(x).
not_equalNot-equal test between x and y using normalised epsilon. Example: not_equal(x, y).
powx to the power of y. Example: pow(x, y) == x ^ y.
rootNth root of x, where n is a positive integer. Example: root(x, 3) == x ^ (1 / 3).
roundRound x to the nearest integer. Example: round(x).
roundnRound x to n decimal places, where n > 0 and is an integer. Example: roundn(1.2345678, 4) == 1.2346.
sgnSign of x, -1 where x < 0, +1 where x > 0, else zero. Example: sgn(x).
sqrtSquare root of x, where x >= 0. Example: sqrt(x).
sumSum of all the inputs. Example: sum(x, y, z, w, u, v, t) == (x + y + z + w + u + v + t).
truncInteger portion of x. Example: trunc(x).

Trigonometry functions #

Trigonometry functions work in radians, but Skala’s rotation fields use degrees. Use deg2rad and rad2deg to convert between them — :=sin(deg2rad(30)) returns 0.5.

OperatorDefinition
acosArc cosine of x expressed in radians. Interval [-1, +1]. Example: acos(x).
acoshInverse hyperbolic cosine of x expressed in radians. Example: acosh(x).
asinArc sine of x expressed in radians. Interval [-1, +1]. Example: asin(x).
asinhInverse hyperbolic sine of x expressed in radians. Example: asinh(x).
atanArc tangent of x expressed in radians. Example: atan(x).
atan2Arc tangent of (x / y) expressed in radians. Interval [-pi, +pi]. Example: atan2(x, y).
atanhInverse hyperbolic tangent of x expressed in radians. Example: atanh(x).
cosCosine of x. Example: cos(x).
coshHyperbolic cosine of x. Example: cosh(x).
cotCotangent of x. Example: cot(x).
cscCosecant of x. Example: csc(x).
secSecant of x. Example: sec(x).
sinSine of x. Example: sin(x).
sincSine cardinal of x. Example: sinc(x).
sinhHyperbolic sine of x. Example: sinh(x).
tanTangent of x. Example: tan(x).
tanhHyperbolic tangent of x. Example: tanh(x).
deg2radConvert x from degrees to radians. Example: deg2rad(x).
deg2gradConvert x from degrees to gradians. Example: deg2grad(x).
rad2degConvert x from radians to degrees. Example: rad2deg(x).
grad2degConvert x from gradians to degrees. Example: grad2deg(x).

Blending and interpolation #

The mix functions blend from a to b as t goes from 0 to 1. The step functions do the opposite, returning a value between 0 and 1 based on where x sits between a and b. Values of x outside that range are clamped.

OperatorDefinition
mixnearestNearest interpolation from a to b, controlled by t (0 to 1 range). Example: mixnearest(a, b, t).
mixlinearLinear interpolation from a to b, controlled by t (0 to 1 range). Example: mixlinear(a, b, t).
mixcosineCosine interpolation from a to b, controlled by t (0 to 1 range). Example: mixcosine(a, b, t).
mixhermite3Hermite3 interpolation from a to b, controlled by t (0 to 1 range). Example: mixhermite3(a, b, t).
mixhermite5Hermite5 interpolation from a to b, controlled by t (0 to 1 range). Example: mixhermite5(a, b, t).
mixhermite7Hermite7 interpolation from a to b, controlled by t (0 to 1 range). Example: mixhermite7(a, b, t).
stepnearestNearest interpolation between 0 and 1 when a < x < b. Example: stepnearest(a, b, x).
steplinearLinear interpolation between 0 and 1 when a < x < b. Example: steplinear(a, b, x).
stepcosineCosine interpolation between 0 and 1 when a < x < b. Example: stepcosine(a, b, x).
stephermite3Hermite3 interpolation between 0 and 1 when a < x < b. Example: stephermite3(a, b, x).
stephermite5Hermite5 interpolation between 0 and 1 when a < x < b. Example: stephermite5(a, b, x).
stephermite7Hermite7 interpolation between 0 and 1 when a < x < b. Example: stephermite7(a, b, x).

Ternary operations #

Ternary operations can be used for conditional expressions. The ternary a ? b : c checks a and returns b if true, or c if false. For example, with a boolean constant called compact, :=compact ? 8 : 16 returns 8 when compact is true, and 16 when it is false. The if function does the same thing: :=if(compact, 8, 16).