Skip to content

Compute vector magnitude with magnitude #685

Description

@Seddryck

Summary

Add a magnitude operation for the first-class numeric Vector type introduced by #684.

magnitude returns the Euclidean (L2) magnitude of the input vector.

Syntax

V(3, 4) | magnitude

returns:

5

Semantics

For V(x1, ..., xn), the result is:

sqrt(x1² + ... + xn²)
  • Input: Vector
  • Output: numeric
  • An all-zero vector has magnitude 0.
  • Numeric behavior follows existing Expressif promotion/coercion rules.
  • Generic arrays and tuples are not implicitly treated as vectors.

Naming

Use magnitude rather than the former norm wording from #553. This keeps the user-facing vocabulary explicit and avoids overloading norm with different possible norm definitions.

Acceptance criteria

  • V(3,4) | magnitude returns 5.
  • Zero, positive, and negative components are supported.
  • The all-zero vector returns 0.
  • Result precision follows Expressif numeric semantics.
  • Generic arrays and tuples are rejected as vector input.
  • Tests and function metadata/documentation are added.

Dependency

Depends on #684.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions