From b144b60ecb19c20ae448b130874184e259295f2a Mon Sep 17 00:00:00 2001 From: Case Van Horsen Date: Mon, 21 Oct 2024 06:46:19 -0700 Subject: [PATCH] Use default expanded exponent range by default. --- setup.py | 2 +- src/gmpy2.c | 4 ++++ src/gmpy2_abs.c | 11 ++++++++++- src/gmpy2_context.c | 4 ++-- src/gmpy2_context.h | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index fac0c365..dc3b1708 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ class Gmpy2Build(build_ext): def initialize_options(self): build_ext.initialize_options(self) - self.fast = False + self.fast = True self.gcov = False self.vector = False self.static = False diff --git a/src/gmpy2.c b/src/gmpy2.c index 0179a5e8..fa27f7f3 100644 --- a/src/gmpy2.c +++ b/src/gmpy2.c @@ -658,6 +658,10 @@ PyMODINIT_FUNC PyInit_gmpy2(void) return NULL;; /* LCOV_EXCL_STOP */ } + + /* Set precision to maximum and minimum values. */ + mpfr_set_emax(MPFR_EMAX_MAX); + mpfr_set_emin(MPFR_EMIN_MIN); /* Initialize exceptions. */ GMPyExc_GmpyError = PyErr_NewException("gmpy2.gmpy2Error", PyExc_ArithmeticError, NULL); diff --git a/src/gmpy2_abs.c b/src/gmpy2_abs.c index 566370a4..69d2c32e 100644 --- a/src/gmpy2_abs.c +++ b/src/gmpy2_abs.c @@ -129,9 +129,10 @@ static PyObject * GMPy_Real_AbsWithType(PyObject *x, int xtype, CTXT_Object *context) { MPFR_Object *result = NULL, *tempx = NULL; + mpfr_exp_t _oldemin, _oldemax; CHECK_CONTEXT(context); - + if (!(tempx = GMPy_MPFR_From_RealWithType(x, xtype, 1, context)) || !(result = GMPy_MPFR_New(0, context))) { /* LCOV_EXCL_START */ @@ -142,10 +143,18 @@ GMPy_Real_AbsWithType(PyObject *x, int xtype, CTXT_Object *context) } mpfr_clear_flags(); + + _oldemin = mpfr_get_emin(); + _oldemax = mpfr_get_emax(); + mpfr_set_emin(GET_EMIN(context)); + mpfr_set_emax(GET_EMAX(context)); result->rc = mpfr_abs(result->f, tempx->f, GET_MPFR_ROUND(context)); Py_DECREF((PyObject*)tempx); + mpfr_set_emin(_oldemin); + mpfr_set_emax(_oldemax); + _GMPy_MPFR_Cleanup(&result, context); return (PyObject*)result; } diff --git a/src/gmpy2_context.c b/src/gmpy2_context.c index fecd79af..68ca30ba 100644 --- a/src/gmpy2_context.c +++ b/src/gmpy2_context.c @@ -63,8 +63,8 @@ GMPy_CTXT_New(void) if ((result = PyObject_New(CTXT_Object, &CTXT_Type))) { result->ctx.mpfr_prec = DBL_MANT_DIG; result->ctx.mpfr_round = MPFR_RNDN; - result->ctx.emax = MPFR_EMAX_DEFAULT; - result->ctx.emin = MPFR_EMIN_DEFAULT; + result->ctx.emax = MPFR_EMAX_MAX; + result->ctx.emin = MPFR_EMIN_MIN; result->ctx.subnormalize = 0; result->ctx.underflow = 0; result->ctx.overflow = 0; diff --git a/src/gmpy2_context.h b/src/gmpy2_context.h index 6fa82c20..38d5f34d 100644 --- a/src/gmpy2_context.h +++ b/src/gmpy2_context.h @@ -79,6 +79,9 @@ static PyTypeObject CTXT_Type; #define GET_IMAG_ROUND(c) ((c->ctx.imag_round==GMPY_DEFAULT)?GET_REAL_ROUND(c):c->ctx.imag_round) #define GET_MPC_ROUND(c) (MPC_RND(GET_REAL_ROUND(c), GET_IMAG_ROUND(c))) +#define GET_EMIN(c) (c->ctx.emin) +#define GET_EMAX(c) (c->ctx.emax) + #define GET_DIV_MODE(c) (c->ctx.rational_division) #define GET_THREAD_MODE(c) (c->ctx.allow_release_gil)