]> git.xonotic.org Git - xonotic/gmqcc.git/blob - tests/operators.qc
Fixing operator precedence of suffices
[xonotic/gmqcc.git] / tests / operators.qc
1 void   print(...)   = #1;
2 string ftos (float) = #2;
3 entity() spawn = #3;
4
5 .float mem;
6
7 void main() {
8         float a;
9
10         // regular binary+store
11         a = 5;
12         print(ftos(a += 1), " = ");
13         print(ftos(a), "\n");
14
15         entity e = spawn();
16     e.mem = 10;
17         print(ftos(e.mem += 1), " = ");
18         print(ftos(e.mem), "\n");
19
20     // prefix
21         print(ftos(++a), " = ");
22         print(ftos(a), "\n");
23         print(ftos(--a), " = ");
24         print(ftos(a), "\n");
25         print(ftos(++e.mem), " = ");
26         print(ftos(e.mem), "\n");
27
28         // suffix
29         print(ftos(a++), " = ");
30         print(ftos(a-1), "\n");
31         // the CLANG way:
32         a = 3;
33         print(ftos((a++ + a) + a), " = 11\n");
34
35         // check if minus translates
36         print(ftos(a--), "\n");
37         print(ftos(--a), "\n");
38
39         // postfix on members
40         print(ftos(e.mem--), " = ");
41         print(ftos(e.mem+1), "\n");
42 }