Language: Arithmetic

Sentinel supports arithmetic operators for integers and floats. Sentinel supports sum, difference, product, quotient, and remainder.

+    sum
*    difference
*    product
/    quotient
%    remainder

These operators work in a typical infix style:

4 + 8 // 12
8 * 2 // 16
8 / 4 // 2
8 / 5 // 1
8 % 5 // 3

Order of Operations

Arithmetic follows a standard mathematical order of operations. Grouping with parentheses can be used to affect ordering.

4 * 5 / 5 // 4
4 * 5 + 2 // 22
4 + 5 * 2 // 14
(4 + 5) * 2 // 18

A full table of operator precendence can be found on the boolean expressions page. This shows how arithmetic operators relate to other operators.

Integer Division

Integer division with a remainder rounds down to the nearest integer. Example: 8 / 3 is 2.

If the divisor is zero, an error occurs.

Mixed Numeric Operations

Mixed numeric operations between integer and floating-point values are permitted. The result is a floating-point operation with the integer converted to a floating-point value for purposes of calculation.

import "types"

a = 1.1 + 1      // 2.1
types.type_of(a) // "float"