-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
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.
There was a problem hiding this 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!
au/constant_test.cc
Outdated
// numerator of `1`, and would therefore always be zero. | ||
// | ||
// Uncomment to make sure the compilation fails: | ||
// EXPECT_THAT((c / 2).coerce_as(meters / second), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
Kinda neat that #200 ended up being a pretty big feature like this. Didn't plan it this way! 😁 |
This is the basic machinery for representing physical constants. Later
on, we plan to include
Constant
instances in the library out of thebox, 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 thetype, we know exactly which
Quantity<U, R>
instances it can convertto.
Doc updates are included: I added a new reference page for
Constant
. Ialso 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 expectwe'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 upway up in the "C" section in the first place.
Helps #90.