-
-
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 Number.rounding_mode
+ .{with,save}_rounding_mode
#11097
Conversation
db65c04
to
70b7fc7
Compare
70b7fc7
to
728d70a
Compare
Number.{with,save}_rounding_mode
Number.rounding_mode
+ .{with,save}_rounding_mode
I would prefer to start a discussion about this feature proposal first, instead of jumping direclty into a PR. |
@straight-shoota I already referenced the comments that were voiced before. |
Yes and in #7126 (review) I explicitly asked for a separate discussion. This is not a trivial addition. We should make sure to identify the correct use cases and design an approriate API for that. |
This sounds like over-complicating the issue. The use case is the ability to globally change the default rounding mode since it's common that an external code:
API in this PR covers that, adding a class property + two yielding class methods. |
Could this be moved forward? |
I'm not convinced about this implementation. So no approval from me without a dedicated discussion about use cases and alternatives. |
@straight-shoota It's hard to discuss "not being convinced" statement. Could you please elaborate on what exactly makes you not convinced? btw, re: use cases I've already started a discussion that you didn't continue. |
Hi @Sija , we took some time to discuss this with the team and concluded we will not move this forward. While we see that changing the behavior of the default rounding method is a reasonable request, we also believe that doing it on the fly, globally, provides an entry point to bugs. Moreover, the block-yielding methods makes it sound as if they could contain the global effect, but that's not really the case. Number.with_rounding_mode :ties_away do
ties_away?
... # no ties away 😭
end
def ties_away?
Number.rounding_mode = :ties_even # 😈
...
end Therefore, I will close this PR, as I see no point in keeping it around. We can always re-open it if we change our minds. As mentioned, we encourage you to continue the discussion in a dedicated issue where we can weight other alternatives. |
Hi @beta-ziliani, thanks for looking into it.
In order to minimize the scope of possible bugs stemming from globally changing the default, it could be changed to be a read-only property, changeable only within the scope of
Well, it is the case, but in your example you're changing the global default within the |
Note that this would easily break in a concurrent setting.
Well, the thing is that you might not know how the methods you call will behave w.r.t. the rounding option, so you might work under the assumption of one option, when in reality it changes mid-way the computation. |
As per #10414 (comment)
Refs #7126 (review)