Arithmetic Operators
Cangjie provides standard arithmetic operators: unary negation (-), addition (+), subtraction (-), multiplication (*), division (/), modulo (%), and exponentiation (**). These operators work on integer and floating-point types, though modulo only supports integer types.
For binary operators, both operands must have the same type. Integer division rounds the result toward zero, so 7 / 3 results in 2, and -7 / 3 results in -2. The modulo operation is defined as a % b = a - b * (a / b), so the result's sign matches the dividend.
The exponentiation operator ** calculates powers. When the left operand is Int64, the right operand must be UInt64; when the left operand is Float64, the right operand can be Int64 or Float64. Additionally, the addition operator can be used for string concatenation.
The code on the right demonstrates various arithmetic operations. You can modify operands to observe the results of negative division and modulo, as well as the precedence rules of exponentiation combined with parentheses.