Operations
Math, comparison, and logic operators apply the standard operations in Spectre. The following notes clarify some implementation details:
- The operators and, or, and not work only with Boolean or null values.
- Among numeric types, addition (+), subtraction (-), and the comparison operators all implicitly promote values to match data type. For example:
- integer + fixed100 returns fixed100
- fixed100 + double returns double
- integer + double returns double
- Multiplication (*) of integer and numeric type X returns type X; any other mix of numeric types returns a double. For example:
- integer * fixed100 returns fixed100
- integer * double returns double
- fixed100 * double returns double
- Division (/), except for division by zero, returns a double.
- Division by zero returns an unknown.
- On doubles, comparison operators have the standard accuracy issues.
- The + operator can concatenate two strings, but does not promote other types to string.
- Comparison operators, as well as addition and subtraction, work on dates.
Order of Operations
Operations in an expression are performed in the following order:
- math: *, /
- math: +, -
- comparison: <, <=, >, >=
- comparison: =, !=
- logic: not, and, or
See also: