8. Formulas

Formulas (generic)

After we know the data types, number formats, strings, operators and leading signs we know (nearly) all what's required to use formulas in DestinyScript. The last missing parts are parentheses and priorities of the operators.

Priorities

Description

According to the arithmetical algebra it is necessary: point operations (multiplication, division) will be executed before stroke operations (addition, subtraction). And according to the boolean algebra is necessary: AND will be executed before OR. A combination of these laws forms the priorities of the operators. If a formula contain multiple partial calculations then they are calculated in the order that result from their priorities. If more than one partial calculation have the same priority then they are calculated from left to right. Leading signs (plus, minus, NOT) have always the highest priority.
x = 15 + 3 * 9
x = 15 + 21
x = 36
 
In this example the point operation (3 * 9) has been calculated before the stroke operation (which whould be 15 + 3) was calculated.

List of the priorities

In the following list applies: the higher the number the higher the priority.
OperatorPriority
AND operation4
OR operation3
XOR operation3
Modulo2
Division2
Multiplication2
Subtraction1
Addition1

Example

The following example uses the signs of DestinyScript but it is just a calcuation example - it is not a valid DestinyScript.
x = 1000 + 2 - 10 * 3 / 15 % 8 | 3 ^ 7 & 6
x = 1002 - 10 * 3 / 15 % 8 | 3 ^ 7 & 6
x = 1002 - 30 / 15 % 8 | 3 ^ 7 & 6
x = 1002 - 2 % 8 | 3 ^ 7 & 6
x = 1002 - 2 % 11 ^ 7 & 6
x = 1002 - 2 % 11 ^ 6
x = 1002 - 2 % 13
x = 1002 - 2
x = 1000
In this example some lines could have been calculated in a single step, but to make it easier to understand the calculation has been made step-by-step.

Parentheses

Description

If a partial calculation with less priority should be calculated before a partial calculation with high priority then you must put the calculation with less priority in parentheses ( ).

Example

The following example uses the signs of DestinyScript but it is just a calcuation example - it is not a valid DestinyScript.
x = 100 * -(10 + 7)
x = 100 * -17
x = -1700
Information
A sign at the beginning of a pair of parentheses modifies only the result of the calculation in the parentheses.