Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75277 - sandbox/big_number/boost/multiprecision
From: john_at_[hidden]
Date: 2011-11-02 13:15:47


Author: johnmaddock
Date: 2011-11-02 13:15:46 EDT (Wed, 02 Nov 2011)
New Revision: 75277
URL: http://svn.boost.org/trac/boost/changeset/75277

Log:
Add mpfr inter-conversions.
Fix numerator/denominator for rational types.
Text files modified:
   sandbox/big_number/boost/multiprecision/gmp.hpp | 10 +
   sandbox/big_number/boost/multiprecision/mpfr.hpp | 169 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 175 insertions(+), 4 deletions(-)

Modified: sandbox/big_number/boost/multiprecision/gmp.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/gmp.hpp (original)
+++ sandbox/big_number/boost/multiprecision/gmp.hpp 2011-11-02 13:15:46 EDT (Wed, 02 Nov 2011)
@@ -1510,13 +1510,15 @@
 
 inline mp_number<gmp_int> numerator(const mp_number<gmp_rational>& val)
 {
- const __mpz_struct* pz = (mpq_numref(val.backend().data()));
- return mp_number<gmp_int>((mpz_t&)pz);
+ mp_number<gmp_int> result;
+ mpz_set(result.backend().data(), (mpq_numref(val.backend().data())));
+ return result;
 }
 inline mp_number<gmp_int> denominator(const mp_number<gmp_rational>& val)
 {
- const __mpz_struct* pz = mpq_denref(val.backend().data());
- return mp_number<gmp_int>((mpz_t&)pz);
+ mp_number<gmp_int> result;
+ mpz_set(result.backend().data(), (mpq_denref(val.backend().data())));
+ return result;
 }
 
 inline void add(gmp_rational& t, const gmp_rational& o)

Modified: sandbox/big_number/boost/multiprecision/mpfr.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/mpfr.hpp (original)
+++ sandbox/big_number/boost/multiprecision/mpfr.hpp 2011-11-02 13:15:46 EDT (Wed, 02 Nov 2011)
@@ -7,6 +7,7 @@
 #define BOOST_MATH_BN_MPFR_HPP
 
 #include <boost/multiprecision/mp_number.hpp>
+#include <boost/multiprecision/gmp.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/lexical_cast.hpp>
@@ -244,6 +245,48 @@
 #ifndef BOOST_NO_RVALUE_REFERENCES
    mpfr_float_backend(mpfr_float_backend&& o) : detail::mpfr_float_imp<digits10>(o) {}
 #endif
+ template <unsigned D>
+ mpfr_float_backend(const mpfr_float_backend<D>& val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set(this->m_data, val.data(), GMP_RNDN);
+ }
+ template <unsigned D>
+ mpfr_float_backend(const gmp_float<D>& val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
+ }
+ mpfr_float_backend(const gmp_int& val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
+ }
+ mpfr_float_backend(const gmp_rational& val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
+ }
+ mpfr_float_backend(mpfr_t val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set(this->m_data, val, GMP_RNDN);
+ }
+ mpfr_float_backend(mpf_t val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_f(this->m_data, val, GMP_RNDN);
+ }
+ mpfr_float_backend(mpz_t val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_z(this->m_data, val, GMP_RNDN);
+ }
+ mpfr_float_backend(mpq_t val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_q(this->m_data, val, GMP_RNDN);
+ }
    mpfr_float_backend& operator=(const mpfr_float_backend& o)
    {
       *static_cast<detail::mpfr_float_imp<digits10>*>(this) = static_cast<detail::mpfr_float_imp<digits10> const&>(o);
@@ -262,6 +305,48 @@
       *static_cast<detail::mpfr_float_imp<digits10>*>(this) = v;
       return *this;
    }
+ mpfr_float_backend& operator=(const mpfr_t& val)
+ {
+ mpfr_set(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const mpf_t& val)
+ {
+ mpfr_set_f(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const mpz_t& val)
+ {
+ mpfr_set_z(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const mpq_t& val)
+ {
+ mpfr_set_q(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ template <unsigned D>
+ mpfr_float_backend& operator=(const mpfr_float_backend<D>& val)
+ {
+ mpfr_set(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
+ template <unsigned D>
+ mpfr_float_backend& operator=(const gmp_float<D>& val)
+ {
+ mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const gmp_int& val)
+ {
+ mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const gmp_rational& val)
+ {
+ mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
 };
 
 template <>
@@ -275,6 +360,26 @@
    {
       mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
    }
+ mpfr_float_backend(mpfr_t val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set(this->m_data, val, GMP_RNDN);
+ }
+ mpfr_float_backend(mpf_t val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set_f(this->m_data, val, GMP_RNDN);
+ }
+ mpfr_float_backend(mpz_t val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set_z(this->m_data, val, GMP_RNDN);
+ }
+ mpfr_float_backend(mpq_t val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set_q(this->m_data, val, GMP_RNDN);
+ }
    mpfr_float_backend(const mpfr_float_backend& o) : detail::mpfr_float_imp<0>(o) {}
 #ifndef BOOST_NO_RVALUE_REFERENCES
    mpfr_float_backend(mpfr_float_backend&& o) : detail::mpfr_float_imp<0>(o) {}
@@ -284,6 +389,28 @@
       mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
       *this = o;
    }
+ template <unsigned D>
+ mpfr_float_backend(const mpfr_float_backend<D>& val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set(this->m_data, val.data(), GMP_RNDN);
+ }
+ template <unsigned D>
+ mpfr_float_backend(const gmp_float<D>& val)
+ {
+ mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L);
+ mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
+ }
+ mpfr_float_backend(const gmp_int& val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
+ }
+ mpfr_float_backend(const gmp_rational& val)
+ {
+ mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L);
+ mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
+ }
 
    mpfr_float_backend& operator=(const mpfr_float_backend& o)
    {
@@ -303,6 +430,48 @@
       *static_cast<detail::mpfr_float_imp<0>*>(this) = v;
       return *this;
    }
+ mpfr_float_backend& operator=(const mpfr_t& val)
+ {
+ mpfr_set(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const mpf_t& val)
+ {
+ mpfr_set_f(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const mpz_t& val)
+ {
+ mpfr_set_z(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const mpq_t& val)
+ {
+ mpfr_set_q(this->m_data, val, GMP_RNDN);
+ return *this;
+ }
+ template <unsigned D>
+ mpfr_float_backend& operator=(const mpfr_float_backend<D>& val)
+ {
+ mpfr_set(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
+ template <unsigned D>
+ mpfr_float_backend& operator=(const gmp_float<D>& val)
+ {
+ mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const gmp_int& val)
+ {
+ mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
+ mpfr_float_backend& operator=(const gmp_rational& val)
+ {
+ mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
+ return *this;
+ }
    static unsigned default_precision()
    {
       return get_default_precision();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk