Next: Unary forms, Previous: Arithmetic, Up: Arithmetic

##### 3.1.4.1 Two-operand (binary) forms and precedence

Most two-operand binary forms have meanings dependent on the types of their arguments. An exhaustive summary of the possibilities is given in the following table.

Left | Op | Right | Result | Description
--- | --- | --- | --- | ---
scalar | `+` | scalar | scalar | Scalar sum.
vector | `+` | vector | vector | Vector sum.
point | `+` | vector | point | Point-vector affine sum.
vector | `+` | point | " | "
scalar | `-` | scalar | scalar | Scalar difference.
vector | `-` | vector | vector | Vector difference.
point | `-` | point | vector | Point-point affine difference.
point | `-` | vector | point | Point-vector affine difference.
scalar | `*` or `.` | scalar | scalar | Scalar product.
scalar | `*` or `.` | vector | vector | Scalar-vector product.
vector | `*` or `.` | scalar | " | "
vector | `*` | vector | vector | Vector cross-product.
vector | `.` | vector | scalar | Vector dot product.
scalar | `^` | scalar | scalar | Raise scalar to scalar power.
transform | `^` | integer | transform | Raise transform or integer power.
transform | `*` or `.` | point | point | Affine point transform (right-to-left).
transform | `*` or `.` | vector | vector | Affine vector transform (right-to-left).
transform | `*` or `.` | transform | transform | Transform composition (right-to-left).
point | `then` | transform | point | Affine point transform (left-to-right).
vector | `then` | transform | vector | Affine vector transform (left-to-right).
transform | `then` | transform | transform | Transform composition (left-to-right).
scalar | `/` | scalar | scalar | Scalar division.
vector | `/` | scalar | vector | Vector component-wise division by scalar.
point | `'` | `x`, `y`, or `z` | scalar | Point component extraction.
vector | `'` | `x`, `y`, or `z` | scalar | Vector component extraction.

Operator precedence is shown in this table.

Op | Precedence
--- | ---
`'` | highest (most tightly binding)
`^` |
`-` | (unary negation)
`*` `.` `/` |
`+` `-` |
`then` | lowest (least tightly binding)

All operations are left-associative except for ^. Parentheses ( ) are used for grouping to override precedence in the usual way.

As you can see, the dot operator . is usually a synonym for run-of-the-mill multiplication, *. The meanings differ only for vector operands. The `then` operator merely reverses the operand order with respect to normal multiplication *. The intent here is to make compositions read more naturally. The code

         (1,2,3) then scale(2) then rotate(30) then translate([1,3,0])

expresses a series of successive modifications to the point, whereas the equivalent form

         translate([1,3,0]) * rotate(30) * scale(2) * (1,2,3)

will be intuitive only to mathematicians (and perhaps Arabic language readers).