static PyObject * Pympany_binary(PyObject *self, PyObject *other) { if (self && Pympz_Check(self)) return Pympz2binary((PympzObject*)self); else if(self && Pyxmpz_Check(self)) return Pyxmpz2binary((PyxmpzObject*)self); else if(self && Pympq_Check(self)) return Pympq2binary((PympqObject*)self); #ifdef WITHMPFR else if(self && Pympfr_Check(self)) return Pympfr2binary((PympfrObject*)self); #endif else if(Pympz_Check(other)) return Pympz2binary((PympzObject*)other); else if(Pyxmpz_Check(other)) return Pyxmpz2binary((PyxmpzObject*)other); else if(Pympq_Check(other)) return Pympq2binary((PympqObject*)other); #ifdef WITHMPFR else if(Pympfr_Check(other)) return Pympfr2binary((PympfrObject*)other); #endif TYPE_ERROR("binary() requires a gmpy2 object as argument"); return NULL; }
static PyObject * Pympany_copy(PyObject *self, PyObject *other) { if (self && Pympz_Check(self)) return (PyObject*)Pympz2Pympz(self); else if (self && Pyxmpz_Check(self)) return (PyObject*)Pyxmpz2Pyxmpz(self); else if (self && Pympq_Check(self)) return (PyObject*)Pympq2Pympq(self); #ifdef WITHMPFR else if (self && Pympfr_Check(self)) return (PyObject*)Pympfr2Pympfr(self, 0); #endif else if (Pympz_Check(other)) return (PyObject*)Pympz2Pympz(other); else if (Pyxmpz_Check(other)) return (PyObject*)Pyxmpz2Pyxmpz(other); else if (Pympq_Check(other)) return (PyObject*)Pympq2Pympq(other); #ifdef WITHMPFR else if (Pympfr_Check(other)) return (PyObject*)Pympfr2Pympfr(other, 0); #endif TYPE_ERROR("_copy() requires a gmpy2 object as argument"); return NULL; }
static PyObject * Pyxmpz_inplace_pow(PyObject *in_b, PyObject *in_e, PyObject *in_m) { PympzObject *e = 0; mpir_ui el; if (!Pyxmpz_Check(in_b)) { PyErr_SetString(PyExc_TypeError, "base must be an Integer"); return NULL; } if (in_m != Py_None) { SYSTEM_ERROR("modulo not expected"); return NULL; } e = Pympz_From_Integer(in_e); if (!e) { TYPE_ERROR("expected an integer exponent"); return NULL; } if (mpz_sgn(e->z) < 0) { VALUE_ERROR("xmpz.pow with negative power"); Py_DECREF((PyObject*)e); return NULL; } if (!mpz_fits_ui_p(e->z)) { VALUE_ERROR("xmpz.pow outrageous exponent"); Py_DECREF((PyObject*)e); return NULL; } el = mpz_get_ui(e->z); mpz_pow_ui(Pyxmpz_AS_MPZ(in_b), Pyxmpz_AS_MPZ(in_b), el); Py_DECREF((PyObject*)e); Py_INCREF((PyObject*)in_b); return (PyObject*)in_b; }
static int isOne(PyObject* obj) { int overflow = 0; long temp; if (!obj) return 1; if (Pympq_Check(obj)) { return (0==mpz_cmp_ui(mpq_denref(Pympq_AS_MPQ(obj)),1)) && (0==mpz_cmp_ui(mpq_numref(Pympq_AS_MPQ(obj)),1)); } else if (Pympz_Check(obj)) { return 0==mpz_cmp_ui(Pympz_AS_MPZ(obj),1); } else if (Pyxmpz_Check(obj)) { return 0==mpz_cmp_ui(Pyxmpz_AS_MPZ(obj),1); #ifdef PY2 } else if (PyInt_Check(obj)) { return PyInt_AS_LONG(obj)==1; #endif } #ifdef WITHMPFR else if (Pympfr_Check(obj)) { return mpfr_get_d(Pympfr_AS_MPFR(obj), context->ctx.mpfr_round)==1.0; } #endif else if (PyFloat_Check(obj)) { return PyFloat_AS_DOUBLE(obj)==1.0; } else if (PyLong_Check(obj)) { temp = PyLong_AsLongAndOverflow(obj, &overflow); if (!overflow && temp == 1) return 1; else return 0; } return 0; }