-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Rounding mode names #4185
Comments
Thanks for the feedback @PaulRBerg, we're reviewing this as part of 5.0. I have a few comments:
So far I agree the current naming may not be clear and require to see the code to verify. Given that I see |
When we added this enum, the objective was to "future-proof" it. This is why we distinguished I personally believe that, we should keep the 3 options, and in the same order, so that we minimize the changes.
|
In principle I like the suggestion to follow Intl.NumberFormat V3. This suggestion would be:
The alternative I would favor is something like the verbose option, but
I am fine with both sets of options in this comment. |
I also find
I also want to bump that we can remove the |
The However, because the two following things have been said:
You should also be open to using |
It feels to me that
Is the winning option here. Any opposition ? |
Starting to realize that it doesn't make sense to try to future-proof for signed numbers. The point that is evident in Intl.NumberFormat V3 is that once you consider signed numbers, 3 rounding modes are not really enough, you need all the 4 rounding modes: ceil (toward +∞), floor (toward -∞), expand (away from 0), trunc (toward zero), depending on what you want to do with the result. So I now think we should only cater to unsigned numbers, and remove With this consideration I think |
Considering |
Then I would add the 4th mode instead of removing zero.
Please don't consider it remove before I'm able to say anything following frangio's message. I have a right to disagree here. |
Also, if we decide to remove the Zero part, I would strongly insist we make sure that the naming we use for the remaining 2 makes clear sens for both signed and unsigned rounding so that we don't have to change it again if we want to introduce signed math with rounding. Changing the name again would be a breaking change, I don't want us to commit to not making signed math with rounding in 5.0. |
This issue is about the
Rounding
enum part of the math library:openzeppelin-contracts/contracts/utils/math/Math.sol
Lines 10 to 14 in 8d633cb
I'd like to provide some feedback:
Rounding.Down
andRounding.Zero
. They essentially mean the same thing for positive numbers.Rounding.Zero
is ambiguous. To understand that it means "toward zero," one must examine the source code, as it could be mistaken for "away from zero."Complicating the matter, the ICU has further butchered these terms by defining "down" as "rounded towards the next smaller absolute value" (which Wikipedia refers to as "toward zero"), and "up" as "rounded towards the next greater absolute value" (which Wikipedia refers to as "away from zero"). This can be misleading, as "down" typically implies "toward negative infinity," and "up" implies "toward positive infinity."
To address all of these issues, I recommend adhering to the
Intl.NumberFormat V3
standard, which replaces the terms "down" and "up" with "trunc" and "expand", respectively:Or like this (more verbose, but clear):
enum Rounding { AwayFromZero, TowardZero }
Or like this (given that only unsigned numbers are supported):
However, I wouldn't go with the last option if you plan on supporting signed numbers in the future.
A good related discussion about this topic can be found here: tc39/proposal-intl-numberformat-v3#7
The text was updated successfully, but these errors were encountered: