$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r85419 - in sandbox/multiprecision.cpp_bin_float: boost/multiprecision libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-08-22 08:35:25
Author: johnmaddock
Date: 2013-08-22 08:35:25 EDT (Thu, 22 Aug 2013)
New Revision: 85419
URL: http://svn.boost.org/trac/boost/changeset/85419
Log:
Change powers on 10 to powers of 5 to reduce memory usage.
Text files modified: 
   sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp             |    25 ++++++++++++++++---------               
   sandbox/multiprecision.cpp_bin_float/libs/multiprecision/test/test_cpp_bin_float_io.cpp |     4 ++++                                    
   2 files changed, 20 insertions(+), 9 deletions(-)
Modified: sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp
==============================================================================
--- sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp	Wed Aug 21 19:24:54 2013	(r85418)
+++ sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp	2013-08-22 08:35:25 EDT (Thu, 22 Aug 2013)	(r85419)
@@ -316,8 +316,9 @@
       else if(decimal_exp >= 0)
       {
          // Nice and simple, the result is an integer...
-         n *= pow(cpp_int(10), decimal_exp);
+         n *= pow(cpp_int(5), decimal_exp);
          exponent() = (int)Bits - 1;
+         exponent() += decimal_exp;
          copy_and_round(*this, n.backend());
          if(ss != sign())
             negate();
@@ -327,9 +328,9 @@
          // Result is the ratio of two integers: we need to organise the
          // division so as to produce at least an N-bit result which we can
          // round according to the remainder.
-         cpp_int d = pow(cpp_int(10), -decimal_exp);
+         cpp_int d = pow(cpp_int(5), -decimal_exp);
          int shift = (int)Bits - msb(n) + msb(d);
-         exponent() = Bits - 1;
+         exponent() = Bits - 1 + decimal_exp;
          if(shift > 0)
          {
             n <<= shift;
@@ -432,24 +433,29 @@
             // to convert our denormalised number to an integer with the right number of digits:
             //
             int power10 = digits_wanted - base10_exp - 1;
+            //
+            // If we calculate 5^power10 rather than 10^power10 we need to move
+            // 2^power10 into /shift/
+            //
+            shift -= power10;
             cpp_int i;
             std::string s;
             int roundup = 0; // 0=no rounding, 1=tie, 2=up
             do
             {
                //
-               // Our integer is: bits() * 2^-shift * 10^power10
+               // Our integer is: bits() * 2^-shift * 5^power10
                //
                i = bits();
                if(shift < 0)
                {
                   i <<= -shift;
                   if(power10 > 0)
-                     i *= pow(cpp_int(10), power10);
+                     i *= pow(cpp_int(5), power10);
                   else if(power10 < 0)
                   {
                      cpp_int r;
-                     cpp_int d = pow(cpp_int(10), -power10);
+                     cpp_int d = pow(cpp_int(5), -power10);
                      divide_qr(i, d, i, r);
                      r <<= 1;
                      int c = r.compare(d);
@@ -464,7 +470,7 @@
                   if(power10 >= 0)
                   {
                      if(power10)
-                        i *= pow(cpp_int(10), power10);
+                        i *= pow(cpp_int(5), power10);
                      if(shift && bit_test(i, shift - 1))
                      {
                         if((int)lsb(i) == shift - 1)
@@ -477,7 +483,7 @@
                   else
                   {
                      cpp_int r;
-                     cpp_int d = pow(cpp_int(10), -power10);
+                     cpp_int d = pow(cpp_int(5), -power10);
                      d <<= shift;
                      divide_qr(i, d, i, r);
                      r <<= 1;
@@ -496,8 +502,9 @@
                {
                   base10_exp += digits_got - digits_wanted;
                   if(fixed)
-                     digits_wanted = digits_got;
+                     digits_wanted = digits_got;  // strange but true.
                   power10 = digits_wanted - base10_exp - 1;
+                  shift = (int)Bits - exponent() - 1 - power10;
                   if(fixed)
                      break;
                   roundup = 0;
Modified: sandbox/multiprecision.cpp_bin_float/libs/multiprecision/test/test_cpp_bin_float_io.cpp
==============================================================================
--- sandbox/multiprecision.cpp_bin_float/libs/multiprecision/test/test_cpp_bin_float_io.cpp	Wed Aug 21 19:24:54 2013	(r85418)
+++ sandbox/multiprecision.cpp_bin_float/libs/multiprecision/test/test_cpp_bin_float_io.cpp	2013-08-22 08:35:25 EDT (Thu, 22 Aug 2013)	(r85419)
@@ -204,6 +204,10 @@
    using namespace boost::multiprecision;
    test<number<cpp_bin_float<113> > >();
    test_round_trip<number<cpp_bin_float<113> > >();
+
+   test<number<cpp_bin_float<53> > >();
+   test_round_trip<number<cpp_bin_float<53> > >();
+
    return boost::report_errors();
 }