Description
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:
- Given that the math library in OZ exclusively supports unsigned integers, I see no need for both
Rounding.Down
andRounding.Zero
. They essentially mean the same thing for positive numbers. - Independent of the first point, the term
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." - The words "down" and "up" can create confusion. As stated by Wikipedia:
For positive x, round-down is equivalent to round-toward-zero, while round-up is equivalent to round-away-from-zero. For negative x, round-down corresponds to round-away-from-zero, and round-up corresponds to round-toward-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:
enum Rounding {
Expand, // away from zero
Trunc // toward zero
}
Or like this (more verbose, but clear):
enum Rounding {
AwayFromZero,
TowardZero
}
Or like this (given that only unsigned numbers are supported):
enum Rounding {
Ceil, // toward positive infinity
Floor, // toward negative infinity
}
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