-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Context #75
Context #75
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #75 +/- ##
==========================================
+ Coverage 98.13% 99.60% +1.47%
==========================================
Files 10 11 +1
Lines 214 255 +41
==========================================
+ Hits 210 254 +44
+ Misses 4 1 -3 ☔ View full report in Codecov by Sentry. |
8ab50a2
to
1d7c94e
Compare
@ViralBShah I wonder if it would be a better interface to have @with CONTEXT => Context(precision=123, rounding=RoundUp) begin
# user code
end instead of setprecision(Decimal, 123) do
setrounding(Decimal, RoundUp) do
# user code
end
end I think the # In package A
module A
using Decimals
function f()
setprecision(Decimal, 123)
end
end
# In package B
module B
using A
function g()
setprecision(Decimal, 456)
f()
# precision is 123, not 456
end
end One "downside" is that users might be used to |
This sounds like a better idea than global state for sure! I think doing things differently from Base that is a better way , should be encouraged. And that often paves the way for Base to do new things later. @oscardssmith Any thoughts, or anyone else we can ask. I don't think there is much of a design decision here, since this is natural - but sometimes it is good to bring these up on discourse. |
yeah this seems like a reasonable design. I think this is what BigFloat is moving to as well, right? |
I am not sure about BigFloat but there is a very recent PR that turns global variables into ScopedValues: JuliaLang/julia#56378 |
ScopedValues require Julia 1.8 at minimum. Is it okay to lift our requirement from v1.6 to v1.8? |
yeah 1.10 is new LTS, so no one would complain if you lifted to 1.8 |
6482133
to
34fd7d2
Compare
What do you think about the Macro: using Decimals
Decimals.@with_context (Emax=384, Emin=-383, precision=9, rounding=RoundNearestTiesAway) begin
@test -(dec"56267e-0") == dec"-56267"
end instead of using Decimals
using ScopedValues
@with Decimals.CONTEXT => Context(Emax=384, Emin=-383, precision=9, rounding=RoundNearestTiesAway) begin
@test -(dec"56267e-0") == dec"-56267"
end Function: using Decimals
Decimals.with_context(f, Emax=384, Emin=-383, precision=9, rounding=RoundNearestTiesAway) instead of using Decimals
using ScopedValues
with(f, Decimals.CONTEXT => Decimals.Context(Emax=384, Emin=-383, precision=9, rounding=RoundNearestTiesAway)) |
465c69b
to
162944d
Compare
This PR introduces
Context
, a structure that holds configuration of the decimal arithmetic.Eventually, the global variable
DIGITS
should be completely removed in favor of this newly-added structure.Requires #79