Operators

Unlike other spreadsheets, the operators in TEAPOT check the type of the values they are applied to, which means trying to add a string to a floating point number will result in an type error. Operators on locations in the spreadsheet, which are just triples of integers, generally operate following typical rules for vectors, with particular notes below. The following operators are available, listed in ascending precedence:

x and y
evaluates to the logical conjunction of values x and y. Note that this evaluation short-circuits: if x is false, then y is never evaluated, and so does not affect the value even if it is an error, for example. In determining the value, the boolean conversions of x and y are used (see the description of the bool() function below), but the actual value returned is either that of x or y, namely, x if it corresponds to a boolean false value or y otherwise.
x or y
evaluates to the logical disjunction of boolean values x and y. As with and, this evaluation short-circuits if x is true. Also in similar fashion, the value is x if it corresponds to a boolean true value and y otherwise.
x<y
evaluates to Boolean true if x is less than y. If x or y are empty, they are considered to be 0 if the other is an integer number, 0.0 if it is a floating point number and the empty string if it is a string. On locations, x<y if every component of x is less than or equal to the corresponding component of y and at least one is strictly less.
x<=y
evaluates to true if x is less than or equal to y. For locations, this must hold for every component.
x>=y
evaluates to true if x is greater than or equal to y. For locations, this must hold for every component.
x>y
evaluates to true if x is greater than y. As with <, for locations, every component must be greater than or equal, and at least one must be strictly greater.
x==y
evaluates to true if x is equal to y.
x~=y
evaluates to true if the floating point value x is almost equal to the floating point value y. Almost equal means that the numbers are equal or neighbor each other in the floating point representation being used. It is an error to use this comparison with any type but float.
x!=y
evaluates to 1 if x is not equal to y.
Note:
a string of consecutive relational operators is interpreted as the conjunction of each consecutive (overlapping) pair. Thus 2 <= y() <= 10 will evaluate to true precisely in rows 2 through 10, inclusive (it is shorthand for 2 <= y() and y() <= 10). Similarly @(cell1) == @(cell2) == @(cell3) will return true exactly when all three cells have the same value.
x+y
evaluates to the sum if x and y are numbers. If x and y are strings, the result is the concatenated string. If they are locations, this operates componentwise. If they are styles, it means to take any unset components of the left-hand style and fill them in with values from the right-hand style (ignoring the right-hand components that are already set in the left-hand style).
x-y
evaluates to the difference if x and y are numbers. If they are locations, this operates componentwise.
x*y
evaluates to the product if x and y are numbers. You can multiply a location by an integer, or take the dot product of the coordinates of two locations (although the use case for that is unclear).
x/y
evaluates to the quotient if x and y are numbers. You can divide a location by an integer.
x%y
evaluates to the remainder of the division if x and y are numbers. You can mod a location by an integer, or operate on two locations, in which case the mod operation applies componentwise.
-x
evaluates to -x if x is a number or location, or the negation of x if x is Boolean. If x is empty, the result will be empty, too.
x^y
evaluates to x to the power of y.
(expression)
evaluates to the expression.
function(argument,...)
evaluates to the value of the function applied to the values resulting from evaluating the argument expressions. Note that if no arguments are being supplied, the parentheses are optional. Hence, for example, you can use “e” by itself, like a reserved constant whose value is the usual mathematical “e,” the base of natural logarithms.