Skip to content

Commit

Permalink
Use default expanded exponent range by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
casevh committed Oct 21, 2024
1 parent 17fb42d commit b144b60
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/gmpy2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/gmpy2_abs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/gmpy2_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/gmpy2_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b144b60

Please sign in to comment.