Maths

These glyphs represent some basic mathematical operations. While not needed for all enchantments, more complex spellforms do rely on these for their correct functioning. While often limited to number species, some glyphs in this section also apply to vector species.

Minus

num|vecnum|vec
Returns the additive inverse of the head, equivalent to multiplying by -1.

For vectors, this operation is applied to each component (as per multiplication by -1).

Add

num|vec, num|vecnum|vec
Pops two number or vector species, adds them, and pushes the result. Behaviour changes depending on popped species.

$(li)Two numbers: num, num → num
Standard addition.

$(li)Two vectors: vec, vec → vec
Standard vector addition.

$(li)Vec & Num: vec, num → vec
Regardless of order, adds the number to each of the vector’s components.

Sub

num|vec, num|vecnum|vec
Subtracts the species at the head from the species below it. Behaviour changes depending on popped species.

$(li)Two numbers: num, num → num
Subtract head from number below it.

$(li)Two vectors: vec, vec → vec
Subtract head from vector below it.

$(li)Vec & Num: vec, num → vec
Subtract number from each of the vector’s components.

Mult

num|vec, num|vecnum|vec
Multiplies the top two species. Behaviour changes depending on popped species.

$(li)Two numbers: num, num → num
Standard multiplication.

$(li)Two vectors: vec, vec → vec
Take the dot product of both vectors.

$(li)Vec & Num: vec, num → vec
Order-insensitive, scale the vector by the number.

Div

num|vec, num|vecnum|vec
Divides the species below the head by the species at the head. Behaviour changes depending on popped species. Do not divide by 0.

$(li)Two Nums: num1, num2 → num
Returns num1/num2, where num2 was at the head.

$(li)Two Vecs: vec1, vec2 → vec
Takes the cross product vec1 x vec 2, where vec2 was at the head.

$(li)Vec & Num: vec, num → vec
Scales the vector by the reciprocal of the number.
(eg. A, 4 → A scaled by 1/4)

Clamp

num, num, numnum
Uses the head and the number below it to adjust the number at the third place on the capsum.

Consider the case $(o)x, $(o)a, $(o)b:

$(li)If $(o)x is within [$(o)a, $(o)b], then the glyph returns $(o)x.

$(li)If $(o)x < $(o)a, returns $(o)a.

$(li)If $(o)x > $(o)b, returns $(o)b.

Lerp

num|vec, num|vec, num|vec
num|vec
Moves from the third value to the second value by the amount specified by the head.

Standard equation:
$(o)a, $(o)b, $(o)t → $(o)a + $(o)t x ($(o)b - $(o)a)

$(li)For numbers, apply the standard equation.

$(li)For cases where $(o)a & $(o)b are vectors, applies the standard equation using vector operations.

$(li)For all vectors, applies the standard equation per axis (on a1, b1 and t1, so on and so forth), returning the resulting vector.

Modulo

num|vec, numnum|vec
Takes the modulus of the species below the head with respect to the head (the remainder from division).

If the number below the head is a vector, the modulus of each component with respect to the number is taken.

Exp

num, numnum
Exponentiates the number below the head by the head.

eg. $(o)a, $(o)b → $(o)a^$(o)b

Floor

numnum
Pops a number, rounds it down if possible, and pushes the result onto the capsum.

Ceil

numnum
Pops a number, rounds it up if possible, and pushes the result onto the capsum.

Round

numnum
Pops a number, rounds it according to the standard method, and pushes the result onto the capsum.

Abs

num|vecnum|vec
Pops the top species and returns the absolute value.

For vectors, the glyph takes the absolute value of each component and returns the resulting vector.

Sign

numnum
Pops a number, and pushes onto the capsum either -1, 0 or 1 depending on whether the popped number was negative, zero or positive.

Min

num, numnum
Pops two numbers and pushes only the smallest of the two onto the capsum.

Max

num, numnum
Pops two numbers and pushes only the largest of the two onto the capsum.