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 implementation and docs for Constant #200

Merged
merged 3 commits into from
Nov 27, 2023
Merged

Conversation

chiphogg
Copy link
Contributor

This is the basic machinery for representing physical constants. Later
on, we plan to include Constant instances in the library out of the
box, but first we want to explore the feature in production inside
Aurora's internal repo.

The first set of basic features is to multiply and divide a wide variety
of types. When we do this, the operations always take place at compile
time
, and symbolically.

The next set of features is various kinds of conversions to Quantity
types and/or raw numbers. The standout feature here is the perfect
conversion policy
: since each Constant fully encodes its value in the
type, we know exactly which Quantity<U, R> instances it can convert
to.

Doc updates are included: I added a new reference page for Constant. I
also updated the alternatives page. A couple libraries that were
previously "good" are now "fair", because they use quantities for their
constants, which is sub-optimal. mp-units moved from "best" to "good"
because I think on balance we're now tied. On the one hand, they have
actually included pre-defined constants. On the other hand, our core
implementation is better because we also support converting to
Quantity types. Once we include constants out of the box, I expect
we'll be "best".

Finally, I re-alphabetized the BUILD rules. This basically meant simply
moving //au:operators to its rightful place; not sure how it ended up
way up in the "C" section in the first place.

Helps #90.

This is the basic machinery for representing physical constants.  Later
on, we plan to include `Constant` instances in the library out of the
box, but first we want to explore the feature in production inside
Aurora's internal repo.

The first set of basic features is to multiply and divide a wide variety
of types.  When we do this, the operations always take place _at compile
time_, and symbolically.

The next set of features is various kinds of conversions to `Quantity`
types and/or raw numbers.  The standout feature here is the _perfect
conversion policy_: since each `Constant` fully encodes its value in the
type, we know exactly which `Quantity<U, R>` instances it can convert
to.

Doc updates are included: I added a new reference page for `Constant`.
I also updated the alternatives page.  A couple libraries that were
previously "good" are now "fair", because they use quantities for their
constants, which is sub-optimal.  mp-units moved from "best" to "good"
because I think on balance we're now tied. On the one hand, they have
actually included pre-defined constants.  On the other hand, our core
implementation is better because we also support converting to
`Quantity` types.  Once we include constants out of the box, I expect
we'll be "best".

Finally, I re-alphabetized the BUILD rules.  This basically meant simply
moving `//au:operators` to its rightful place; not sure how it ended up
way up in the "C" section in the first place.
@chiphogg chiphogg added the release notes: ✨ lib (enhancement) PR enhancing the library code label Nov 25, 2023
Copy link
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes, tests, and documentation look good. This PR is a big feature. Thanks!

// numerator of `1`, and would therefore always be zero.
//
// Uncomment to make sure the compilation fails:
// EXPECT_THAT((c / 2).coerce_as(meters / second),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Can you elaborate on this code? Wouldn't coerce_as allow for truncation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The c / 2 is the only part that really matters here. I'll eliminate the rest --- it's quite a distraction. Nice catch!

@chiphogg
Copy link
Contributor Author

Changes, tests, and documentation look good. This PR is a big feature. Thanks!

Kinda neat that #200 ended up being a pretty big feature like this. Didn't plan it this way! 😁

@chiphogg chiphogg merged commit 8fa4e38 into main Nov 27, 2023
10 checks passed
@chiphogg chiphogg deleted the chiphogg/constants-impl#90 branch November 27, 2023 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: ✨ lib (enhancement) PR enhancing the library code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants