[Mplapack-devel] mpcomplex.h: lost precision in extraction of real and imag parts
Status: Pre-Alpha
Brought to you by:
nakatamaho
From: Edwin H. <ew...@st...> - 2016-05-29 00:53:40
|
Hello, The code for real() and imag() in "mpcomplex.h", starting from line 141: mpreal real() { mpreal tmp; tmp = mpc_realref(mpc); return tmp; } results in lost precision if mpc has higher precision than the default used for tmp. For example, the following code: #include <mpcomplex.h> using namespace mpfr; int main(void) { const mp_prec_t prec = 256; mpreal pi(0.0, prec, MPFR_RNDN); pi = const_pi(prec, MPFR_RNDN); mpfr_printf("pi, mpreal:\t%.60Rf\n", mpfr_ptr(pi)); mpcomplex pi_complex(0.0, prec, prec, MPC_RNDNN); pi_complex = pi; mpfr_printf("pi, mpcomplex:\t%.60Rf\n", mpfr_ptr(pi_complex.real())); return 0; } gives this output: pi, mpreal: 3.141592653589793238462643383279502884197169399375105820974945 pi, mpcomplex: 3.141592653589793115997963468544185161590576171875000000000000 I believe this may be resolved without any negative side effects by this simplification: mpreal real() { return mpc_realref(mpc); } and likewise for imag(). Best, Edwin |