-
Notifications
You must be signed in to change notification settings - Fork 212
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
Ratios and rounding modes #3138
Comments
As the above maybe hints at, I'm currently leaning toward a single operation (and use of I don't think |
I like the idea of
where one API call is used for both parts and ensures conservation of amounts. Perhaps an optional ack: I think @dtribble suggested this. |
Not all our ratios are less than one, so thinking of it as splitting the amount doesn't always make sense. When it does, I like the idea of giving the product and the remainder. ( We could revisit the idea of merging this into AmountMath, but the current state is that Ratios are separate from Amounts, though the do overlap with that functionality a lot. The vast majority of uses of AmountMath never get near a ratio. |
My vote is for |
Yes. The basic idea is that the difference between "floor" and "ceil" is instead "choose which party you explicitly give the remainder to". Edit: Actually the code sample entangled two separate suggestions:
I like 1, though as Chris notes, what you want for ratios<1 is usually different than rations > 1. 2 probably is not worth it, since generally we are just talking about whether the least significant bit is 1 or 0 :). |
@erights, @dtribble Please express a position among options 1-6, or describe an alternative in enough detail that it could be considered with the others. @katelynsills expressed a preference for #1. My preference is for #3 or #2, though I'd prefer #1 to not making a decision. IMHO, @dckc's suggestion addresses a subset of cases, so isn't really in contention as a general solution. |
I like #3 much better than the others. I had to ask @Chris-Hibbert to explain "apply" to me as I had no idea where that came from. I also like "scale" better than "rate" |
I prefer #3 of the action options. I don't like starting operation names that don't start with the operation; e.g. If we are using the verb |
Scaling by a rate sounds good to me. So we'd still keep "scale" as the verb. I think I like Everyone: Does |
I don't have a problem with |
BTW the one minor caveat for having the verb first is that tab completion will require you to choose each time whether ceiling or floor. |
I don't think we have consensus yet, since I voted for number 1. There are significant downsides to number 3:
I think we need to prioritize clarity and ease of use, and 3 doesn't do that. |
I dislike using We do however have 93 |
Trying to read this - does this mean there are 38
Can you expand on this question? Not sure what you mean. |
I count 20 The fact that there are so few cases of |
Dean suggested that verbs should go first, which would give us
There are still unretracted arguments above for requiring invert in order to divide, which gives
My current feeling is that we aren't saving anyone any complication by going with 7. Choice 9 has fewer operations, but not fewer concepts. The maintenance and doc burden for us to support explicit divide operations is negligible. |
Option 7 gets my vote because |
This gets what I intended to write exactly backward. We don't save anyone any trouble by only having (Edited to add) I should say this explicitly: I'm in favor of 7. |
I prefer option 1 to 7, even though I generally prefer verb first. But consider the names of the option 7 verbs. For example
As a variant of option 7, |
|
Separate but related question. Why the "By"? For an infix operator this is sometimes appropriate, as in the recent |
Have we already enumerated
|
We needed |
Rounding aside, is |
It was the fact that the ratio had to be the second argument to the divide operation that drove us away from making ratios be objects with methods. One could say "divide x by y" or "divide y into x", so 'by' does add something. |
In light of Chris' defense of "By", I favor option 1. If we need the "By", that kills both 10 and 11. With the "By", the confusion of what's modifying what kills 7. |
If we agree
then, are we left with any options other than 1? |
I think we've also given up on |
I'm fine with Option 1 |
Any remaining objections to 1? If so, are there any surviving viable alternatives to 1? |
No objections. |
I will add this to my tasks. Thanks for the discussion! |
I'm going to need to think about how to represent ratios to multiply by non-amounts. In governance, a quorum is a ratio applied to numbers of voters, which don't have a brand. |
It seems to me that it has a brand. The quorum of a committee is unrelated to the quorum of a liq token vote. That brand mechanism allows describing that! |
The current Ratio library hides the fact that every
multiplyBy
anddivideBy
ends by making anAmount
with a bigInt value by doing a divide. The current implementation always usesfloorDivide
rather than giving the caller control. We're in agreement that the caller should make an explicit choice, but haven't found operation names and parameter decisions that we all like. This issue is a place to be clear about potential solutions so we can settle on a least bad compromise, or find something that we mostly all like.There are two operations
amount * ratio
andamount / ratio
and two choices of rounding mode: round up and round down. We're pretty much agreed that using a parameter to choose either the rounding mode or the operation would be a mistake. That leaves naming the operation.There are some arguments for
scale
or possiblyapply
as the operation name rather thanmultiple/divide
.One alternative to having two operation names is to perform divisions by explicitly inverting the ratio. Current practice heavily leans toward
multiplyBy
; it seems relatively straightforward to arrange that the ratios we build are designed for use withmultiplyBy
. (I only see two non-test uses of divideBy, while there are ~20 of multiplyBy.)Dean suggested:
He also suggested that it's possible that the ratio/rate could have the choice of
floorDivide
vs.ceilDivide
baked in.The text was updated successfully, but these errors were encountered: