mpf2mpfr.h
is probably not what you want. It contains plenty of #define
to replace mpf names with mpfr names in everything that follows. If you wanted a chance of having it work in your case, you would have to include mpf2mpfr.h
before gmpxx.h
. However, the file does not translate everything. The following lets it compile in C++03 (as long as you don't convert to mpq_class
):
#include <mpfr.h>
#include <mpf2mpfr.h>
void mpfr_get_q (mpq_ptr, mpfr_srcptr);
#undef mpq_set_f
#define mpq_set_f(x,y) mpfr_get_q(x,y)
#include <gmpxx.h>
int main(){
mpf_class x=.73;
mpf_class y;
mpfr_sin(y.get_mpf_t(),x.get_mpf_t(),MPFR_RNDN);
}
but trying to print with operator<<
will print a pointer instead of the number, for instance. Extra functions provided in C++11 would require more tweaking, it is easier to disable them: #define __GMPXX_USE_CXX11 0
before including gmpxx.h
.
There are mostly two ways to solve this and both start with removing mpf2mpfr.h
. The first one is to create a temporary mpfr_t
:
mpf_class x=.73;
mpf_class y;
mpfr_t xx;
mpfr_t yy;
mpfr_init_set_f(xx, x.get_mpf_t(), MPFR_RNDN);
mpfr_init(yy);
mpfr_sin(yy, xx, MPFR_RNDN);
mpfr_get_f(y.get_mpf_t(), yy, MPFR_RNDN);
The second one is to drop mpf completely and use only mpfr. Its webpage lists 6 C++ wrappers for it, several of which are still maintained.