-
Notifications
You must be signed in to change notification settings - Fork 183
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
FixedDecimal mutating functions should use active verbs #2902
Comments
I must say trunced makes me think of trounced than truncated (but agreed, it is more understandable than the various flavours of rounding to nearest). |
Some thoughts: I think there's nothing majorly wrong with the current way. If we wanted to change it, here's some suggestions:
Another thought, however, is that I had some trouble understanding all the methods (e.g., Since we are discussing changing names, maybe adding a Verdict: I don't think the issue of active verbs is a big deal, but changing names might clear things up a bit. I do agree with @eggrobin that |
Conclusion: Add better documentation for FixedDecimal. We are unable to reach consensus on a set of names for the functions. |
A slate of names to consider in the future (suggested by @eggrobin):
|
With the addition of @jedel1043's new RoundingIncrement functions, @markusicu noted that the matrix of these rounding functions is very large and unwieldy. I believe we now have 36 rounding functions, 4 for each of the 9 rounding modes. We need separate Also incorporating @eggrobin's naming scheme from the previous post, it would mean clients would need to change the following: formatter.format(
FixedDecimal::from(123usize)
.multiplied_pow2(-2)
.half_expanded(-1)) to formatter.format({
let mut fd = FixedDecimal::from(123usize);
fd.multiply_pow2(-2);
fd.round_half_expanded(-1);
fd
}) Of course the assembly code between these two examples should be exactly the same. |
Seeking consensus on the following proposals for 2.0: Part 1Remove the self-moving rounding functions in order to reduce API bloat. See previous post. Seeking consensus from: Part 2Rename all of the rounding functions to have
Seeking consensus from: Part 3To increase discoverability, add aliases for the most common rounding functions:
Seeking consensus from: Part 4 Alternative ATo further reduce API bloat but at the cost of choices when it comes to code size, we can make all
Seeking consensus from: Part 4 Alternative BTo reduce API bloat even further, we can merge all of the "unusual" rounding functions down to just one function that takes an enumeration argument. Again, this is dependent on Part 3 so that we provide something for code-size-conscious clients. There is some bikeshedding to do here. A strawperson: pub enum RoundingMode {
Ceil,
Floor,
Trunc,
Expand,
HalfCeil,
HalfFloor,
HalfTrunc,
HalfExpand,
HalfEven,
}
impl FixedDecimal {
pub fn round_to_mode(&mut self,
position: i16,
mode: RoundingMode) { ... }
pub fn round_to_mode_and_increment(&mut self,
position: i16,
mode: RoundingMode,
increment: RoundingIncrement) { ... }
} Seeking consensus from: |
As part of this issue, we should also address the documentation feedback @markusicu left in the RoundingIncrement API Review here: https://docs.google.com/document/d/1gKZCaiTG2eeyxrIKUF2tf6PIsaPCIBaUVRXD-JDh6dI/edit#heading=h.7pm5mstzwo40 |
Agreed on the general idea of parts 1-3. For part 4, I strongly tend towards B because it would considerably simplify the API usage for users who take the rounding mode programmatically. Example of the current usage: match mode {
RoundingMode::Ceil => number.ceil_to_increment(position, multiple),
RoundingMode::Floor => number.floor_to_increment(position, multiple),
RoundingMode::Expand => number.expand_to_increment(position, multiple),
RoundingMode::Trunc => number.trunc_to_increment(position, multiple),
RoundingMode::HalfCeil => number.half_ceil_to_increment(position, multiple),
RoundingMode::HalfFloor => number.half_floor_to_increment(position, multiple),
RoundingMode::HalfExpand => number.half_expand_to_increment(position, multiple),
RoundingMode::HalfTrunc => number.half_trunc_to_increment(position, multiple),
RoundingMode::HalfEven => number.half_even_to_increment(position, multiple),
} With the proposed change, this would simplify to: number.round_to_mode_and_increment(position, mode, multiple) |
I don't feel strongly about the |
On Alternative B, you could drop the |
My proposal is that |
This is consistent with Python, but I think it's more common to use half-expand rounding by default. (Rust uses that in its |
Okay, how about making the list of functions in Part 3 be
I would like to not add a function named |
Scripsit Markus:
4B does have the advantage of sidestepping the whole discussion of how to avoid silliness of either round half evenings or round half floors (presumably these are found in half-apartments of spherical buildings?), while retaining the word round that gives the hapless reader a chance to figure out what this mysterious evening is about1. Footnotes
|
Can be done pre-2.0 because fixed_decimal is not icu4x-versioned |
It is in FFI and therefore impacts 2.0 |
My understanding is that the proposed set of functions is:
Does that match everyone's expectations? |
Also, do we still keep the With fewer functions, maybe we can afford to keep them now. |
Start: 11:05
Conclusion: keep self-moving functions. |
Related to #2902 Mainly removes all the `_to_increment` methods, which are superseeded by the `round_with_mode_and_increment` method. Additionally, adds a `round` function that does half to even rounding.
It occurred to me when reviewing #2898 that the function names we chose for rounding do not have an active verb: "half_even", etc. Should they be active verbs?
Some of the functions are fine, like "trunc". I feel like "floor" is understood to be a verb in this context, too.
The text was updated successfully, but these errors were encountered: