Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83394 - in sandbox/big_number/boost/multiprecision: . detail
From: e_float_at_[hidden]
Date: 2013-03-10 07:02:43


Author: christopher_kormanyos
Date: 2013-03-10 07:02:41 EDT (Sun, 10 Mar 2013)
New Revision: 83394
URL: http://svn.boost.org/trac/boost/changeset/83394

Log:
Progress with cpp_bin_float.
Added:
   sandbox/big_number/boost/multiprecision/detail/utype_helper.hpp (contents, props changed)
Text files modified:
   sandbox/big_number/boost/multiprecision/cpp_bin_float.hpp | 114 +++++++++++++++++++++++++++------------
   sandbox/big_number/boost/multiprecision/detail/dynamic_array.hpp | 4
   sandbox/big_number/boost/multiprecision/detail/rebind.hpp | 4
   3 files changed, 83 insertions(+), 39 deletions(-)

Modified: sandbox/big_number/boost/multiprecision/cpp_bin_float.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/cpp_bin_float.hpp (original)
+++ sandbox/big_number/boost/multiprecision/cpp_bin_float.hpp 2013-03-10 07:02:41 EDT (Sun, 10 Mar 2013)
@@ -13,6 +13,7 @@
   #include <boost/multiprecision/number.hpp>
   #include <boost/math/policies/policy.hpp>
   #include <boost/multiprecision/detail/dynamic_array.hpp>
+ #include <boost/multiprecision/detail/utype_helper.hpp>
 
   namespace boost { namespace multiprecision {
   namespace backends
@@ -107,33 +108,35 @@
       round_and_truncate();
     }
 
- template<class integer_type>
- cpp_bin_float(integer_type i,
- typename enable_if<is_unsigned<integer_type> >::type* = 0) : my_data (),
- my_exp (static_cast<my_exponent_type>(0)),
- my_neg (false),
- my_fpclass (cpp_bin_float_finite),
- my_precision_in_bits(cpp_bin_float_bits_number)
+ template<class unsigned_integer_type>
+ cpp_bin_float(unsigned_integer_type ui,
+ typename enable_if<is_unsigned<unsigned_integer_type> >::type* = 0) : my_data (),
+ my_exp (static_cast<my_exponent_type>(0)),
+ my_neg (false),
+ my_fpclass (cpp_bin_float_finite),
+ my_precision_in_bits(cpp_bin_float_bits_number)
     {
- from_unsigned_type(i);
+ from_unsigned_integer_type(ui);
       round_and_truncate();
     }
 
- template<class integer_type>
- cpp_bin_float(integer_type i,
- typename enable_if<is_signed<integer_type> >::type* = 0) : my_data (),
- my_exp (static_cast<my_exponent_type>(0)),
- my_neg (i < static_cast<integer_type>(0)),
- my_fpclass (cpp_bin_float_finite),
- my_precision_in_bits(cpp_bin_float_bits_number)
+ template<class signed_integer_type>
+ cpp_bin_float(signed_integer_type si,
+ typename enable_if<is_signed<signed_integer_type> >::type* = 0) : my_data (),
+ my_exp (static_cast<my_exponent_type>(0)),
+ my_neg (si < static_cast<signed_integer_type>(0)),
+ my_fpclass (cpp_bin_float_finite),
+ my_precision_in_bits(cpp_bin_float_bits_number)
     {
+ typedef typename boost::multiprecision::detail::utype_helper<std::numeric_limits<signed_integer_type>::digits>::exact unsigned_integer_type;
+
       if(my_neg)
       {
- from_unsigned_type(static_cast<eval_ops_unsigned_type>(-i));
+ from_unsigned_integer_type<unsigned_integer_type>(-si);
       }
       else
       {
- from_unsigned_type(static_cast<eval_ops_unsigned_type>(i));
+ from_unsigned_integer_type<unsigned_integer_type>(si);
       }
 
       round_and_truncate();
@@ -212,11 +215,11 @@
     {
       if(my_neg)
       {
- from_float_type(static_cast<eval_ops_float_type>(-a));
+ from_float_type(static_cast<float_type>(-a));
       }
       else
       {
- from_float_type(static_cast<eval_ops_float_type>(a));
+ from_float_type(static_cast<float_type>(a));
       }
 
       round_and_truncate();
@@ -267,44 +270,85 @@
                                            my_fpclass (fp_class),
                                            my_precision_in_bits(cpp_bin_float_bits_number) { }
 
- void from_unsigned_type(eval_ops_unsigned_type u)
+ template<class unsigned_integer_type>
+ void from_unsigned_integer_type(unsigned_integer_type u)
     {
- boost::uint_least8_t i = boost::uint_least8_t(0U);
-
- while(u != eval_ops_unsigned_type(0U))
+ if(u <= (std::numeric_limits<short_limb_type>::max)())
       {
- my_data[i] = short_limb_type(u);
- ++i;
- u >>= std::numeric_limits<short_limb_type>::digits;
- my_exp += std::numeric_limits<short_limb_type>::digits;
+ my_data[0U] = short_limb_type(u);
       }
+ else
+ {
+ boost::uint_least8_t i = boost::uint_least8_t(0U);
 
- std::reverse(my_data.begin(), my_data.begin() + i);
+ while(u != unsigned_integer_type(0U))
+ {
+ my_data[i] = short_limb_type(u);
+ ++i;
+ u >>= std::numeric_limits<short_limb_type>::digits;
+ my_exp += std::numeric_limits<short_limb_type>::digits;
+ }
+
+ std::reverse(my_data.begin(), my_data.begin() + i);
+ }
     }
 
- void from_float_type(eval_ops_float_type a)
+ template<class float_type>
+ void from_float_type(float_type a)
     {
       BOOST_MATH_STD_USING // ADL of std names, needed for frexp.
 
       int e2;
- eval_ops_float_type y = frexp(a, &e2);
+ float_type y = frexp(a, &e2);
 
       my_exp = static_cast<my_exponent_type>(e2);
 
- boost::uint_least8_t i = boost::uint_least8_t(0U);
+ int delta_exp = int(my_exp % std::numeric_limits<short_limb_type>::digits);
+
+ int number_of_digits;
 
- for( ; i < boost::uint_least8_t(std::numeric_limits<eval_ops_float_type>::digits / std::numeric_limits<short_limb_type>::digits); ++i)
+ unsigned i = 0U;
+
+ if(delta_exp != 0)
       {
- y *= long_limb_type(long_limb_type(1U) << std::numeric_limits<short_limb_type>::digits);
+ if(delta_exp > 0)
+ {
+ y *= (short_limb_type(1U) << delta_exp);
+ number_of_digits = delta_exp;
+ my_exp -= delta_exp;
+ }
+ else
+ {
+ y *= (short_limb_type(1U) << (std::numeric_limits<short_limb_type>::digits + delta_exp));
+ number_of_digits = std::numeric_limits<short_limb_type>::digits + delta_exp;
+ my_exp -= (std::numeric_limits<short_limb_type>::digits + delta_exp);
+ }
+
         my_data[i] = static_cast<short_limb_type>(y);
         y -= my_data[i];
+ ++i;
+ }
+ else
+ {
+ number_of_digits = 0U;
       }
 
- if((std::numeric_limits<eval_ops_float_type>::digits % std::numeric_limits<short_limb_type>::digits) != 0)
+ while(number_of_digits < boost::uint_least16_t(std::numeric_limits<float_type>::digits))
       {
- y *= long_limb_type(long_limb_type(1U) << (std::numeric_limits<eval_ops_float_type>::digits % std::numeric_limits<short_limb_type>::digits));
+ if((std::numeric_limits<float_type>::digits - number_of_digits) >= std::numeric_limits<short_limb_type>::digits)
+ {
+ y *= long_limb_type(long_limb_type(1U) << std::numeric_limits<short_limb_type>::digits);
+ number_of_digits += std::numeric_limits<short_limb_type>::digits;
+ }
+ else if((std::numeric_limits<float_type>::digits - number_of_digits) > 0)
+ {
+ y *= (short_limb_type(1U) << (std::numeric_limits<float_type>::digits - number_of_digits));
+ number_of_digits += (std::numeric_limits<float_type>::digits - number_of_digits);
+ }
+
         my_data[i] = static_cast<short_limb_type>(y);
         y -= my_data[i];
+ ++i;
       }
     }
 

Modified: sandbox/big_number/boost/multiprecision/detail/dynamic_array.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/detail/dynamic_array.hpp (original)
+++ sandbox/big_number/boost/multiprecision/detail/dynamic_array.hpp 2013-03-10 07:02:41 EDT (Sun, 10 Mar 2013)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Copyright Christopher Kormanyos 2013.
-// Copyright 2012 John Maddock. Distributed under the Boost
+// Copyright 2012 John Maddock.
+// Copyright Christopher Kormanyos 2013. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //

Modified: sandbox/big_number/boost/multiprecision/detail/rebind.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/detail/rebind.hpp (original)
+++ sandbox/big_number/boost/multiprecision/detail/rebind.hpp 2013-03-10 07:02:41 EDT (Sun, 10 Mar 2013)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Copyright Christopher Kormanyos 2013.
-// Copyright 2012 John Maddock. Distributed under the Boost
+// Copyright 2012 John Maddock.
+// Copyright Christopher Kormanyos 2013. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //

Added: sandbox/big_number/boost/multiprecision/detail/utype_helper.hpp
==============================================================================
--- (empty file)
+++ sandbox/big_number/boost/multiprecision/detail/utype_helper.hpp 2013-03-10 07:02:41 EDT (Sun, 10 Mar 2013)
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright 2012 John Maddock.
+// Copyright Christopher Kormanyos 2013. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef BOOST_MP_UTYPE_HELPER_HPP
+ #define BOOST_MP_UTYPE_HELPER_HPP
+
+ #include <boost/cstdint.hpp>
+
+ namespace boost { namespace multiprecision {
+ namespace detail
+ {
+ template<const unsigned> struct utype_helper { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<0U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<1U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<2U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<3U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<4U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<5U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<6U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<7U> { typedef boost::uint8_t exact; };
+ template<> struct utype_helper<8U> { typedef boost::uint8_t exact; };
+
+ template<> struct utype_helper<9U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<10U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<11U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<12U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<13U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<14U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<15U> { typedef boost::uint16_t exact; };
+ template<> struct utype_helper<16U> { typedef boost::uint16_t exact; };
+
+ template<> struct utype_helper<17U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<18U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<19U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<20U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<21U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<22U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<23U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<24U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<25U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<26U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<27U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<28U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<29U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<30U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<31U> { typedef boost::uint32_t exact; };
+ template<> struct utype_helper<32U> { typedef boost::uint32_t exact; };
+
+ template<> struct utype_helper<33U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<34U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<35U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<36U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<37U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<38U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<39U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<40U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<41U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<42U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<43U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<44U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<45U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<46U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<47U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<48U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<49U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<50U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<51U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<52U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<53U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<54U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<55U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<56U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<57U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<58U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<59U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<60U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<61U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<62U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<63U> { typedef boost::uint64_t exact; };
+ template<> struct utype_helper<64U> { typedef boost::uint64_t exact; };
+ } } }
+
+#endif // BOOST_MP_UTYPE_HELPER_HPP


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