Mathematical operators

For the sake of simplicity, the Zahl, Byte and Kommazahl types are grouped together as numeric in this article.

To make finding a specific operator easier for readers who already know a programming language, the C operator is included in this and later tables.

Unary operators

FunctionUsageC equivalentType of operandreturn typeExampleResult
NOT gatelogisch nicht a~aZahl, ByteZahl, Bytelogisch nicht 1-2
List/Text element countdie Länge von a-Liste, TextZahlDie Länge von "Hello"5
Byte sizedie Größe von einem/einer <type name>sizeof(a)type nameZahlDie Größe von einer Zahl8
Default valueder Standardwert von einem/einer <type name>-type namematching the type nameDer Standardwert von einer Zahl0
Negation-a-anumericZahl, Kommazahl-(2 plus 3)-5
Absolute valueder Betrag von aabs(a)numericnumericDer Betrag von -55

Binary operators

FunctionUsageC equivalentType of 1st operandType of 2nd operandreturn typeExampleResult
Additiona plus ba + bnumericnumericnumeric1 plus 12
Subtractiona minus ba - bnumericnumericnumeric1 minus 2-1
Multiplicationa mal ba * bnumericnumericnumeric5 mal 315
Divisiona durch ba / bnumericnumericKommazahl6 durch 23,0
Remaindera modulo ba % bZahl, ByteZahl, ByteZahl, Byte16 modulo 124
Exponentiationa hoch bpow(a, b)numericnumericKommazahl2 hoch 8256,0
Rootdie a. Wurzel von bpow(b, 1/a)numericnumericKommazahldie 2. Wurzel von 93,0
Logarithmder Logarithmus von b zur Basis alog10(b) / log10(a)numericnumericKommazahlder Logarithmus von 100 zur Basis 102,0
Left bit shifta um b Bit nach links verschobena << bZahl, ByteZahl, ByteZahl, Byte7 um 3 Bit nach links verschoben56
Right bit shifta um b Bit nach rechts verschobena >> bZahl, ByteZahl, ByteZahl, Byte70 um 2 Bit nach rechts verschoben17
AND gatea logisch und ba&bZahl, ByteZahl, ByteZahl, Byte5 logisch und 20
OR gatea logisch oder ba| bZahl, ByteZahl, ByteZahl, Byte5 logisch oder 27
XOR gatea logisch kontra ba^bZahl, ByteZahl, ByteZahl, Byte8 logisch kontra 513

Boolean operators

With the help of boolean operators, complex conditions can be expressed and combined, and used for example in branches or loops.

OperatorDescriptionC equivalentExampleResult
undTrue if both arguments are true.true && falsewahr und wahr
wahr und falsch
falsch und wahr
falsch und falsch
wahr
falsch
falsch
falsch
oderTrue if either argument is true.true || falsewahr oder wahr
wahr oder falsch
falsch oder wahr
falsch oder falsch
wahr
wahr
wahr
falsch
entweder ..., oderTrue if only one of the arguments is true.true != falseentweder wahr, oder wahr
entweder wahr, oder falsch
entweder falsch, oder wahr
entweder falsch, oder falsch
falsch
wahr
wahr
falsch
nichtThe value of the argument is reversed.!truenicht wahr
nicht falsch
falsch
wahr

Comparison operators

OperatorDescriptionC equivalentExampleResult
gleichTrue if both arguments have the same value.1 == 11 gleich 1 ist
1 gleich 2 ist
wahr
falsch
ungleichTrue if the two arguments have different values.1 != 11 ungleich 1 ist
1 ungleich 2 ist
falsch
wahr
kleiner alsTrue if the left argument has a smaller value than the right.5 < 105 kleiner als 10 ist
30 kleiner als 15 ist
wahr
falsch
größer alsTrue if the left argument has a greater value than the right.7 > 37 größer als 3 ist
5 größer als 8 ist
wahr
falsch
kleiner als, oderTrue if the left argument is less than or the same value as the right.5 <= 105 kleiner als, oder 10 ist
30 kleiner als, oder 15 ist
5 kleiner als, oder 5 ist
wahr
falsch
wahr
größer als, oderTrue if the left argument is greater than or the same value as the right.7 >= 37 größer als, oder 3 ist
5 größer als, oder 8 ist
5 größer als, oder 5 ist
wahr
falsch
wahr
zwischenTrue if the left argument lies between the two right ones.(4 < 5 && 4 > 3)4 zwischen 3 und 5 ist
6 zwischen 3 und 5 ist
wahr
falsch

Comparison operators all have an “ist” at the end to conform to the grammar in any context. If that leads to several “ist"s in a row, a single one is enough:

2 größer als 2 ist gleich 4 größer als 4 ist ist. [ugly]
2 größer als 2 ist gleich 4 größer als 4 ist. [nice]

