Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77979 - in sandbox/fixed_point: boost/fixed_point libs/fixed_point/example
From: vicente.botet_at_[hidden]
Date: 2012-04-14 16:37:43


Author: viboes
Date: 2012-04-14 16:37:42 EDT (Sat, 14 Apr 2012)
New Revision: 77979
URL: http://svn.boost.org/trac/boost/changeset/77979

Log:
FixedPoint: Added operator++/--
Text files modified:
   sandbox/fixed_point/boost/fixed_point/number.hpp | 272 ++++++++++++++++++++++-----------------
   sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp | 251 ++++++++++++++++++++++++++++++++----
   2 files changed, 369 insertions(+), 154 deletions(-)

Modified: sandbox/fixed_point/boost/fixed_point/number.hpp
==============================================================================
--- sandbox/fixed_point/boost/fixed_point/number.hpp (original)
+++ sandbox/fixed_point/boost/fixed_point/number.hpp 2012-04-14 16:37:42 EDT (Sat, 14 Apr 2012)
@@ -543,75 +543,75 @@
 
       };
 
- template <int Range, int Resolution, typename Optimization=optimization::space>
- class signed_uniform_quantizer
- {
- BOOST_MPL_ASSERT_MSG(Range>=Resolution, RANGE_MUST_BE_GREATER_EQUAL_THAN_RESOLUTION, (mpl::int_<Range>,mpl::int_<Resolution>));
- public:
-
- //! The underlying integer type
- typedef typename Optimization::template signed_integer_type<Range,Resolution>::type underlying_type;
-
- // name the template parameters
- BOOST_STATIC_CONSTEXPR int range_exp = Range;
- BOOST_STATIC_CONSTEXPR int resolution_exp = Resolution;
- BOOST_STATIC_CONSTEXPR int digits = range_exp-resolution_exp+1;
-
- typedef Optimization optimization_type;
-
- BOOST_STATIC_CONSTEXPR underlying_type min_index = detail::signed_integer_traits<underlying_type,Range,Resolution>::const_min;
- BOOST_STATIC_CONSTEXPR underlying_type max_index = detail::signed_integer_traits<underlying_type,Range,Resolution>::const_max;
-
- //! conversion factor.
- template <typename FP>
- static FP factor()
- {
- if (Resolution>=0) return FP(1 << Resolution);
- else return FP(1)/(1 << -Resolution);
- }
- template <typename FP>
- static underlying_type integer_part(FP x)
- {
- return underlying_type(floor(x));
- }
- };
-
-
- template <typename Final, int Range, int Resolution, typename Rounding=round::negative, typename Overflow=overflow::exception,
- typename Optimization=optimization::space
- >
- class signed_quantizer : public signed_uniform_quantizer<Range,Resolution,Optimization>
- {
- typedef signed_uniform_quantizer<Range,Resolution,Optimization> base_type;
- public:
- typedef typename base_type::underlying_type underlying_type;
- BOOST_STATIC_CONSTEXPR underlying_type min_index = base_type::const_min;
- BOOST_STATIC_CONSTEXPR underlying_type max_index = base_type::const_max;
-
- template <typename FP>
- static FP reconstruct(underlying_type k)
- {
- BOOST_ASSERT(min_index <= k && k <= max_index);
-
- return Rounding::reconstruct(k, base_type::template factor<FP>());
- }
- template <typename FP>
- static underlying_type classify(FP x)
- {
- if (x<Final::min().template as<FP>()) {
- return Overflow::on_negative_overflow(min_index,x);
- }
- if (x>Final::max().template as<FP>()) {
- return Overflow::on_positive_overflow(max_index,x);
- }
- return Rounding::classify(x, base_type::template factor<FP>());
- }
- template <typename FP>
- static Final cast(FP x)
- {
- fixed_point::number_cast<Final>(x);
- }
- };
+// template <int Range, int Resolution, typename Optimization=optimization::space>
+// class signed_uniform_quantizer
+// {
+// BOOST_MPL_ASSERT_MSG(Range>=Resolution, RANGE_MUST_BE_GREATER_EQUAL_THAN_RESOLUTION, (mpl::int_<Range>,mpl::int_<Resolution>));
+// public:
+//
+// //! The underlying integer type
+// typedef typename Optimization::template signed_integer_type<Range,Resolution>::type underlying_type;
+//
+// // name the template parameters
+// BOOST_STATIC_CONSTEXPR int range_exp = Range;
+// BOOST_STATIC_CONSTEXPR int resolution_exp = Resolution;
+// BOOST_STATIC_CONSTEXPR int digits = range_exp-resolution_exp+1;
+//
+// typedef Optimization optimization_type;
+//
+// BOOST_STATIC_CONSTEXPR underlying_type min_index = detail::signed_integer_traits<underlying_type,Range,Resolution>::const_min;
+// BOOST_STATIC_CONSTEXPR underlying_type max_index = detail::signed_integer_traits<underlying_type,Range,Resolution>::const_max;
+//
+// //! conversion factor.
+// template <typename FP>
+// static FP factor()
+// {
+// if (Resolution>=0) return FP(1 << Resolution);
+// else return FP(1)/(1 << -Resolution);
+// }
+// template <typename FP>
+// static underlying_type integer_part(FP x)
+// {
+// return underlying_type(std::floor(x));
+// }
+// };
+//
+//
+// template <typename Final, int Range, int Resolution, typename Rounding=round::negative, typename Overflow=overflow::exception,
+// typename Optimization=optimization::space
+// >
+// class signed_quantizer : public signed_uniform_quantizer<Range,Resolution,Optimization>
+// {
+// typedef signed_uniform_quantizer<Range,Resolution,Optimization> base_type;
+// public:
+// typedef typename base_type::underlying_type underlying_type;
+// BOOST_STATIC_CONSTEXPR underlying_type min_index = base_type::const_min;
+// BOOST_STATIC_CONSTEXPR underlying_type max_index = base_type::const_max;
+//
+// template <typename FP>
+// static FP reconstruct(underlying_type k)
+// {
+// BOOST_ASSERT(min_index <= k && k <= max_index);
+//
+// return Rounding::reconstruct(k, base_type::template factor<FP>());
+// }
+// template <typename FP>
+// static underlying_type classify(FP x)
+// {
+// if (x<Final::min().template as<FP>()) {
+// return Overflow::on_negative_overflow(min_index,x);
+// }
+// if (x>Final::max().template as<FP>()) {
+// return Overflow::on_positive_overflow(max_index,x);
+// }
+// return Rounding::classify(x, base_type::template factor<FP>());
+// }
+// template <typename FP>
+// static Final cast(FP x)
+// {
+// fixed_point::number_cast<Final>(x);
+// }
+// };
 
       template <
         typename From,
@@ -1584,6 +1584,11 @@
       {
         return reconstruct<FP>(this->value_);
       }
+ //! explicit conversion to int.
+ int as_int() const
+ {
+ return detail::shift_right<-Resolution>(value_);
+ }
       //! explicit conversion to float.
       float as_float() const
       {
@@ -1604,6 +1609,11 @@
 
 #ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
       //! explicit conversion to float.
+ explicit operator int() const
+ {
+ return as_int();
+ }
+ //! explicit conversion to float.
       explicit operator float() const
       {
         return as<float>();
@@ -1620,8 +1630,6 @@
       }
 #endif
 
-#if 1
-
       template <typename FP>
       static underlying_type integer_part(FP x)
       {
@@ -1652,8 +1660,8 @@
         return integer_part(x/factor<FP>());
       }
 
- //! implicit conversion from float
- signed_number(int x) : value_(classify(x))
+ //! implicit conversion from int
+ signed_number(int x) : value_(detail::shift_left<-Resolution>(x))
       {}
       //! implicit conversion from float
       signed_number(float x) : value_(classify(x))
@@ -1665,9 +1673,6 @@
       signed_number(long double x) : value_(classify(x))
       {}
 
-
-#endif
-
       // arithmetic
 
       /**
@@ -1685,46 +1690,48 @@
         // As the range is symmetric the type is preserved
         return signed_number(index(-value_));
       }
-#if 0
- signed_number& operator++(
- typename boost::enable_if <
- is_equal<mpl::int_<Resolution>, mpl::int_<0> >
- >::type* = 0
- )
+
+ /**
+ * @Effects Pre-increase this instance as if <c>*this+=1</c>
+ * @Returns this instance.
+ */
+ signed_number& operator++()
       {
- ++value_;
+ *this+=1;
         return *this;
       }
- signed_number operator++(int
- , typename boost::enable_if <
- is_equal<mpl::int_<Resolution>, mpl::int_<0> >
- >::type* = 0
- )
+
+ /**
+ * @Effects Post-increase this instance as if <c>*this+=1</c>
+ * @Returns a copy of this instance before increasing it.
+ */
+ signed_number operator++(int)
       {
         signed_number tmp=*this;
- ++value_;
+ *this+=1;
         return tmp;
       }
- signed_number& operator--(
- typename boost::enable_if <
- is_equal<mpl::int_<Resolution>, mpl::int_<0> >
- >::type* = 0
- )
+
+ /**
+ * @Effects Pre-decrease this instance as if <c>*this-=1</c>
+ * @Returns this instance.
+ */
+ signed_number& operator--()
       {
- --value_;
+ *this-=1;
         return *this;
       }
- signed_number operator--(int
- , typename boost::enable_if <
- is_equal<mpl::int_<Resolution>, mpl::int_<0> >
- >::type* = 0
- )
+
+ /**
+ * @Effects Post-decrease this instance as if <c>*this-=1</c>
+ * @Returns a copy of this instance before decreasing it.
+ */
+ signed_number operator--(int)
       {
         signed_number tmp=*this;
- --value_;
+ *this-=1;
         return tmp;
       }
-#endif
 
       /**
        * @Effects As if <c>number_cast<signed_number>(*this+rhs)</c>
@@ -1930,11 +1937,6 @@
       template <typename UT>
       explicit unsigned_number(index_tag<UT> i) : value_(i.get())
       {
- std::cout << __FILE__ << "[" <<__LINE__<<"] "<< int(i.get()) << std::endl;
- std::cout << __FILE__ << "[" <<__LINE__<<"] "<< int(min_index) << std::endl;
- std::cout << __FILE__ << "[" <<__LINE__<<"] "<< int(max_index) << std::endl;
- std::cout << __FILE__ << "[" <<__LINE__<<"] "<< int(digits) << std::endl;
-
         //BOOST_ASSERT(i.get()>=min_index);
         BOOST_ASSERT(i.get()<=max_index);
       }
@@ -1980,35 +1982,37 @@
         return count() >> resolution_exp;
       }
 
-#if 0
-
       //! conversion factor.
       template <typename FP>
- static FP factor() const
+ static FP factor()
       {
- if (Resolution>=0) return FP(1 << Resolution);
- else return FP(1)/(1 << -Resolution);
+ if (Resolution>=0) return FP(detail::shift_left<Resolution>(1));
+ else return FP(1)/(detail::shift_left<-Resolution>(1));
       }
       template <typename FP>
       static underlying_type integer_part(FP x)
       {
- return underlying_type(floor(x));
+ return underlying_type(std::floor(x));
       }
       template <typename FP>
- static FP reconstruct(underlying_type index) const
+ static FP reconstruct(underlying_type k)
       {
         BOOST_ASSERT(min_index <= k && k <= max_index);
 
         return k*factor<FP>();
       }
       template <typename FP>
- static underlying_type classify(FP x) const
+ static underlying_type classify(FP x)
       {
         if (x<min().as<FP>()) return min_index;
         if (x>max().as<FP>()) return max_index;
- return integer_part(x/factor());
+ return integer_part(x/factor<FP>());
       }
 
+ //! implicit conversion from int
+ unsigned_number(unsigned int x) : value_(detail::shift_left<-Resolution>(x))
+ {}
+
       //! implicit conversion from float
       unsigned_number(float x) : value_(classify(x))
       {}
@@ -2025,6 +2029,11 @@
       {
         return reconstruct<FP>(this->value_);
       }
+ //! explicit conversion to int.
+ int as_unsigned_int() const
+ {
+ return detail::shift_right<-Resolution>(value_);
+ }
       //! explicit conversion to float.
       float as_float() const
       {
@@ -2043,7 +2052,11 @@
         return as<long double>();
       }
 
-#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS //! explicit conversion to float.
+ explicit operator unsigned int() const
+ {
+ return as_unsigned_int());
+ }
       //! explicit conversion to float.
       explicit operator float() const
       {
@@ -2060,7 +2073,6 @@
         return as<long double>();
       }
 #endif
-#endif
 
       // arithmetic
 
@@ -2080,26 +2092,42 @@
         return signed_number<Range,Resolution,Rounding,Overflow,Optimization>(index(-value_));
       }
 
+ /**
+ * @Effects Pre-increase this instance as if <c>*this+=1</c>
+ * @Returns this instance.
+ */
       unsigned_number& operator++()
       {
- *this+=1;
+ *this+=1u;
         return *this;
       }
+ /**
+ * @Effects Post-increase this instance as if <c>*this+=1</c>
+ * @Returns a copy of this instance before increasing it.
+ */
       unsigned_number operator++(int)
       {
         unsigned_number tmp=*this;
- *this+=1;
+ *this+=1u;
         return tmp;
       }
+ /**
+ * @Effects Pre-decrease this instance as if <c>*this-=1</c>
+ * @Returns this instance.
+ */
       unsigned_number& operator--()
       {
- *this-=1;
+ *this-=1u;
         return *this;
       }
+ /**
+ * @Effects Post-decrease this instance as if <c>*this-=1</c>
+ * @Returns a copy of this instance before decreasing it.
+ */
       unsigned_number operator--(int)
       {
         unsigned_number tmp=*this;
- --value_;
+ *this-=1u;
         return tmp;
       }
 

Modified: sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp
==============================================================================
--- sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp (original)
+++ sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp 2012-04-14 16:37:42 EDT (Sat, 14 Apr 2012)
@@ -73,12 +73,9 @@
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<1,-32> n1((index(1U)));
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<64,31,round::negative> n2(n1);
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
   }
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -89,9 +86,7 @@
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<9,-1> n1((index(-254)));
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<7,0,round::negative> n2(n1);
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     BOOST_TEST(n2.count()==-127);
   }
   {
@@ -117,6 +112,7 @@
     BOOST_TEST(n2.count()==1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-2> n1((index(1)));
     signed_number<2,-3,round::negative> n2(n1);
     BOOST_TEST(n1.count()==1);
@@ -124,6 +120,7 @@
     BOOST_TEST(n2.count()==2);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-2> n1((index(1)));
     signed_number<2,-3,round::negative> n2;
     n2=n1;
@@ -132,6 +129,7 @@
     BOOST_TEST(n2.count()==2);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<2,-2> n1((index(1)));
     unsigned_number<2,-3,round::negative> n2(n1);
     BOOST_TEST(n1.count()==1);
@@ -139,23 +137,26 @@
     BOOST_TEST(n2.count()==2);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<2,-3> n1((index(1)));
     unsigned_number<2,-2,round::negative> n2(n1);
     BOOST_TEST(n1.count()==1);
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
   }
- // {
- // unsigned_number<2,-3> n1((index(1)));
- // unsigned_number<2,-2,round::negative> n2;
- // n2=n1; // compile must fail as conversion required
- // }
+// {
+// unsigned_number<2,-3> n1((index(1)));
+// unsigned_number<2,-2> n2;
+// n2=n1; // compile must fail as conversion required
+// }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<2,-3> n1((index(1)));
     unsigned_number<2,-2,round::negative> n2;
     n2=number_cast<unsigned_number<2,-2,round::negative> >(n1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(1)));
     signed_number<2,-2,round::negative> n2(n1);
     BOOST_TEST(n1.count()==1);
