Skip to content

Make DimensionalMeasurement SI-coherent and add typed Measurement operators - #11

Merged
ken0nek merged 4 commits into
mainfrom
si-coherence-typed-algebra
Oct 1, 2026
Merged

ken0nek merged 4 commits into
mainfrom
si-coherence-typed-algebra

Conversation

@ken0nek

@ken0nek ken0nek commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • DimensionalMeasurement computes in coherent SI units instead of Foundation's base units, so 1 m × 1 m × 1 m is 1 m³, not 1 L.
  • Angle and information storage are their own dimensions and never mix with plain ratios.
  • Products and quotients with a typed result return that Measurement directly (60 generated operators); a dimensionless result is a Double.
  • DimensionalMeasurement equality is relative, and infinite values compare exactly.
  • Measurement no longer conforms to the literal protocols, which made x / 2 ambiguous against the typed operators.
  • CI fails when the generated operators are stale.

Breaking

This is a 3.0 change. The README's "Migrating to 3.0" section lists every behaviour change, including the new DimensionalUnit.coherentScale requirement.

Testing

swift test

…rators

DimensionalMeasurement now stores its value in coherent SI units, scaled by
each unit type's coherentScale, so products and quotients agree wherever
Foundation's base unit is not SI: litres, degrees, bytes, parts per million
and L/100km. The information storage scale is derived from Foundation's own
bit unit, because the base unit is the byte on Darwin and the bit on Linux.
Angle and information become pseudo-dimensions, so angles and data sizes
never mix with plain ratios. Equality uses a relative tolerance, and infinite
values compare exactly.

Concrete Measurement<A> op Measurement<B> -> Measurement<C> operators are
generated from the dimension table by the GenerateTypedAlgebra executable,
so an unannotated product is typed. CI fails when the generated files are
stale.

The retroactive literal conformances on Measurement are removed: they make
x / 2 ambiguous against the typed operators.

The README documents the typed operators, SI coherence and the 3.0
behaviour changes.
@ken0nek ken0nek self-assigned this Oct 1, 2026
On Linux, Foundation builds litersPer100Kilometers with a reciprocal
converter, so converting a base-unit measurement to miles per gallon
inverted the value. convert(to:) now applies the target unit's converter
to the base value directly, which gives the same result on Darwin.
@ken0nek
ken0nek merged commit b7673c4 into main Oct 1, 2026
3 checks passed
@ken0nek
ken0nek deleted the si-coherence-typed-algebra branch October 1, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant