-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 BigDecimal#round(digits, mode) overload #7126
Conversation
5f8824b
to
589add7
Compare
a2607dd
to
003083c
Compare
a75179f
to
1ea2fd8
Compare
Ready for review. |
This doesn't even attempt to be compatible with |
That's true, some goes for Ruby has more uniform API in this regard, with
Unfortunately, that's quite likely, but you're free to post your optimization suggestions, let's treat it as yet another Advent of Code puzzle ;) |
I don't want to merge this before we sort out a rounding API on |
I'd like to correct my statement, since Now, as for cleaning up the API, I'd suggest dropping base argument, would leave us with consistent API of Additional (named?) argument mode support would stay for |
@RX14 any thoughts? |
Same as before, we need to unify the API. We should keep base. |
@RX14 yeah, you said it before, any (counter) suggestions how? and why in your opinion should we keep base? |
Hi, what's the status of this PR? @RX14 proposed unification of
I disagree, personally I've never had a need to specify base while rounding, neither I've seen it anywhere in the wild. Ruby, JavaScript, Python, PHP - they all have pretty consistent APIs regarding rounding numbers, in which base is nowhere to be seen. In terms of
I'd like to continue working on it once some course of action is settled. |
1ea2fd8
to
7d3b17d
Compare
7d3b17d
to
96b9ef9
Compare
Mornin' ☀️ ! I've force-pushed refactored implementation which, I believe should be a tad more performant, and so I'd like to revisit this PR if possible since this feature comes rrrly handy for these few occasions (think financial, especially crypto), thanks for the attention and have a great day there :) 🙏 Side note: Some of the GHA CI jobs (CircleCI is ✅ ) seem to use a stale cache or sth - the spec failures doesn't seem to cover for the actual code - that or... might a be a red herring since it's already just a bit l8 for me - or early for that matter 🙃 |
f761e16
to
99f2f52
Compare
ping, could this get a review please? /cc @straight-shoota @asterite @waj |
@Sija I don't think this has any pressure to get into 1.0. There are a bunch of more important things right now to make sure 1.0 is properly released, so please be patient until we get some time to review this and other PRs. Thank you! |
99f2f52
to
2f46b1e
Compare
This can now be refactored on top of #10413. |
I don't think we should add the global It might actually be best to close this and start with a fresh PR. |
77c088a
to
e942306
Compare
@straight-shoota rebased on top of the current |
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.
Please exclude rounding_mode
setting from this PR. This feature warrants a dedicated discussion. If at all, it should probably be global to Number
and not specific to BigDecimal
(see #10414 (comment) ff.).
Also BigDecimal
is missing the basic rounding mode methods #round_away
and #round_even
.
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.
Misclicked on Approve
@Sija Are you up to address the last review commment and remove |
@straight-shoota Will do, sadly I'm not sure I can give you any sensible timeframe for that. |
in .to_negative? then negative | ||
end | ||
|
||
value += 1 if round_up |
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.
This addition is incorrect, since value
is already the BigDecimal
itself, not the mantissa:
BigDecimal.new("123.456789").round(2, mode: :ties_away) # => 124.45
With #10798 merged and the part about |
Thank you both, @Sija and @HertzDevil =) |
Fixes #5714
TBD:
BigDecimal.rounding_mode
BigDecimal.save_rounding_mode
BigDecimal.with_rounding_mode