@@ -163,30 +164,35 @@
     BOOST_TEST(n2.count()==0);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(1)));
     signed_number<2,-2,round::positive> n2(n1);
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(1)));
     signed_number<2,-2,round::truncated> n2(n1);
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(0)));
     signed_number<2,-2,round::negative> n2(n1);
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<2,-3> n1((index(0)));
     unsigned_number<2,-2,round::negative> n2(n1);
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(2)));
     signed_number<2,-2,round::negative> n2(n1);
     BOOST_TEST(n1.count()==2);
@@ -194,6 +200,7 @@
     BOOST_TEST(n2.count()==1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(2)));
     signed_number<2,-2,round::positive> n2(n1);
     BOOST_TEST(n1.count()==2);
@@ -201,6 +208,7 @@
     BOOST_TEST(n2.count()==1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(2)));
     signed_number<2,-2,round::truncated> n2(n1);
     BOOST_TEST(n1.count()==2);
@@ -218,22 +226,19 @@
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(-1)));
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-2,round::positive> n2(n1);
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
   }
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(-1)));
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-2,round::truncated> n2(n1);
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==0);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(-2)));
     signed_number<2,-2,round::negative> n2(n1);
     BOOST_TEST(n1.count()==-2);
@@ -241,29 +246,33 @@
     BOOST_TEST(n2.count()==-1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(-2)));
     signed_number<2,-2,round::positive> n2(n1);
     BOOST_TEST(n1.count()==-2);
- std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==-1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-3> n1((index(-2)));
     signed_number<2,-2,round::truncated> n2(n1);
     BOOST_TEST(n1.count()==-2);
- std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n2.count()==-1);
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-1> n1((index(-7)));
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-1> n1((index(7)));
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<2,-1> n1((index(7)));
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-2> n1((index(15)));
     try {
       signed_number<2,-1> n2(n1);
@@ -271,6 +280,7 @@
     } catch (positive_overflow &) {}
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     unsigned_number<2,-2> n1((index(15)));
     try {
       unsigned_number<2,-1> n2(n1);
@@ -278,6 +288,7 @@
     } catch (positive_overflow &) {}
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<2,-2> n1((index(-15)));
     try {
       signed_number<2,-1> n2(n1);
@@ -285,6 +296,7 @@
     } catch (negative_overflow &) {}
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<3,-1> n1((index(15)));
     try {
       signed_number<2,-1> n2(n1);
@@ -292,6 +304,7 @@
     } catch (positive_overflow &) {}
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<3,-1> n1((index(-15)));
     try {
       signed_number<2,-1> n2(n1);
@@ -299,6 +312,7 @@
     } catch (negative_overflow &) {}
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<3,-2> n1((index(31)));
     try {
       signed_number<2,-1> n2(n1);
@@ -306,12 +320,105 @@
     } catch (positive_overflow &) {}
   }
   {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     signed_number<3,-2> n1((index(-31)));
     try {
       signed_number<2,-1> n2(n1);
       BOOST_TEST(false);
     } catch (negative_overflow &) {}
   }
+ /////////////////////////////////////////////////////////////////
+ // C(int)
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(1);
+ BOOST_TEST(n1.count()==2);
+ BOOST_TEST(n1.as_int()==1);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(-1);
+ BOOST_TEST(n1.count()==-2);
+ BOOST_TEST(n1.as_int()==-1);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1(1U);
+ BOOST_TEST(n1.count()==2);
+ BOOST_TEST(n1.as_unsigned_int()==1U);
+ }
+// {
+// std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+// unsigned_number<4,-1> n1(-1); // compile must fail as ambiguous
+// }
+ /////////////////////////////////////////////////////////////////
+ // C(float)
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(0.5f);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n1.as_float()==0.5f);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(-0.5f);
+ BOOST_TEST(n1.count()==-1);
+ BOOST_TEST(n1.as_float()==-0.5f);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1(0.5f);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n1.as_float()==0.5f);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1(-0.5f);
+ BOOST_TEST(n1.count()==0);
+ BOOST_TEST(n1.as_float()==0.0f);
+ }
+ /////////////////////////////////////////////////////////////////
+ // C(double)
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(0.5);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n1.as_double()==0.5);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(-0.5);
+ BOOST_TEST(n1.count()==-1);
+ BOOST_TEST(n1.as_double()==-0.5);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1(0.5);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n1.as_double()==0.5);
+ }
+ /////////////////////////////////////////////////////////////////
+ // C(long double)
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(0.5l);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n1.as_long_double()==0.5l);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1(-0.5l);
+ BOOST_TEST(n1.count()==-1);
+ BOOST_TEST(n1.as_long_double()==-0.5l);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1(0.5l);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n1.as_long_double()==0.5l);
+ }
+
+ /////////////////////////////////////////////////////////////////
   // unary plus
   {
     signed_number<2,-1> n1((index(7)));
@@ -323,6 +430,7 @@
     unsigned_number<2,-1> n2(+n1);
     BOOST_TEST(n2.count()==3);
   }
