Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75520 - in sandbox/big_number: boost/multiprecision libs/multiprecision/test
From: john_at_[hidden]
Date: 2011-11-17 13:08:52


Author: johnmaddock
Date: 2011-11-17 13:08:51 EST (Thu, 17 Nov 2011)
New Revision: 75520
URL: http://svn.boost.org/trac/boost/changeset/75520

Log:
Fix operator>> for mp_number.
Add template inter-conversions on cpp_float.
Adjust precision of test reporting.
Text files modified:
   sandbox/big_number/boost/multiprecision/cpp_float.hpp | 26 ++++++++++++++++++++++++++
   sandbox/big_number/boost/multiprecision/mp_number.hpp | 4 +++-
   sandbox/big_number/libs/multiprecision/test/test.hpp | 2 +-
   3 files changed, 30 insertions(+), 2 deletions(-)

Modified: sandbox/big_number/boost/multiprecision/cpp_float.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/cpp_float.hpp (original)
+++ sandbox/big_number/boost/multiprecision/cpp_float.hpp 2011-11-17 13:08:51 EST (Thu, 17 Nov 2011)
@@ -163,6 +163,18 @@
       fpclass (f.fpclass),
       prec_elem(f.prec_elem) { }
 
+ template <unsigned D>
+ cpp_float(const cpp_float<D>& f) :
+ exp (f.exp),
+ neg (f.neg),
+ fpclass (static_cast<enum_fpclass>(static_cast<int>(f.fpclass))),
+ prec_elem(mp_elem_number)
+ {
+ // TODO: this doesn't round!
+ std::copy_n(f.data.begin(), std::min(f.prec_elem, prec_elem), data.begin());
+ precision(std::min(f.prec_elem, prec_elem));
+ }
+
    template <class F>
    cpp_float(const F val, typename enable_if<is_floating_point<F> >::type* = 0):
       data(),
@@ -299,6 +311,16 @@
       prec_elem = v.prec_elem;
       return *this;
    }
+ template <unsigned D>
+ cpp_float& operator=(const cpp_float<D>& f)
+ {
+ exp = f.exp;
+ neg = f.neg;
+ fpclass = static_cast<enum_fpclass>(static_cast<int>(f.fpclass));
+ std::copy_n(f.data.begin(), std::min(f.prec_elem, prec_elem), data.begin());
+ precision(std::min(f.prec_elem, prec_elem));
+ return *this;
+ }
    cpp_float& operator= (long long v)
    {
       if(v < 0)
@@ -481,6 +503,10 @@
    static boost::uint32_t div_loop_n(boost::uint32_t* const u, boost::uint32_t n, const boost::int32_t p);
 
    bool rd_string(const char* const s);
+
+ template <unsigned D>
+ friend class cpp_float;
+
 };
 
 template <unsigned Digits10>

Modified: sandbox/big_number/boost/multiprecision/mp_number.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/mp_number.hpp (original)
+++ sandbox/big_number/boost/multiprecision/mp_number.hpp 2011-11-17 13:08:51 EST (Thu, 17 Nov 2011)
@@ -1529,7 +1529,9 @@
 template <class Backend>
 inline std::ostream& operator << (std::ostream& os, const mp_number<Backend>& r)
 {
- return os << r.str(static_cast<unsigned>(os.precision(), os.flags() & os.scientific));
+ unsigned d = os.precision();
+ bool b = os.flags() & os.scientific;
+ return os << r.str(d, b);
 }
 
 namespace detail{

Modified: sandbox/big_number/libs/multiprecision/test/test.hpp
==============================================================================
--- sandbox/big_number/libs/multiprecision/test/test.hpp (original)
+++ sandbox/big_number/libs/multiprecision/test/test.hpp 2011-11-17 13:08:51 EST (Thu, 17 Nov 2011)
@@ -116,7 +116,7 @@
    << std::setprecision(digits_of(x)) << std::scientific\
    << "Value of LHS was: " << x << "\n"\
    << "Value of RHS was: " << y << "\n"\
- << std::setprecision(3)\
+ << std::setprecision(5) << std::fixed\
    << "Relative error was: " << relative_error(x, y) << "eps\n"\
    << "Tolerance was: " << tol << "eps" << std::endl;\
    BOOST_MP_REPORT_SEVERITY(severity);\


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