P is for Practical | |
PerlMonks |
Re: Converting Math::MPFR to Math::GMPqby syphilis (Archbishop) |
on Dec 28, 2015 at 13:08 UTC ( [id://1151260]=note: print w/replies, xml ) | Need Help?? |
So far, I tried converting Math::MPFR to Math::GMPf, then Math::GMPf to Math::GMPq, which works correctly I think that's about the best you can do - ie, I can't spot anything better. The mpfr library provides direct conversion to mpf_t and mpz_t types (using the mpfr_get_f and mpfr_get_z functions), but the mpfr_get_q function is not there - and hence no Rmpfr_get_q function in Math::MPFR. It would be nice to avoid the overhead of having to load Math::GMPf but, other than that, I think your conversion should be working quite efficiently. For 128 bits of precision, the value of the mpfr_t and mpf_t will be exactly equivalent, and the final mpq_t will be an exact representation of that floating point value. Belated update: That last statement of mine is poorly thought out - the value of the mpfr_t and mpf_t will be exactly equivalent if the precision allocated to the mpfr_t equals the precision allocated to the mpf_t (irrespective of whether the precision is 128 or not). Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|