# Built-in Math Expressions

Adama lets you do math, and that's awesome! It has the typical operations that you would expect, and then some fun twists. So, let's get into it.

## #

Operators*expr* )#

Parentheses: ( You can wrap any expression with parentheses, and parentheses will alter the precedence of evaluation. See operator precedence section for details about operator precedence.

**Sample Code**

**Result**

**Typing:** The resulting type is the type of the sub-expression.

*expr*#

Unary numeric negation: - When you want want to turn a positive into a negative, a negative into a positive, a smile into a frown, a frown upside down, or reflect a value over the y-axis.. This is done with the subtract symbol prefixing any expression.

**Sample Code**

**Result**

**Typing:** The sub-expression type must be an int, long, or double. The resulting type is the type of the sub-expression.

### negation / not / logical compliment: ! *expr*#

Unary boolean Turn false into true, and true into false. This is the power of the unary **Not** operator using the exclamation point **!**. Money back if it doesn't invert those boolean values!

**Sample Code**

**Result**

**Typing:** The sub-expression type must be a bool, and the resulting type is also bool.

*expr* + *expr*#

Addition: You'll need to use addition to count the phat stacks of money you'll earn with a computer science degree.

**Sample Code**

**Result**

**Typing:** The addition operator commonly is used to add two numbers, but it can also be used with strings and lists. The following table summarizes the typing and behavior.

left type | right type | result type | behavior |
---|---|---|---|

int | int | int | integer addition |

double | double | double | floating point addition |

double | int | double | floating point addition |

int | double | double | floating point addition |

long | long | long | integer addition |

long | int | long | integer addition |

int | long | long | integer addition |

string | string | string | concatenation |

int | string | string | concatenation |

long | string | string | concatenation |

double | string | string | concatenation |

bool | string | string | concatenation |

string | int | string | concatenation |

string | long | string | concatenation |

string | double | string | concatenation |

string | bool | string | concatenation |

list<int> | int | list<int> | integer addition on each element |

list<int> | long | list<long> | integer addition on each element |

list<int> | double | list<double> | floating point addition on each element |

list<long> | int | list<int> | integer addition on each element |

list<long> | long | list<long> | integer addition on each element |

list<double> | int | list<double> | floating point addition on each element |

list<double> | double | list<double> | floating point addition on each element |

list<string> | int | list<string> | concatenation on each element |

list<string> | long | list<string> | concatenation on each element |

list<string> | double | list<string> | concatenation on each element |

list<string> | bool | list<string> | concatenation on each element |

*expr* - *expr*#

Subtraction: You'll need the subtract operator to remove taxes from your phat stack of dolla-bills.

**Sample Code**

**Result**

**Typing:**

The subtraction operator commonly is used to subtract a number from another number, but it can also be used with lists. The following table summarizes the typing and behavior.

left type | right type | result type | behavior |
---|---|---|---|

int | int | int | integer subtraction |

int | double | double | floating point subtraction |

double | double | double | floating point subtraction |

double | int | double | floating point subtraction |

long | int | int | integer subtraction |

long | long | long | integer subtraction |

int | long | int | integer subtraction |

list<int> | int | list<int> | integer subtraction on each element |

list<int> | long | list<long> | integer subtraction on each element |

list<int> | double | list<double> | floating point subtraction on each element |

list<long> | int | list<int> | integer subtraction on each element |

list<long> | long | list<long> | integer subtraction on each element |

list<double> | int | list<double> | floating point subtraction on each element |

list<double> | double | list<double> | floating point subtraction on each element |

*expr* * *expr*#

Multiplication: TODO: something pithy about multiplication.

**Sample Code**

**Result**

**Typing:** TODO
| int | int | int | integer subtraction |
| int | double | double | floating point subtraction |
| double | double | double | floating point subtraction |
| double | int | double | floating point subtraction |
| long | int | int | integer subtraction |
| long | long | long | integer subtraction |
| int | long | int | integer subtraction |

*expr* / *expr*#

Division: TODO: something pithy about division.

**Sample Code**

**Result**

**Typing:** TODO

*expr* % *expr*#

Modulus: TODO: something pithy about Modulus and remainders.

**Sample Code**

**Result**

**Typing:** The left and right side must be integral (i.e. int or long), and the result is integral as well. The following table summarizes the logic precisely.

left type | right type | result type |
---|---|---|

int | int | int |

long | int | int |

int | long | int |

long | long | long |

*expr* < *expr*#

Less than: TODO: something pithy

**Sample Code**

**Result**

**Typing:** The left and right must be comparable, and the resulting type is always bool. The following table outlines comparability

left type | right type |
---|---|

int | int |

int | long |

int | double |

long | int |

long | long |

long | double |

double | int |

double | long |

double | double |

string | string |

TODO: do maybes play into this?

*expr* > *expr*#

Greater than: TODO: something pithy

**Sample Code**

**Result**

**Typing:** This has the same typing as <

*expr* <= *expr*#

Less than or equal to: TODO: something pithy

**Sample Code**

**Result**

**Typing:** This has the same typing as <

*expr* >= *expr*#

Greater than or equal to: TODO: something pithy

**Sample Code**

**Typing:** This has the same typing as <

**Result**

*expr* == *expr*#

Equality: TODO: something pithy

**Sample Code**

**Result**

**Typing:** If a left and right type are comparable (see table under <), then the types can be tested for equality. The resulting type is a bool. Beyond comparable left and right types, the following table

*expr* != *expr*#

Inequality: TODO: something pithy

**Sample Code**

**Result**

**Typing:** This has the same typing as =;

*expr* && *expr*#

Logical and: TODO: something pithy

**Truth Table**

left | right | result |
---|---|---|

false | false | false |

true | false | false |

false | true | false |

true | true | true |

**Sample Code**

**Result**

**Typing:** The left and right expressions must have a type of bool, and the resulting type is bool.

*expr* || *expr*#

Logical or: TODO: something pithy

**Truth Table**

left | right | result |
---|---|---|

false | false | false |

true | false | true |

false | true | true |

true | true | true |

**Sample Code**

**Result**

**Typing:** The left and right expressions must have a type of bool, and the resulting type is bool.

*expr* ? *expr* : *expr*#

Conditional / Ternary: **Sample Code**

**Result**

**Typing:** The first expression must have a type of bool, and the second and third type must be the compatible under type rectification. The result is the rectified type. For more information about type rectification, see anonymous messages and arrays.

## #

Operator precedenceWhen multiple operators operate on different operands (i.e. things), the order of operators (or operator precedence) is used to break ambiguities such that the final result is deterministic. This avoids confusion, and operators with a higher level must evaluate first.

When there are multiple operators at the same level, then an associativity rule indicates how to evaluate those operations. Typically, this is left to right, but some operators may not be associative or be right to left.

level | operator(s) | description | associativity |
---|---|---|---|

11 | expr.ident [_expr expr] exprF(expr0,...,exprN) ( expr) | field dereference index lookup functional application parentheses | left to right |

10 | expr++ expr-- | post-increment post-decrement | not associative |

9 | ++expr -- expr | pre-increment pre-decrement | not associative |

8 | -expr ! expr | unary negation | not associative |

7 | expr*expr expr/expr expr%expr | multiply divide modulo | left to right |

6 | expr+expr expr-expr | addition subtraction | left to right |

5 | expr<expr expr>expr expr<=expr expr>=expr | less than greater than less than or equal to greater than or equal to | not associative |

4 | expr==expr expr!=expr | equality inequality | not associative |

3 | expr&&expr | logical and | left to right |

2 | expr||expr | logical or | left to right |

1 | expr?expr:_expr | inline conditional / ternary | right to left |