Repository navigation
Make DimensionalMeasurement SI-coherent and add typed Measurement operators - #11
Merged
Merged
Conversation
…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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DimensionalMeasurementcomputes in coherent SI units instead of Foundation's base units, so1 m × 1 m × 1 mis 1 m³, not 1 L.Measurementdirectly (60 generated operators); a dimensionless result is aDouble.DimensionalMeasurementequality is relative, and infinite values compare exactly.Measurementno longer conforms to the literal protocols, which madex / 2ambiguous against the typed operators.Breaking
This is a 3.0 change. The README's "Migrating to 3.0" section lists every behaviour change, including the new
DimensionalUnit.coherentScalerequirement.Testing
swift test