Skip to content

Resolve open design decision for Vector0 subtraction #52

@matt-edmondson

Description

@matt-edmondson

Summary

docs/strategy-unified-vector-quantities.md explicitly flags this as an open question:

Design decision needed: What happens when subtracting two Vector0 values would produce a negative result?

  1. Return the absolute value of the difference
  2. Throw an exception
  3. Don't define subtraction on Vector0 at all
  4. Return a Vector1 (the signed difference)

The generator has unilaterally picked option 4: Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs:388-407 emits V0 - V0 => V1 when a V1 form exists.

Problems with the current behaviour

  1. Silent design choice — the strategy doc still lists this as undecided, so consumers won't know what to expect.
  2. No fallback for scalar-only dimensions — quantities like Mass, Energy, Area have no V1 form. The generator either skips subtraction entirely (loss of arithmetic) or could emit something invalid; this is not documented.
  3. No tests assert the chosen semantics in Semantics.Test/SemanticQuantityTests.cs.

Suggested next step

  • Pick a documented option per dimension (probably hybrid: option 4 when V1 exists, option 1 with T.Abs(...) otherwise).
  • Update docs/strategy-unified-vector-quantities.md to state the chosen semantics.
  • Emit consistent operators in the generator and back them with tests.

Area / Severity

SourceGenerators / Docs · incomplete

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions