Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit-awareness library #1218

Closed
wants to merge 1 commit into from

Conversation

DavidLegg
Copy link
Contributor

  • Tickets addressed: N/A
  • Review: By file
  • Merge strategy: Merge (no squash)

Description

Adds a QUDV (Quantity, Unit, Dimension, and Value) library, generalized over the type of values. This is part of #1198, which applies units to numbers, dynamics, and resources, and allows adding units to other types.

In this library, base dimensions are declared at runtime, and derived dimensions are constructed by multiplying and taking powers of base dimensions. A dimension is a product of rational powers of base dimensions, and are represented exactly.

Units are a dimension and a scale. To use them properly, we declare a base unit for each base dimension, which implicitly has a scale of "1", and derive all other units from these through multiplication and powers. Derived units are anonymous by default, but can be given names. Since units are a multiplier and a dimension, we can only represent units with "absolute" scales. (So Kelvin is representable, but degrees Fahrenheit isn't.)

Quantities are represented by the UnitAware<T> interface, and represent a value of type T and a unit, with the ability to do dimensionality checks and rescale the value to convert to a different unit.

Verification

There's a unit test for the Dimension class, but other classes have only been spot-checked. I'm working on converting the Clipper model, and parts of it use UnitAware types, so that should provide some test cases.

Documentation

At the moment, only the inline Javadocs document this code, but we want to make wiki page(s) describing this and other parts of #1198. I'll update this description when that happens.

Future work

See #1198

@DavidLegg DavidLegg requested a review from a team as a code owner October 26, 2023 21:22
@DavidLegg DavidLegg temporarily deployed to e2e-test October 26, 2023 21:22 — with GitHub Actions Inactive
@DavidLegg
Copy link
Contributor Author

Closing this as redundant, because #1253 was merged.

@DavidLegg DavidLegg closed this Jan 31, 2024
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