-
Notifications
You must be signed in to change notification settings - Fork 20
MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS -> MPREAL_FIXED_PRECISION #28
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
base: master
Are you sure you want to change the base?
Conversation
The old semantics: MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS: digits() is a function !MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS: digits is a constant But in the latter case, the constant value of digits is hardwired into mpreal.h. The new semantics: MPREAL_FIXED_PRECISION == 0: digits() is a function MPREAL_FIXED_PRECISION > 0: digits = MPREAL_FIXED_PRECISION This makes it easy to select the fixed precision at compile time with, e.g., -DMPREAL_FIXED_PRECISION=256 At runtime set_default_prec(numeric_limits<mprf::mpreal>::digits); should be called to make the actual precision consistent with digits.
|
Sorry to be submitting this PR superseding the previous #27. It should |
Switch the MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS logic from defined/undefined to 1/0. This make it easy to set the value externally, e.g., with #define MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS 0 #include <mpreal.h> I needed this facility using Boost's boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp But most users won't notice this change.
|
I appreciate the proposal and contribution, but I am not sure if it makes sense switching to the MPREAL_FIXED_PRECISION at the moment. First of all, this might break a lot of projects relying on Secondly, introduction of MPREAL_FIXED_PRECISION may create confusion for most of the users. They might assume it controls default precision overall. I believe we should avoid such potentially ambiguous features, particularly regarding precision control. The proper control of MPFR's default precision is not easy as it is. Basically there are two ways (build time/runtime):
#pragma omp parallel firstprivate(precision, N)
{
mpfr_set_default_prec(precision);
#pragma omp for schedule(static)
for (int i = 0; i < N; i++)
{
}
mpfr_free_cache();
}IMHO, adding another entity which might be confused with precision control will make things more complicated (even now most emails I receive from users are related to precision control). Now, in case of MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS, Boost, Eigen, etc. probably need to introduce customized numeric traits allowing digits to be dynamic, if arbitrary precision support is planned. I would appreciate comments & opinions. As an idea - maybe we should remove the |
|
Let me give my use case: I routinely compile my codes to use I recently needed to use Boost's dense solvers for ODEs and these require that This PR addresses this problem by replacing the magic constant I concede that some users may be confused. But only if they set Beyond this, I could imagine modifying the code so that for
I don't see the need to these changes and would trust the users to know what they are doing. |
|
I should add, that while I think this PR is, on balance, useful, I'm fine with it not being accepted. I can work with my patched version of |
This is exactly what I want to avoid in Advanced precision control (together with things like optimized memory allocators for Thus, I consider inclusion of In any case, thank you very much for all your suggestions and contributions! |
The old semantics:
MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS: digits() is a function
!MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS: digits is a constant
But in the latter case, the constant value of digits is hardwired into mpreal.h.
The new semantics:
MPREAL_FIXED_PRECISION == 0: digits() is a function
MPREAL_FIXED_PRECISION > 0: digits = MPREAL_FIXED_PRECISION
This makes it easy to select the fixed precision at compile time with, e.g.,
-DMPREAL_FIXED_PRECISION=256
At runtime
set_default_prec(numeric_limitsmprf::mpreal::digits);
should be called to make the actual precision consistent with digits.