Type check

For values of type Variable you can check which type the stored value currently has. To do this, you write ein, eine, kein or keine and the type name. The article must match the type.

OperatorDescriptionExampleResult
ein(e) ... istTrue if the value has this type.(5 als Variable) eine Zahl ist
(5 als Variable) ein Text ist
wahr
falsch
kein(e) ... istTrue if the value does not have this type.(5 als Variable) keine Zahl ist
(5 als Variable) kein Text ist
falsch
wahr

List and text operators

FunctionUsageC equivalentType of 1st operandType of 2nd operandType of 3rd operandreturn typeExampleResult
Concatenationa verkettet mit b-Text/Liste/BuchstabeText/Liste/Buchstabe-Text/Liste"Hello" verkettet mit " World""Hello World"
Indexinga an der Stelle ba[b]Text/ListeZahl, Byte-Buchstabe/element type"Hello" an der Stelle 1‘H’
Rangea im Bereich von b bis c-Text/ListeZahl, ByteZahl, ByteText/Liste"Hello World" im Bereich von 1 bis 5“Hello”
... ab dem ...a ab dem b. Element-Text/ListeZahl, Byte-Text/Liste"Hello World" ab dem 7. Element“World”
... bis zum ...a bis zum b. Element-Text/ListeZahl, Byte-Text/Liste"Hello World" bis zum 5. Element“Hello”

Remarks

The operand types of a concatenation cannot be combined arbitrarily.

With indexing and im Bereich von ... bis the indices are always inclusive and start at 1. So a list from 1 to 5 contains the first, the fifth and all elements in between. A list at position 0 would be a runtime error, as would an index that exceeds the length of the list.

With im Bereich von ... bis there are no runtime errors if indices are too small or too large. The indices are automatically brought into the range [1, length of the list/text]. If the 2nd index is then smaller than the 1st, there is a runtime error. So if both indices are greater than the length of the list, the result is the last element of the list.

... ab dem ... and ... bis zum ... are just short forms of im Bereich von ... bis with the second or first operand set to the length of the list or 1 respectively.

Examples

Die Zahlen Liste z ist eine Liste, die aus 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 besteht.
Schreibe (z an der Stelle 5). [writes 5 to the console]
Schreibe (z im Bereich von 3 bis 7). [writes "3, 4, 5, 6, 7" to the console]
Schreibe (z im Bereich von 3 bis 7 verkettet mit z im Bereich von 1 bis 4). [writes "3, 4, 5, 6, 7, 1, 2, 3, 4" to the console]

Schreibe ("Hello" verkettet mit 'Ü'). [writes "HelloÜ" to the console]
Schreibe ("Hello" im Bereich von 1 bis 3 verkettet mit 'ö'). [writes "Helö" to the console]
Schreibe ('b' verkettet mit 'a'). [writes "b, a" to the console]

Falls

The Falls operator corresponds to the ternary operator (a ? b : c) in other languages. Its parameters are a Wahrheitswert and 2 expressions of any (but the same) type:

Der Text t ist "2 > 3", falls 2 größer als 3 ist, ansonsten "2" verkettet mit " < " verkettet mit "3".

Operator prioritization

Different operators are prioritized differently. This means that some operators take precedence over others when evaluated. For example, in mathematics, multiplication and division take precedence over addition and subtraction, and powers in turn take precedence over multiplication and division. With the mathematical operators, DDP largely adheres to the mathematical order. Here is a table with all operators and their prioritization (high priority operators at the top):

RankOperator
1Function call
2Literals, constants
3Parentheses
4Type conversions
5Field access on combinations
6Indexing
7im Bereich von ... bis, ab dem ... Element, bis zum ... Element
8Exponentiation, root, logarithm
9Negation
10Absolute value, size, length, default value, logical/boolean NOT
11Multiplication, division, remainder
12Addition, subtraction, concatenation
13Bit shift
14Comparison (kleiner, größer, etc.)
15Equality (gleich and ungleich), type check (ein ... ist)
16Logical AND gate
17Logical XOR gate
18Logical OR gate
19Boolean AND
20Boolean OR
21entweder ..., oder
22Falls

Operator prioritization example

Die Zahlen Liste z ist eine Liste, die aus 1, 2, 3 besteht.
Schreibe (z an der Stelle 2 hoch 3). [writes 8 to the console]

Here you can see the prioritization of the an der Stelle operator over the hoch operator. First z an der Stelle 2 is evaluated and then the result is raised to the power of 3. If the hoch operator took precedence over an der Stelle, 2 hoch 3 would be calculated first and then the element at position 8 of z would be used, which would result in a runtime error, since z only has 3 elements.

Operator overloading

Operators can also be overloaded to execute functions instead of operators while still profiting from operator prioritization. More about this in the article Operator overloading.