I installed gmp and mpfr on my environment. Now I can successfully
#include <gmpxx.h>
#include <mpfr.h>
#include <mpf2mpfr.h>
Now, say that I initialize an mpf_class with some value:
mpf_class x = 0.73;
How can I use mpfr to get the sin of this number? I just need an mpf_class in, an mpf_class out. Something like:
mpf_class y = sin(x)
Which obviously doesn't work. I noticed that there is a mpfr_sin function, which I called like this:
mpfr_sin(x, y, MPFR_RNDN);
But that didn't work as well. So what am I supposed to do? Am I doing something wrong?
Thank you
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 includempf2mpfr.h
beforegmpxx.h
. However, the file does not translate everything. The following lets it compile in C++03 (as long as you don't convert tompq_class
):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 includinggmpxx.h
.There are mostly two ways to solve this and both start with removing
mpf2mpfr.h
. The first one is to create a temporarympfr_t
: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.