Arithmetic Operators
Cangjie provides standard arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), remainder (%), and exponentiation (**). These operators behave mostly as you'd expect from other languages, with some details to note.
Integer division rounds the result toward zero. For example, 7 / 3 yields 2, while -7 / 3 yields -2. The remainder operation a % b is defined as a - b * (a / b), so the result has the same sign as the dividend. The unary minus - can negate a numeric value.
Operators have fixed precedence: unary minus has the highest precedence, followed by **, then *, /, %, and finally +, -. Use parentheses to change the order of operations and make your code's intent clearer.
The code on the right demonstrates various arithmetic operators. Try modifying the operands in expressions or adding parentheses, predict the results, then run to verify.
Run to see the output, and try modifying the code to understand operator behavior.