+ /////////////////////////////////////////////////////////////////
   // unary minus
   {
     signed_number<2,-1> n1((index(7)));
@@ -338,6 +446,7 @@
     signed_number<2,-1> n3(-n2);
     BOOST_TEST(n3.count()==3);
   }
+ /////////////////////////////////////////////////////////////////
   // plus
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -374,6 +483,7 @@
     signed_number<3,-1> n3 = n1 + n2;
     BOOST_TEST(n3.count()==-14);
   }
+ /////////////////////////////////////////////////////////////////
   // +=
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -382,6 +492,70 @@
     n1+=n2;
     BOOST_TEST(n1.count()==6);
   }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1((index(3)));
+ BOOST_TEST(n1.count()==3);
+ n1+=1.0;
+ BOOST_TEST(n1.count()==5);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1((index(3)));
+ n1+=1;
+ BOOST_TEST(n1.count()==5);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1((index(3)));
+ n1+=1u;
+ BOOST_TEST(n1.count()==5);
+ }
+ /////////////////////////////////////////////////////////////////
+ // ++()
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1((index(3)));
+ ++n1;
+ BOOST_TEST(n1.count()==5);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1((index(3)));
+ ++n1;
+ BOOST_TEST(n1.count()==5);
+ }
+ /////////////////////////////////////////////////////////////////
+ // ++(int)
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1((index(3)));
+ signed_number<4,-1> n2 = n1++;
+ BOOST_TEST(n1.count()==5);
+ BOOST_TEST(n2.count()==3);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1((index(3)));
+ unsigned_number<4,-1> n2 = n1++;
+ BOOST_TEST(n1.count()==5);
+ BOOST_TEST(n2.count()==3);
+ }
+ /////////////////////////////////////////////////////////////////
+ // --()
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<4,-1> n1((index(3)));
+ --n1;
+ BOOST_TEST(n1.count()==1);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<4,-1> n1((index(3)));
+ --n1;
+ BOOST_TEST(n1.count()==1);
+ }
+ /////////////////////////////////////////////////////////////////
   // minus
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -397,6 +571,7 @@
     signed_number<3,-2> n3 = n1 - n2;
     BOOST_TEST(n3.count()==0);
   }
+ /////////////////////////////////////////////////////////////////
   // -=
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -406,6 +581,7 @@
     std::cout << int(n1.count()) << std::endl;
     BOOST_TEST(n1.count()==0);
   }
