/* Rmpc_get_max_prec - return the maximum precision of two mpc_t. * * Reads in the precision used for storing the two provided mpc_t * variables and stores the maximum of the real and imaginary * precision through the provided pointers. * * Args: * real_prec: Pointer to store the necessary precision for real part. * imag_prec: Pointer to store the necessary precision for imaginary part. * z1: An mpc_t * z2: An mpc_t * Return value: * None. */ static void Rmpc_get_max_prec(mpfr_prec_t *real_prec, mpfr_prec_t *imag_prec, mpc_t z1, mpc_t z2) { mpfr_prec_t rp1, ip1, rp2, ip2; mpc_get_prec2(&rp1, &ip1, z1); mpc_get_prec2(&rp2, &ip2, z2); *real_prec = max(rp1, rp2); *imag_prec = max(ip1, ip2); }
static PyObject * GMPy_MPC_Repr_Slot(MPC_Object *self) { PyObject *result, *temp; mpfr_prec_t rbits, ibits; long rprec, iprec; char fmtstr[60]; mpc_get_prec2(&rbits, &ibits, MPC(self)); rprec = (long)(log10(2) * (double)rbits) + 2; iprec = (long)(log10(2) * (double)ibits) + 2; if (rbits != DBL_MANT_DIG || ibits !=DBL_MANT_DIG) sprintf(fmtstr, "mpc('{0:.%ld.%ldg}',(%ld,%ld))", rprec, iprec, rbits, ibits); else sprintf(fmtstr, "mpc('{0:.%ld.%ldg}')", rprec, iprec); temp = Py_BuildValue("s", fmtstr); if (!temp) return NULL; result = PyObject_CallMethod(temp, "format", "O", self); Py_DECREF(temp); return result; }
static PyObject * GMPy_MPC_GetPrec_Attrib(MPC_Object *self, void *closure) { mpfr_prec_t rprec = 0, iprec = 0; mpc_get_prec2(&rprec, &iprec, self->c); return Py_BuildValue("(nn)", rprec, iprec); }
/* R_mpc_get_prec - Return precision used for an MPC S3 object. * * Args: * ptr - An MPC S3 object. * Returns: * Vector of length two for real and imaginary precision bits for MPC. */ SEXP R_mpc_get_prec(SEXP ptr) { mpc_ptr z = (mpc_ptr)R_ExternalPtrAddr(ptr); SEXP retVal; if (z) { PROTECT(retVal = Rf_allocVector(INTSXP, 2)); mpfr_prec_t real_prec, imag_prec; mpc_get_prec2(&real_prec, &imag_prec, z); INTEGER(retVal)[0] = real_prec; INTEGER(retVal)[1] = imag_prec; UNPROTECT(1); return retVal; } return R_NilValue; }