– title: “Operators” author: “Pierre Laplante laplante@plcb.ca” date: “2023-05-05” version: “1.0.0” section: “1g”
The following operators exist in goweb:
+ : if both operands are strings, they will be concatenated.-*/%!<(MISSING)/code> (modulo)** (power) — always returns a float.- (unary minus)( ... ) — parentheses to enforce operator precedence.The order of operators in goweb is:
+, -*, /%!<(MISSING)/code>, **-For example:
1 + 2 * 3 ** 4
Output:
163
Parentheses can be used to explicitly enforce operator precedence.
For the modulo operator %!<(MISSING)/code>, if one operand is a float, it returns the floating-point remainder of x / y.
The magnitude of the result is less than y and its sign matches that of x.
res={{
5 %!;(MISSING)
5.2 %!;(MISSING)
}}.
Output:
res=1
0.7999999999999998
res={{
0 ** 0; "\n";
2 ** 5; "\n";
2 ** -5; "\n";
}}.
Output:
1
32
0.03125
res={{
5 + 7; "\n";
5 + 7.2; "\n";
5 + "7.3"; "\n";
}}.
Output:
12
12.2
12.3
res={{
5 - 7; "\n";
5 - 7.2; "\n";
5 - "7.3"; "\n";
}}.
Output:
-2
-2.2
-2.3
res={{
5 * 7; "\n";
5 * 7.2; "\n";
5 * "7.3"; "\n";
}}.
Output:
35
36
36.5
res={{
14 / 7; "\n";
5 / 7.2; "\n";
5 / "7.3"; "\n";
}}.
Output:
2
0.6944444444444444
0.684931506849315
res={{
7.3 / 0.0; "\n";
}}.
Output:
*division by zero.*