expression

Use a dot product to compare directions

The dot product combines corresponding vector components into one scalar. For nonzero vectors its sign distinguishes acute, right and obtuse angles in exact mathematics. For unit vectors it equals the cosine of their angle. Here integer unit axes give exact results; floating-point near-zero results need a tolerance. Expected result (NOT RUN): 1 0 -1 Common mistake: Interpreting a dot product as an angle in degrees or using it as a cosine before normalization. Small integer inputs are required here to avoid overflow. Static Rust example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
a[0] * b[0] + a[1] * b[1]

Working Example

Example Snippetrust
fn dot(a: [i32; 2], b: [i32; 2]) -> i32 { a[0]*b[0] + a[1]*b[1] }fn main() {    let forward = [1, 0];    for other in [[1, 0], [0, 1], [-1, 0]] {        println!("{}", dot(forward, other));    }}
Rust Reference