ColdC provides several operators for performing arithmetic operations. These operators apply primarily to integers and floats, but some of them may be used with non-integer data for easier formatting and manipulation. If any arithmetic operator is used with inappropriate data the error ~type is thrown.
If both sides of a binary arithmetic expression are integers, the result will always be an integer, even if the result would have floating precision. If one side of the expression is a float, the result will always be a float. For instance, 3 / 2 (both integers) would result in 1, whereas 3 / 2.0 would result in 1.500000.
The arithmetic operators are:
+ ignored (unary) - negate (unary) + addition (binary) - subtraction (binary) * multiply (binary) / divide (binary) % modulo (binary) ++ increment (unary) -- decrement (unary)
The unary - operator negates the numeric value (reverses its positive/negative value). The unary + operator has no effect on its argument, and is provided simply for completeness. The binary operators + and - add and subtract their arguments.
The binary multiplication operator * multiplies the left argument by the right argument. The binary division operator / divides the left argument by the right argument, returning the whole result. The binary modulus operator % divides the left argument by the right argument and returns the remainder result.
The unary Increment and Decrement operators serve a dual function, and are explained further in their own section.
Operator Precedence | Index Operators | Arithmetic Operators | Assignments | Logical Operators | Conditional | List Splice Operator