Hi
It indeed is almost as easy as this:Is it simply a matter of adding a header file and declare my "MAPM" of "GMP" variable?
You have to make sure that you link the gmp.lib / mapm.lib (libgmp.a / libmapm.a)
libraries to your project:
Visual C++ 6.0: Project --> Settings --> Link --> Object/library modules
gcc: -lgmp -lmapm
Here are two working examples:
gmp:
MAPM:Code:#include "gmp.h" // C++ with operator overloading: gmpxx.h[1] // log, exp, ... : mpfr.h[2] void main(){ mpf_t myMpf_t1,myMpf_t2,myMpf_res; mpf_set_default_prec(512); // minimal precision (in bits) mpf_init(myMpf_t1); mpf_init(myMpf_t2); mpf_init(myMpf_res); mpf_set_d(myMpf_t1,1.2345e260); mpf_set_d(myMpf_t2,2.3456e300); mpf_mul(myMpf_res,myMpf_t1,myMpf_t2); printf("Result exceeds double range: %e\n",mpf_get_d(myMpf_res)); gmp_printf("mpf_t: %.*Fe\n",8,myMpf_res); // 8 digits mpf_clear(myMpf_t1); mpf_clear(myMpf_t2); mpf_clear(myMpf_res); }
MAPM is easier to use, gmp is faster. However, the C++-wrapper of gmpCode:#include "M_APM.h" void main(){ MAPM myMapm_t1,myMapm_t2,myMapm_res; char buf[1024]; m_apm_cpp_precision(64); // minimal precision (in digits!) myMapm_t1=1.2345e260; myMapm_t2=2.3456e300; myMapm_res=myMapm_t1*myMapm_t2; myMapm_res.toString(buf,8); printf("Result exceeds double range: %e\n",atof(buf)); printf("MAPM: %s\n",buf); }
adds to gmp the nice MAPM-like behaviour.
Cheers
[1] http://www.swox.com/gmp/#DOC
[2] http://www.mpfr.org/




Reply With Quote