Operators
Equals recognizes all common mathematical operators:
Operator | Function | Description |
---|---|---|
Standard Operators | ||
+ |
add |
addition and unary positive |
- or − |
subtract and negate |
subtraction and negation |
* or × |
multiply |
multiplication |
/ or ÷ |
divide |
division |
% |
mod or percent |
modulus or a percentage of a value |
! |
factorial |
factorial |
** |
pow |
exponentiation |
º or ° |
dtor |
converts the value to radians |
Bitwise Operators | ||
& |
and |
bitwise and |
| |
or |
bitwise or |
^ |
xor |
bitwise xor |
~ |
not |
bitwise not |
<< |
lshift |
bitwise left shift |
>> |
rshift |
bitwise right shift |
Comparison Operators | ||
== or = |
l_eq |
equal |
!= |
l_neq |
not equal |
< |
l_lt |
less than |
> |
l_gt |
greater than |
<= or =< or ≤ or ≮ |
l_ltoe |
less than or equal |
>= or => or ≥ or ≯ |
l_gtoe |
greater than or equal |
Logical Operators | ||
&& or ∧ |
l_and |
logical and |
|| or ∨ |
l_or |
logical or |
! or ¬ |
l_not |
logical not |
Considerations
The Degree Operator
The degree operator (°
) is interesting. Because all of the trigonometric functions require their parameters to be passed in radians, the degree operator will convert its operand into radians. Thus, 45°
is equivalent to dtor(45)
.
The %
Sign
The %
sign is usually interpreted as a percentage. Example:
50 + 10% = 55
By default, %
is shorthand for /100
. In other words, 42%
becomes 42/100
, or 0.42
.
However, if the %
term is the right hand side of either a subtraction or addition operation (such as in 50 + 10%
), then the percent is evaluated as a percentage of the left-hand side (i.e. “50 plus 10% of 50“).
On many computer systems the %
sign is used as the modulo operator. You can always calculate the modulus this way:
mod(10, 3) = 1
However, if you enable “Interpret percent sign (%) as modulo” in the preferences, then:
10 % 3
… evaluates to 1
(the remainder after 10 is divided by 3).
In this case, you can still request a percentage by using the function name directly:
(10 % 3) + percent(50) = 1.5
Logical Values
The comparison and logical operators both return a boolean value. During evaluation, that boolean value is strictly interpreted as either 0
(false) or 1
(true). For example, 41 + (1 && 1)
is literally 41 + true
, but is evaluated as 42
.
On the same note, the operands to the logical operators are also interpreted as booleans.
Factorial and Logical Not
Differentiating between factorial (!
) and a logical not (!
) is difficult. A !
is interpreted as a logical not if:
- it is the first token
- it is preceded by a binary operator
- it is preceded by a right associative unary operator
Otherwise it is treated as a factorial. A ¬
token is always treated as a logical not (for obvious reasons).
Parentheses and Associativity
For simplification in dealing with implicit multiplication, an opening parenthesis is considered a right associative unary operator, and a closing parenthesis is considered a left associative unary operator.