Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76129 - in sandbox/big_number: boost/multiprecision libs/multiprecision/test
From: john_at_[hidden]
Date: 2011-12-24 06:59:26


Author: johnmaddock
Date: 2011-12-24 06:59:25 EST (Sat, 24 Dec 2011)
New Revision: 76129
URL: http://svn.boost.org/trac/boost/changeset/76129

Log:
Fix File IO and string conversion for rational_adapter, and update tests accordingly.
Text files modified:
   sandbox/big_number/boost/multiprecision/rational_adapter.hpp | 32 ++++++++++++++++++++++++++++++--
   sandbox/big_number/libs/multiprecision/test/test_rational_io.cpp | 3 +++
   2 files changed, 33 insertions(+), 2 deletions(-)

Modified: sandbox/big_number/boost/multiprecision/rational_adapter.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/rational_adapter.hpp (original)
+++ sandbox/big_number/boost/multiprecision/rational_adapter.hpp 2011-12-24 06:59:25 EST (Sat, 24 Dec 2011)
@@ -50,7 +50,35 @@
    }
    rational_adapter& operator = (const char* s)
    {
- m_value = s;
+ std::string s1;
+ multiprecision::mp_number<IntBackend> v1, v2;
+ char c;
+ bool have_hex = false;
+
+ while((0 != (c = *s)) && (c == 'x' || c == 'X' || c == '-' || c == '+' || (c >= '0' && c <= '9') || (have_hex && (c >= 'a' && c <= 'f')) || (have_hex && (c >= 'A' && c <= 'F'))))
+ {
+ if(c == 'x' || c == 'X')
+ have_hex = true;
+ s1.append(1, c);
+ ++s;
+ }
+ v1 = s1;
+ s1.erase();
+ if(c == '/')
+ {
+ ++s;
+ while((0 != (c = *s)) && (c == 'x' || c == 'X' || c == '-' || c == '+' || (c >= '0' && c <= '9') || (have_hex && (c >= 'a' && c <= 'f')) || (have_hex && (c >= 'A' && c <= 'F'))))
+ {
+ if(c == 'x' || c == 'X')
+ have_hex = true;
+ s1.append(1, c);
+ ++s;
+ }
+ v2 = s1;
+ }
+ else
+ v2 = 1;
+ data().assign(v1, v2);
       return *this;
    }
    void swap(rational_adapter& o)
@@ -65,7 +93,7 @@
       std::string result = data().numerator().str(digits, f);
       if(data().denominator() != 1)
       {
- result.append(1, ',');
+ result.append(1, '/');
          result.append(data().denominator().str(digits, f));
       }
       return result;

Modified: sandbox/big_number/libs/multiprecision/test/test_rational_io.cpp
==============================================================================
--- sandbox/big_number/libs/multiprecision/test/test_rational_io.cpp (original)
+++ sandbox/big_number/libs/multiprecision/test/test_rational_io.cpp 2011-12-24 06:59:25 EST (Sat, 24 Dec 2011)
@@ -33,6 +33,7 @@
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/rational.hpp>
+#include <boost/multiprecision/rational_adapter.hpp>
 #include "test.hpp"
 #include <iostream>
 #include <iomanip>
@@ -122,9 +123,11 @@
 #ifdef TEST_MPQ
    test_round_trip<boost::multiprecision::mpq_rational>();
    test_round_trip<boost::rational<boost::multiprecision::mpz_int> >();
+ test_round_trip<boost::multiprecision::mp_number<boost::multiprecision::rational_adapter<boost::multiprecision::gmp_int> > >();
 #endif
 #ifdef TEST_TOMMATH
    test_round_trip<boost::rational<boost::multiprecision::mp_int> >();
+ test_round_trip<boost::multiprecision::mp_number<boost::multiprecision::rational_adapter<boost::multiprecision::tommath_int> > >();
 #endif
    return boost::report_errors();
 }


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