SEXP R_mpc_arg(SEXP e1) { mpfr_t x; if (Rf_inherits(e1, "mpc")) { mpc_t *z1 = (mpc_t *)R_ExternalPtrAddr(e1); mpc_arg(x, *z1, GMP_RNDN); if (mpfr_fits_sint_p(x, GMP_RNDN)) { return Rf_ScalarReal(mpfr_get_d(x, GMP_RNDN)); } else { Rf_error("Arg doesn't fit in numeric."); } } else { Rf_error("Invalid operand for MPC log."); } return R_NilValue; /* Not reached */ }
static PyObject * GMPy_Complex_Phase(PyObject *x, CTXT_Object *context) { MPFR_Object *result; MPC_Object *tempx; CHECK_CONTEXT(context) result = GMPy_MPFR_New(0, context); tempx = GMPy_MPC_From_Complex(x, 1, 1, context); if (!result || !tempx) { return NULL; } result->rc = mpc_arg(result->f, tempx->c, GET_MPFR_ROUND(context)); Py_DECREF((PyObject*)tempx); GMPY_MPFR_CLEANUP(result, context, "phase()"); return (PyObject*)result; }