+ /////////////////////////////////////////////////////////////////
   // multiply
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -440,6 +616,7 @@
     BOOST_TEST(n3.count()==49);
   }
 
+ /////////////////////////////////////////////////////////////////
   // virtual_scale
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -455,6 +632,7 @@
     std::cout << int(n2.count()) << std::endl;
     BOOST_TEST(n1.count()==7);
   }
+ /////////////////////////////////////////////////////////////////
   // scale_up
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -470,6 +648,7 @@
     std::cout << int(n1.count()) << std::endl;
     BOOST_TEST(n1.count()==28);
   }
+ /////////////////////////////////////////////////////////////////
   // scale
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -499,6 +678,7 @@
     std::cout << int(n1.count()) << std::endl;
     BOOST_TEST(n1.count()==1);
   }
+ /////////////////////////////////////////////////////////////////
   // *=
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -516,22 +696,23 @@
     std::cout << int(n1.count()) << std::endl;
     BOOST_TEST(n1.count()==10); // The exact result 21/4 rounds to 10/2.
   }
- // {
- // std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
- // unsigned_number<6,-1, round::truncated> n1((index(7)));
- // signed_number<6,-1, round::truncated> n2((index(3)));
- // n1*=n2; // compile fails
- // std::cout << int(n1.count()) << std::endl;
- // BOOST_TEST(n1.count()==10); // The exact result 21/4 rounds to 10/2.
- // }
- {
- std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
- unsigned_number<6,-1, round::truncated> n1((index(7)));
- signed_number<6,-1, round::truncated> n2((index(3)));
- n1*=number_cast<unsigned_number<6,-1, round::truncated> >(n2); // force cast
- std::cout << int(n1.count()) << std::endl;
- BOOST_TEST(n1.count()==10); // The exact result 21/4 rounds to 10/2.
- }
+// {
+// std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+// unsigned_number<6,-1, round::truncated> n1((index(7)));
+// signed_number<6,-1, round::truncated> n2((index(3)));
+// n1*=n2; // compile fails
+// std::cout << int(n1.count()) << std::endl;
+// BOOST_TEST(n1.count()==10); // The exact result 21/4 rounds to 10/2.
+// }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<6,-1, round::truncated> n1((index(7)));
+ signed_number<6,-1, round::truncated> n2((index(3)));
+ n1*=number_cast<unsigned_number<6,-1, round::truncated> >(n2); // force cast
+ std::cout << int(n1.count()) << std::endl;
+ BOOST_TEST(n1.count()==10); // The exact result 21/4 rounds to 10/2.
+ }
+ /////////////////////////////////////////////////////////////////
   // /=
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -749,6 +930,7 @@
     std::cout << int(n3.count()) << std::endl;
     BOOST_TEST(n3.count()==7*64);
   }
+ /////////////////////////////////////////////////////////////////
   // equal
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -762,6 +944,7 @@
     signed_number<2,-2> n2((index(14)));
     BOOST_TEST(n1==n2);
   }
+ /////////////////////////////////////////////////////////////////
   // not_equal
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -769,6 +952,7 @@
     signed_number<2,-1> n2((index(1)));
     BOOST_TEST(n1!=n2);
   }
+ /////////////////////////////////////////////////////////////////
   // gt
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -776,6 +960,7 @@
     signed_number<2,-1> n2((index(1)));
     BOOST_TEST(n1>n2);
   }
+ /////////////////////////////////////////////////////////////////
   // ge
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -789,6 +974,7 @@
     signed_number<2,-1> n2((index(7)));
     BOOST_TEST(n1>=n2);
   }
+ /////////////////////////////////////////////////////////////////
   // lt
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
@@ -863,6 +1049,7 @@
     std::cout << sizeof(long int) << std::endl;
   }
 
+ /////////////////////////////////////////////////////////////////
   {
     std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
     typedef signed_number<15,-16> fp_15__16; // Signed fixed-point values with 15 bits of integer part


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