|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77142 - in sandbox/fixed_point: . boost boost/fixed_point libs libs/fixed_point libs/fixed_point/doc libs/fixed_point/example libs/fixed_point/perf libs/fixed_point/test
From: vicente.botet_at_[hidden]
Date: 2012-02-29 13:11:00
Author: viboes
Date: 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
New Revision: 77142
URL: http://svn.boost.org/trac/boost/changeset/77142
Log:
FixedPoint: Add first POC
Added:
sandbox/fixed_point/
sandbox/fixed_point/Jamfile.v2 (contents, props changed)
sandbox/fixed_point/Jamroot.jam (contents, props changed)
sandbox/fixed_point/README.txt (contents, props changed)
sandbox/fixed_point/boost/
sandbox/fixed_point/boost-build.jam (contents, props changed)
sandbox/fixed_point/boost/fixed_point/
sandbox/fixed_point/boost/fixed_point/number.hpp (contents, props changed)
sandbox/fixed_point/libs/
sandbox/fixed_point/libs/fixed_point/
sandbox/fixed_point/libs/fixed_point/doc/
sandbox/fixed_point/libs/fixed_point/example/
sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp (contents, props changed)
sandbox/fixed_point/libs/fixed_point/perf/
sandbox/fixed_point/libs/fixed_point/test/
sandbox/fixed_point/libs/fixed_point/test/Jamfile.v2 (contents, props changed)
Added: sandbox/fixed_point/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/Jamfile.v2 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,28 @@
+# Copyright Rene Rivera 2007.
+#
+# 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)
+
+# Usage:
+#
+# bjam [options | properties | targets]
+#
+# Options:
+#
+# --boost=<BOOST> The directotory of a Boost source tree.
+# Default; BOOST env var (if found)
+# Default; ../boost (if found)
+#
+# --boost-build=<BOOST_BUILD>
+# The directory for the Boost.Build v2 files.
+# Default; BOOST_BUILD_PATH env var (if found)
+# Default; BOOST_BUILD env var (if found)
+# Default; <BOOST>/tools/build/v2 (if found)
+
+#~ If we have the Boost sources we can use the project...
+
+if [ GLOB $(BOOST) : [ modules.peek project : JAMFILE ] ]
+{
+ use-project /boost : $(BOOST) ;
+}
Added: sandbox/fixed_point/Jamroot.jam
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/Jamroot.jam 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,9 @@
+
+import modules ;
+
+local boost = [ modules.peek : BOOST ] ;
+
+project sandbox : requirements <include>$(boost) ;
+
+# This seems to prevent some Boost.Build errors that otherwise occur :-(
+use-project /boost : $(boost) ;
Added: sandbox/fixed_point/README.txt
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/README.txt 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,22 @@
+This directory contains the file "boost-build.jam" which search for a Boost install as follows:
+
+* In a directory specified by the --boost=path command line option.
+* In a directory specified by the BOOST environment variable.
+* In the directories ../boost and ../Trunk.
+
+In addition the variables BOOST and BOOST_ROOT are set to point to the root of the Boost install, so to refer to other
+Boost libraries and the main Boost headers, your Jamfile should contain something like:
+
+import modules ;
+
+local boost-path = [ modules.peek : BOOST ] ;
+
+And then you can refer to a Boost library "foo" as:
+
+$(boost-path)/libs/foo/build//boost_foo
+
+Note that if your project does not specify a Jamroot file, then a default one is provided for you,
+and that this file will automatically add $(BOOST)/ to your include path.
+
+
+
Added: sandbox/fixed_point/boost-build.jam
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/boost-build.jam 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,70 @@
+# Copyright Rene Rivera 2007.
+#
+# 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)
+
+# For instructions see Jamfile.v2, or "bjam --help".
+
+local rule if-has-file ( file + : dir * )
+{
+ local result ;
+ if $(dir)
+ {
+ result = [ GLOB $(dir) : $(file) ] ;
+ }
+ return $(result[1]:P) ;
+}
+
+#~ Attempts to find the Boost source tree...
+
+local boost-src = [ if-has-file LICENSE_1_0.txt :
+ [ MATCH --boost=(.*) : $(ARGV) ]
+ $(BOOST)
+ $(.boost-build-file:D)/../boost
+ $(.boost-build-file:D)/../Trunk
+ ] ;
+
+# error handling:
+if ! $(boost-src)
+{
+ ECHO Unable to find the Boost source tree in the locations searched. ;
+ ECHO Try setting the environment variable BOOST to point to your ;
+ ECHO Boost tree, or else invoke bjam with the --boost=path option. ;
+ ECHO The Boost include path will not be automatically set. ;
+ ECHO The paths searched were [ MATCH --boost=(.*) : $(ARGV) ] $(BOOST) $(.boost-build-file:D)/../boost $(.boost-build-file:D)/../Trunk ;
+ ECHO But the file LICENSE_1_0.txt was not found in any of them ;
+}
+
+#~ Attempts to find the Boost.Build files...
+
+local boost-build-src = [ if-has-file bootstrap.jam :
+ [ MATCH --boost-build=(.*) : $(ARGV) ]
+ $(BOOST_BUILD_PATH)
+ $(BOOST_BUILD)
+ $(boost-src)/tools/build/v2
+ ] ;
+
+# error handling:
+if ! $(boost-build-src)
+{
+ ECHO Unable to find the Boost.Build source tree in the locations searched. ;
+ ECHO Try setting the environment variable BOOST_BUILD to point to your ;
+ ECHO Boost.Build tree, or else invoke bjam with the --boost-build=path option. ;
+ ECHO The paths searched were [ MATCH --boost-build=(.*) : $(ARGV) ] $(BOOST_BUILD_PATH) $(BOOST_BUILD) $(boost-src)/tools/build/v2 ;
+ ECHO But bootstrap.jam was not found in any of these ;
+ ECHO More failures will very likely follow... ;
+}
+
+#~ Set some common vars to refer to the Boost sources...
+
+BOOST ?= $(boost-src) ;
+BOOST_ROOT ?= $(boost-src) ;
+
+#~ And load up Boost.Build...
+
+boost-build $(boost-build-src) ;
+
+
+
+
Added: sandbox/fixed_point/boost/fixed_point/number.hpp
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/boost/fixed_point/number.hpp 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,2278 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2012.
+// 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)
+//
+// See http://www.boost.org/libs/fixed_point for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_FIXED_POINT_NUMBER_HPP
+#define BOOST_FIXED_POINT_NUMBER_HPP
+
+#include <boost/mpl/logical.hpp>
+#include <boost/mpl/comparison.hpp>
+#include <boost/mpl/max.hpp>
+#include <boost/mpl/min.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/common_type.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_signed.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/integer.hpp>
+#include <boost/integer/static_log2.hpp>
+#include <boost/ratio/detail/mpl/abs.hpp>
+
+#include <boost/config.hpp>
+//#include <boost/fixed_point/config.hpp>
+//#include <boost/fixed_point/round/nearest_odd.hpp>
+//#include <boost/fixed_point/overflow/exception.hpp>
+
+#include <limits>
+
+namespace boost
+{
+ namespace fixed_point
+ {
+ struct positive_overflow {};
+ struct negative_overflow {};
+
+ namespace round
+ {
+ struct fastest {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style = std::round_indeterminate;
+ };
+ struct negative {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style = std::round_toward_infinity;
+ template <typename From, typename To>
+ static typename To::underlying_type round(From const& rhs)
+ {
+ BOOST_STATIC_CONSTEXPR typename To::underlying_type d = To::resolution_exp-From::resolution_exp;
+
+ return typename To::underlying_type(rhs.count()) >> d;
+ }
+ };
+ struct truncated {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style = std::round_toward_zero;
+ template <typename From, typename To>
+ static typename To::underlying_type round(From const& rhs)
+ {
+ BOOST_STATIC_CONSTEXPR typename To::underlying_type d = To::resolution_exp-From::resolution_exp;
+ typename To::underlying_type m(((rhs.count()>0)?rhs.count():-rhs.count()));
+ typename To::underlying_type s(((rhs.count()>0)?+1:-1));
+
+ return s * (m >> d);
+ }
+ };
+ struct positive {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style = std::round_toward_neg_infinity;
+ template <typename From, typename To>
+ static typename To::underlying_type round(From const& rhs)
+ {
+ BOOST_STATIC_CONSTEXPR typename To::underlying_type d = To::resolution_exp-From::resolution_exp;
+ typename To::underlying_type w = (1<<d)-1;
+ typename To::underlying_type i = rhs.count();
+
+ return (i+w) >> d;
+ }
+ };
+ struct classic {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style = std::round_to_nearest;
+ };
+ struct near_even {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style = std::round_to_nearest;
+ };
+ struct nearest_odd {
+ //BOOST_STATIC_CONSTEXPR std::round_to_nearest round_style;
+ };
+ }
+ namespace overflow
+ {
+ struct impossible {
+ template <typename T, typename U>
+ static typename T::underlying_type on_negative_overflow(U value)
+ {
+ BOOST_ASSERT_MSG(false,"Negative overflow while trying to convert fixed point numbers");
+ return value;
+ }
+ template <typename T, typename U>
+ static typename T::underlying_type on_positive_overflow(U value)
+ {
+ BOOST_ASSERT_MSG(false,"Positive overflow while trying to convert fixed point numbers");
+ return value;
+ }
+ };
+ struct undefined {
+ template <typename T, typename U>
+ static typename T::underlying_type on_negative_overflow(U value)
+ {
+ return value;
+ }
+ template <typename T, typename U>
+ static typename T::underlying_type on_positive_overflow(U value)
+ {
+ return value;
+ }
+ };
+ namespace detail {
+ template <typename T, typename U, bool TisSigned=T::is_signed>
+ struct modulus_on_negative_overflow;
+
+
+ template <typename T, typename U>
+ struct modulus_on_negative_overflow<T,U, false>
+ {
+ static typename T::underlying_type value(U value)
+ {
+ return (value%(T::max_index-T::min_index+1))+(T::max_index-T::min_index+1);
+ }
+ };
+
+ template <typename T, typename U>
+ struct modulus_on_negative_overflow<T,U, true>
+ {
+ static typename T::underlying_type value(U value)
+ {
+ return ((value-T::min_index)%(T::max_index-T::min_index+1))-T::min_index;
+ }
+ };
+
+
+ template <typename T, typename U, bool TisSigned=T::is_signed>
+ struct modulus_on_positive_overflow;
+
+ template <typename T, typename U>
+ struct modulus_on_positive_overflow<T,U, true>
+ {
+ static typename T::underlying_type value(U value)
+ {
+ return ((value-T::max_index)%(T::max_index-T::min_index+1))-T::max_index;
+ }
+ };
+ template <typename T, typename U>
+ struct modulus_on_positive_overflow<T,U, false>
+ {
+ static typename T::underlying_type value(U value)
+ {
+ return value%(T::max_index-T::min_index+1);
+ }
+ };
+ }
+ struct modulus {
+ template <typename T, typename U>
+ static typename T::underlying_type on_negative_overflow(U val)
+ {
+ return detail::modulus_on_negative_overflow<T,U>::value(val);
+ }
+ template <typename T, typename U>
+ static typename T::underlying_type modulus_on_positive_overflow(U val)
+ {
+ return detail::modulus_on_negative_overflow<T,U>::value(val);
+ }
+ };
+ struct saturate {
+ template <typename T, typename U>
+ static typename T::underlying_type on_negative_overflow(U value)
+ {
+ return T::min_index;
+ }
+ template <typename T, typename U>
+ static typename T::underlying_type on_positive_overflow(U value)
+ {
+ return T::max_index;
+ }
+
+ };
+ struct exception {
+ template <typename T, typename U>
+ static typename T::underlying_type on_negative_overflow(U value)
+ {
+ throw negative_overflow();
+ }
+ template <typename T, typename U>
+ static typename T::underlying_type on_positive_overflow(U value)
+ {
+ throw positive_overflow();
+ }
+
+ };
+ }
+ namespace optimization
+ {
+
+ struct undefined {
+ /**
+ * signed_integer_type: Gets the signed integer type with enough bits to manage with the Range and Resolution depending on the Opt
+ */
+ template <int Range, int Resolution>
+ struct signed_integer_type
+ {
+ typedef typename ::boost::int_t<Range-Resolution+1>::least type;
+ };
+
+ /**
+ * unsigned_integer_type: Gets the unsigned integer type with enough bits to manage with the Range and Resolution depending on the Opt
+ */
+ template <int Range, int Resolution>
+ struct unsigned_integer_type
+ {
+ typedef typename ::boost::uint_t<Range-Resolution>::least type;
+ };
+ };
+ struct space {
+ template <int Range, int Resolution>
+ struct signed_integer_type
+ {
+ typedef typename ::boost::int_t<Range-Resolution+1>::least type;
+ };
+ template <int Range, int Resolution>
+ struct unsigned_integer_type
+ {
+ typedef typename ::boost::uint_t<Range-Resolution>::least type;
+ };
+ };
+ struct time {
+ template <int Range, int Resolution>
+ struct signed_integer_type
+ {
+ typedef typename ::boost::int_t<Range-Resolution+1>::fast type;
+ };
+ template <int Range, int Resolution>
+ struct unsigned_integer_type
+ {
+ typedef typename ::boost::uint_t<Range-Resolution>::fast type;
+ };
+
+ };
+ }
+ /**
+ * fixed point unsigned number .
+ * @tparam Range the 2-exponent of the range. The range is 0<=x<2^Range,
+ * @tparam Resolution the 2-exponent of the step between two fixed point numbers
+ * @tparam Round the rounding policy
+ * @tparam Overflow the overflow policy
+ * @tparam Optimization the Optimization policy
+ */
+ template <int Range, int Resolution, typename Rounding=round::negative, typename Overflow=overflow::exception, typename Optimization=optimization::space>
+ class unsigned_number;
+
+ /**
+ * fixed point signed number .
+ * @tparam Range the 2-exponent of the range. the range is -2^Range<x<2^Range.
+ * @tparam Resolution the 2-exponent of the step between two fixed point numbers
+ * @tparam Round the rounding policy
+ * @tparam Overflow the overflow policy
+ * @tparam Optimization the Optimization policy
+ */
+ template <int Range, int Resolution, typename Rounding=round::negative, typename Overflow=overflow::exception, typename Optimization=optimization::space>
+ class signed_number;
+
+ // named parameter like class, allowing to make a specific overload when the integer must be taken by the index.
+ template <typename T>
+ struct index_tag
+ {
+ typedef T type;
+ T value;
+ index_tag(T v) : value(v) {}
+ T get() { return value; }
+
+ };
+
+ //! helper function to make easier the use of index_tag.
+ template <typename T>
+ struct index_tag<T> index(T v) { return index_tag<T>(v); }
+
+ template <class From, class To>
+ To number_cast(From const&);
+
+ namespace detail
+ {
+ template <typename T, int Range, int Resolution >
+ struct signed_integer_traits {
+ BOOST_STATIC_CONSTEXPR std::size_t bits = (Range-Resolution)+1;
+ BOOST_STATIC_ASSERT_MSG((sizeof(T)*8)>=bits, LLLL);
+ //BOOST_MPL_ASSERT_MSG((sizeof(T)*8)>=bits, LLLL, (mpl::int_<sizeof(T)*8>, mpl::int_<bits>));
+ BOOST_STATIC_CONSTEXPR T const_max = (1<<(bits-1)) - 1;
+ BOOST_STATIC_CONSTEXPR T const_min = -const_max;
+
+ };
+ template <typename T, int Range, int Resolution >
+ struct unsigned_integer_traits {
+ BOOST_STATIC_CONSTEXPR std::size_t bits = (Range-Resolution);
+ BOOST_STATIC_CONSTEXPR T const_max = (1<<(bits)) - 1;
+ BOOST_STATIC_CONSTEXPR T const_min = 0;
+
+ };
+
+ 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;
+ 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 <
+ typename From,
+ typename To,
+ bool LE_Range=mpl::less_equal < mpl::int_<From::range_exp>, mpl::int_<To::range_exp> >::type::value,
+ bool GE_Resolution=mpl::greater_equal < mpl::int_<From::resolution_exp>, mpl::int_<To::resolution_exp> >::type::value
+ > struct number_cast;
+
+ // LE_Range=true GE_Resolution=true
+ ///////////////////////////////////
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ true, true >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<< P1-P2 <<std::endl;
+ // No overflow and no round needed
+ return To(index(underlying_type(rhs.count()) << (P1-P2)));
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ true, true >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ // No overflow and no round needed
+ return To(index(underlying_type(rhs.count()) << (P1-P2)));
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ true, true >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<< P1-P2 <<std::endl;
+ // No overflow and no round needed
+ return To(index(underlying_type(rhs.count()) << (P1-P2)));
+ }
+ };
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ true, true >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<< P1-P2 <<std::endl;
+
+ underlying_type indx((underlying_type(rhs.count()) << (P1-P2)));
+ // Overflow
+ if (indx < To::min_index)
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+ // No round needed
+ return To(index(underlying_type(rhs.count()) << (P1-P2)));
+ }
+ };
+
+ // LE_Range=false GE_Resolution=true
+ ////////////////////////////////////
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ false, true >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ underlying_type indx((underlying_type(rhs.count()) << (P1-P2)));
+ // Overflow impossible
+ if (indx > To::max_index)
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (indx < To::min_index)
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // No round needed
+ return To(index(indx));
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ false, true >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ underlying_type indx((underlying_type(rhs.count()) << (P1-P2)));
+ // Overflow impossible
+ if (indx > To::max_index)
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (indx < To::min_index)
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // No round needed
+ return To(index(indx));
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ false, true >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ underlying_type indx((underlying_type(rhs.count()) << (P1-P2)));
+ // Overflow
+ if (indx > To::max_index)
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+
+ // No round needed
+ return To(index(indx));
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ false, true >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ underlying_type indx((underlying_type(rhs.count()) << (P1-P2)));
+ // Overflow
+ if (indx > To::max_index)
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+
+ // No round needed
+ return To(index(indx));
+ }
+ };
+
+ // LE_Range=true GE_Resolution=false
+ ////////////////////////////////////
+ template <int R, int P1, typename RP1, typename OP1, typename Opt1,
+ int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R,P1,RP1,OP1,Opt1>,
+ signed_number<R,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef signed_number<R,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow could be possible because more resolution implies a bigger range when the range exponents are the same.
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (rhs.count() < (typename From::underlying_type(To::min_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return res;
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // No overflow check needed as the case for the same range exponent is explicit above
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<RP2::template round<From,To>(rhs) <<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+
+ ////
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (rhs.count() < (typename From::underlying_type(To::min_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return res;
+ }
+ };
+
+ ////
+ template <int R, int P1, typename RP1, typename OP1, typename Opt1,
+ int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R,P1,RP1,OP1,Opt1>,
+ signed_number<R,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef unsigned_number<R,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow could be possible because more resolution implies a bigger range when the range exponents are the same.
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return res;
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // No overflow check needed as the case for the same range exponent is explicit above
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<RP2::template round<From,To>(rhs) <<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+
+ ////
+
+ template <int R, int P1, typename RP1, typename OP1, typename Opt1,
+ int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R,P1,RP1,OP1,Opt1>,
+ unsigned_number<R,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef unsigned_number<R,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow could be possible because more resolution implies a bigger range when the range exponents are the same.
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return res;
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ true, false >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // No overflow check needed as the case for the same range exponent is explicit above
+
+ // Round
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<RP2::template round<From,To>(rhs) <<std::endl;
+ To res((index(RP2::template round<From,To>(rhs))));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+
+ // LE_Range=false GE_Resolution=false
+ /////////////////////////////////////
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ false, false >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (rhs.count() < (typename From::underlying_type(To::min_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ signed_number<R2,P2,RP2,OP2,Opt2>,
+ false, false >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef signed_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ signed_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ false, false >
+ {
+ typedef signed_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (rhs.count() < (typename From::underlying_type(To::min_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct number_cast<
+ unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ unsigned_number<R2,P2,RP2,OP2,Opt2>,
+ false, false >
+ {
+ typedef unsigned_number<R1,P1,RP1,OP1,Opt1> From;
+ typedef unsigned_number<R2,P2,RP2,OP2,Opt2> To;
+ typedef typename To::underlying_type underlying_type;
+
+ BOOST_CONSTEXPR To operator()(const From& rhs) const
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ // Overflow
+ underlying_type indx(((rhs.count()) >> (P2-P1)));
+ if (rhs.count() > (typename From::underlying_type(To::max_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_positive_overflow<To,underlying_type>(indx)));
+ }
+ if (rhs.count() < (typename From::underlying_type(To::min_index)<<(P2-P1)))
+ {
+ return To(index(OP2::template on_negative_overflow<To,underlying_type>(indx)));
+ }
+
+ // Round
+ return To(index(RP2::template round<From,To>(rhs)));
+ }
+ };
+
+ } // namespace detail
+ } // namespace fixed_point
+
+ // common_type trait specializations
+
+ template <>
+ struct common_type<fixed_point::overflow::undefined, fixed_point::overflow::modulus>
+ {
+ typedef fixed_point::overflow::modulus type;
+ };
+ template <>
+ struct common_type<fixed_point::overflow::modulus, fixed_point::overflow::undefined>
+ {
+ typedef fixed_point::overflow::modulus type;
+ };
+
+ template <>
+ struct common_type<fixed_point::overflow::saturate, fixed_point::overflow::undefined>
+ {
+ typedef fixed_point::overflow::saturate type;
+ };
+ template <>
+ struct common_type<fixed_point::overflow::undefined, fixed_point::overflow::saturate>
+ {
+ typedef fixed_point::overflow::saturate type;
+ };
+
+ template <>
+ struct common_type<fixed_point::overflow::saturate, fixed_point::overflow::modulus>
+ {
+ typedef fixed_point::overflow::exception type;
+ };
+ template <>
+ struct common_type<fixed_point::overflow::modulus, fixed_point::overflow::saturate>
+ {
+ typedef fixed_point::overflow::exception type;
+ };
+ template <>
+ struct common_type<fixed_point::overflow::exception, fixed_point::overflow::exception>
+ {
+ typedef fixed_point::overflow::exception type;
+ };
+ template <typename Overflow>
+ struct common_type<fixed_point::overflow::exception, Overflow>
+ {
+ typedef fixed_point::overflow::exception type;
+ };
+ template <typename Overflow>
+ struct common_type<Overflow,fixed_point::overflow::exception>
+ {
+ typedef fixed_point::overflow::exception type;
+ };
+
+ template <>
+ struct common_type<fixed_point::overflow::impossible, fixed_point::overflow::impossible>
+ {
+ typedef fixed_point::overflow::impossible type;
+ };
+ template <typename Overflow>
+ struct common_type<fixed_point::overflow::impossible, Overflow>
+ {
+ typedef Overflow type;
+ };
+ template <typename Overflow>
+ struct common_type<Overflow,fixed_point::overflow::impossible>
+ {
+ typedef Overflow type;
+ };
+
+ template <>
+ struct common_type<fixed_point::round::fastest,fixed_point::round::fastest>
+ {
+ typedef fixed_point::round::fastest type;
+ };
+ template <typename Round>
+ struct common_type<Round,fixed_point::round::fastest>
+ {
+ typedef Round type;
+ };
+ template <typename Round>
+ struct common_type<fixed_point::round::fastest,Round>
+ {
+ typedef Round type;
+ };
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct common_type<
+ fixed_point::unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ fixed_point::unsigned_number<R2,P2,RP2,OP2,Opt2> >
+ {
+ typedef fixed_point::unsigned_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > type;
+ };
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct common_type<
+ fixed_point::signed_number<R1,P1,RP1,OP1,Opt1>,
+ fixed_point::signed_number<R2,P2,RP2,OP2,Opt2> >
+ {
+ typedef fixed_point::signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > type;
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct common_type<
+ fixed_point::signed_number<R1,P1,RP1,OP1,Opt1>,
+ fixed_point::unsigned_number<R2,P2,RP2,OP2,Opt2> >
+ {
+ typedef fixed_point::signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > type;
+ };
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ struct common_type<
+ fixed_point::unsigned_number<R1,P1,RP1,OP1,Opt1>,
+ fixed_point::signed_number<R2,P2,RP2,OP2,Opt2> >
+ {
+ typedef fixed_point::signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > type;
+ };
+
+ namespace fixed_point {
+
+
+ //! signed_number associated to a quantizer
+ template <int Range, int Resolution, typename Rounding, typename Overflow, typename Optimization>
+ class signed_number
+ {
+ 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;
+ typedef Rounding rounding_type;
+ typedef Overflow overflow_type;
+ 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;
+
+
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ static bool positive_overflows(signed_number<R,P,RP,OP,Opt> const& rhs)
+ {
+ return false;
+ }
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ static bool negative_overflows(signed_number<R,P,RP,OP,Opt> const& rhs)
+ {
+ return false;
+ }
+
+
+ //! construct/copy/destroy:
+ signed_number() {} // = default;
+ signed_number(signed_number const& rhs) : value_(rhs.value_) {} // = default;
+
+
+ //! implicit constructor from a signed_number with no larger range and no better resolution
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ signed_number(signed_number<R,P,RP,OP,Opt> const& rhs
+ , typename boost::enable_if <
+ mpl::and_ <
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >
+ >
+ >::type* = 0
+ )
+ : value_(fixed_point::detail::number_cast<signed_number<R,P,RP,OP,Opt>, signed_number, true, true>()(rhs).count())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<< P << std::endl;
+
+ }
+ //! implicit constructor from a signed_number with no larger range and no better resolution
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ signed_number(unsigned_number<R,P,RP,OP,Opt> const& rhs
+ , typename boost::enable_if <
+ mpl::and_ <
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >
+ >
+ >::type* = 0
+ )
+ : value_(fixed_point::detail::number_cast<unsigned_number<R,P,RP,OP,Opt>, signed_number, true, true>()(rhs).count())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<< P << std::endl;
+
+ }
+
+ //! explicit constructor from a signed_number with larger range or better resolution
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ explicit signed_number(signed_number<R,P,RP,OP,Opt> const& rhs
+ , typename boost::disable_if <
+ mpl::and_ <
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >
+ >
+ >::type* = 0
+ )
+ : value_(fixed_point::detail::number_cast<signed_number<R,P,RP,OP,Opt>, signed_number,
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >::value,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >::value
+ >()(rhs).count())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ }
+ //! explicit constructor from a signed_number with larger range or better resolution
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ explicit signed_number(unsigned_number<R,P,RP,OP,Opt> const& rhs
+ , typename boost::disable_if <
+ mpl::and_ <
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >
+ >
+ >::type* = 0
+ )
+ : value_(fixed_point::detail::number_cast<unsigned_number<R,P,RP,OP,Opt>, signed_number,
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >::value,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >::value
+ >()(rhs).count())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ }
+
+ ~signed_number() {} //= default;
+
+
+ //! explicit construction from an index.
+ template <typename UT>
+ explicit signed_number(index_tag<UT> i) : value_(i.get())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<<int(min_index) <<std::endl;
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<<int(max_index) <<std::endl;
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<<int(i.get()) <<std::endl;
+ BOOST_ASSERT(i.get()>=min_index);
+ BOOST_ASSERT(i.get()<=max_index);
+ }
+
+ //! observer
+
+ underlying_type count() const {return value_;}
+
+ static BOOST_CONSTEXPR signed_number zero()
+ {
+ return signed_number(index(0));
+ }
+ static BOOST_CONSTEXPR signed_number min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return signed_number(index(min_index));
+ }
+ static BOOST_CONSTEXPR signed_number max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return signed_number(index(max_index));
+ }
+
+
+#if 0
+
+ //! conversion factor.
+ template <typename FP>
+ static FP factor() const
+ {
+ 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 FP>
+ static FP reconstruct(underlying_type index) const
+ {
+ BOOST_ASSERT(min_index <= k && k <= max_index);
+
+ return k*factor<FP>();
+ }
+ template <typename FP>
+ static underlying_type classify(FP x) const
+ {
+ if (x<min().as<FP>()) return min_index;
+ if (x>max().as<FP>()) return max_index;
+ return integer_part(x/factor());
+ }
+
+ //! implicit conversion from float
+ signed_number(float x) : value_(classify(x))
+ {}
+ //! implicit conversion from double
+ signed_number(double x) : value_(classify(x))
+ {}
+ //! implicit conversion from long double
+ signed_number(long double x) : value_(classify(x))
+ {}
+
+ //! explicit conversion to FP.
+ template <typename FP>
+ FP as() const
+ {
+ return reconstruct<FP>(this->value_);
+ }
+ //! explicit conversion to float.
+ float as_float() const
+ {
+ return as<float>();
+ }
+
+ //! explicit conversion to double.
+ double as_double() const
+ {
+ return as<double>();
+ }
+
+ //! explicit conversion to long double.
+ long double as_long_double() const
+ {
+ return as<long double>();
+ }
+
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+ //! explicit conversion to float.
+ explicit operator float() const
+ {
+ return as<float>();
+ }
+ //! explicit conversion to double.
+ explicit operator double() const
+ {
+ return as<double>();
+ }
+ //! explicit conversion to long double.
+ explicit operator long double() const
+ {
+ return as<long double>();
+ }
+#endif
+#endif
+
+ // arithmetic
+
+ signed_number operator+() const
+ {
+ return *this;
+ }
+ signed_number operator-() const
+ {
+ // 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
+ )
+ {
+ ++value_;
+ return *this;
+ }
+ signed_number operator++(int
+ , typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ signed_number tmp=*this;
+ ++value_;
+ return tmp;
+ }
+ signed_number& operator--(
+ typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ --value_;
+ return *this;
+ }
+ signed_number operator--(int
+ , typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ signed_number tmp=*this;
+ --value_;
+ return tmp;
+ }
+#endif
+ signed_number& operator += (signed_number const& rhs)
+ {
+ value_ += rhs.count();
+ return *this;
+ }
+ signed_number& operator-=(const signed_number& rhs)
+ {
+ value_ -= rhs.count();
+ return *this;
+ }
+ signed_number& operator*=(const signed_number& rhs)
+ {
+ value_ *= rhs.count();
+ return *this;
+ }
+ signed_number& operator/=(const signed_number& rhs)
+ {
+ value_ /= rhs.count();
+ return *this;
+ }
+ protected:
+ underlying_type value_;
+ };
+
+ //! signed_number associated to a quantizer
+ template <int Range, int Resolution, typename Rounding, typename Overflow, typename Optimization>
+ class unsigned_number
+ {
+ 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;
+ typedef Rounding rounding_type;
+ typedef Overflow overflow_type;
+ typedef Optimization optimization_type;
+
+ BOOST_STATIC_CONSTEXPR underlying_type min_index = detail::unsigned_integer_traits<underlying_type,Range,Resolution>::const_min;
+ BOOST_STATIC_CONSTEXPR underlying_type max_index = detail::unsigned_integer_traits<underlying_type,Range,Resolution>::const_max;
+
+
+ //! construct/copy/destroy:
+ unsigned_number() {} // = default;
+ unsigned_number(unsigned_number const& rhs) : value_(rhs.value_) {} // = default;
+
+
+ //! implicit constructor from a unsigned_number with no larger range and no better resolution
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ unsigned_number(unsigned_number<R,P,RP,OP,Opt> const& rhs
+ , typename boost::enable_if <
+ mpl::and_ <
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >
+ >
+ >::type* = 0
+ )
+ : value_(fixed_point::detail::number_cast<unsigned_number<R,P,RP,OP,Opt>, unsigned_number, true, true>()(rhs).count())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<< P << std::endl;
+
+ }
+
+ //! explicit constructor from a unsigned_number with larger range or better resolution
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ explicit unsigned_number(unsigned_number<R,P,RP,OP,Opt> const& rhs
+ , typename boost::disable_if <
+ mpl::and_ <
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >
+ >
+ >::type* = 0
+ )
+ : value_(fixed_point::detail::number_cast<unsigned_number<R,P,RP,OP,Opt>, unsigned_number,
+ mpl::less_equal < mpl::int_<R>, mpl::int_<Range> >::value,
+ mpl::greater_equal < mpl::int_<P>, mpl::int_<Resolution> >::value
+ >()(rhs).count())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+
+ }
+
+ ~unsigned_number() {} //= default;
+
+
+ //! explicit construction from an index.
+ template <typename UT>
+ explicit unsigned_number(index_tag<UT> i) : value_(i.get())
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<<int(min_index) <<std::endl;
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<<int(max_index) <<std::endl;
+ std::cout << __FILE__ << "[" <<__LINE__<<"] "<<int(i.get()) <<std::endl;
+ BOOST_ASSERT(i.get()>=min_index);
+ BOOST_ASSERT(i.get()<=max_index);
+ }
+
+ //! observer
+
+ underlying_type count() const {return value_;}
+
+ static BOOST_CONSTEXPR unsigned_number zero()
+ {
+ return unsigned_number(index(0));
+ }
+ static BOOST_CONSTEXPR unsigned_number min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return unsigned_number(index(min_index));
+ }
+ static BOOST_CONSTEXPR unsigned_number max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return unsigned_number(index(max_index));
+ }
+
+#if 0
+
+ //! conversion factor.
+ template <typename FP>
+ static FP factor() const
+ {
+ 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 FP>
+ static FP reconstruct(underlying_type index) const
+ {
+ BOOST_ASSERT(min_index <= k && k <= max_index);
+
+ return k*factor<FP>();
+ }
+ template <typename FP>
+ static underlying_type classify(FP x) const
+ {
+ if (x<min().as<FP>()) return min_index;
+ if (x>max().as<FP>()) return max_index;
+ return integer_part(x/factor());
+ }
+
+ //! implicit conversion from float
+ unsigned_number(float x) : value_(classify(x))
+ {}
+ //! implicit conversion from double
+ unsigned_number(double x) : value_(classify(x))
+ {}
+ //! implicit conversion from long double
+ unsigned_number(long double x) : value_(classify(x))
+ {}
+
+ //! explicit conversion to FP.
+ template <typename FP>
+ FP as() const
+ {
+ return reconstruct<FP>(this->value_);
+ }
+ //! explicit conversion to float.
+ float as_float() const
+ {
+ return as<float>();
+ }
+
+ //! explicit conversion to double.
+ double as_double() const
+ {
+ return as<double>();
+ }
+
+ //! explicit conversion to long double.
+ long double as_long_double() const
+ {
+ return as<long double>();
+ }
+
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+ //! explicit conversion to float.
+ explicit operator float() const
+ {
+ return as<float>();
+ }
+ //! explicit conversion to double.
+ explicit operator double() const
+ {
+ return as<double>();
+ }
+ //! explicit conversion to long double.
+ explicit operator long double() const
+ {
+ return as<long double>();
+ }
+#endif
+#endif
+
+ // arithmetic
+
+ unsigned_number operator+() const
+ {
+ return *this;
+ }
+ signed_number<Range,Resolution,Rounding,Overflow,Optimization>
+ operator-() const
+ {
+ return signed_number<Range,Resolution,Rounding,Overflow,Optimization>(index(-value_));
+ }
+
+#if 0
+ unsigned_number& operator++(
+ typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ ++value_;
+ return *this;
+ }
+ unsigned_number operator++(int
+ , typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ unsigned_number tmp=*this;
+ ++value_;
+ return tmp;
+ }
+ unsigned_number& operator--(
+ typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ --value_;
+ return *this;
+ }
+ unsigned_number operator--(int
+ , typename boost::enable_if <
+ is_equal<mpl::int_<Resolution>, mpl::int_<0> >
+ >::type* = 0
+ )
+ {
+ unsigned_number tmp=*this;
+ --value_;
+ return tmp;
+ }
+#endif
+ unsigned_number& operator += (unsigned_number const& rhs)
+ {
+ value_ += rhs.count();
+ return *this;
+ }
+ unsigned_number& operator-=(const unsigned_number& rhs)
+ {
+ value_ -= rhs.count();
+ return *this;
+ }
+ unsigned_number& operator*=(const unsigned_number& rhs)
+ {
+ value_ *= rhs.count();
+ return *this;
+ }
+ unsigned_number& operator/=(const unsigned_number& rhs)
+ {
+ value_ /= rhs.count();
+ return *this;
+ }
+ protected:
+ underlying_type value_;
+ };
+
+ template <int Times, int Resolution>
+ BOOST_CONSTEXPR
+ inline
+ unsigned_number< static_log2<mpl::abs<mpl::int_<Times+1> >::type::value>::value, Resolution>
+ to_unsigned_number()
+ {
+ return unsigned_number< static_log2<mpl::abs<mpl::int_<Times+1> >::type::value>::value, Resolution>(index(Times));
+ }
+ template <int Times, int Resolution>
+ BOOST_CONSTEXPR
+ inline
+ signed_number< static_log2<mpl::abs<mpl::int_<Times+1> >::type::value>::value, Resolution>
+ to_signed_number()
+ {
+ return signed_number< static_log2<mpl::abs<mpl::int_<Times+1> >::type::value>::value, Resolution>(index(Times));
+ }
+
+ // signed_number non-member arithmetic
+
+ //! +
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator+(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()+result_type(rhs).count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator+(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()+result_type(rhs).count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator+(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()+result_type(rhs).count()));
+ }
+ //! unsigned_number +
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ unsigned_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator+(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef unsigned_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()+result_type(rhs).count()));
+ }
+
+ //! -
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator-(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()-result_type(rhs).count()));
+ }
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator-(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()-result_type(rhs).count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator-(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()-result_type(rhs).count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator-(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ mpl::max<mpl::int_<R1>,mpl::int_<R2> >::type::value+1,
+ mpl::min<mpl::int_<P1>,mpl::int_<P2> >::type::value,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return result_type(index(result_type(lhs).count()-result_type(rhs).count()));
+ }
+
+ //! *
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator*(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+ typedef typename result_type::underlying_type underlying_type;
+
+ return result_type(index(underlying_type(lhs.count()) * rhs.count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator*(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+ typedef typename result_type::underlying_type underlying_type;
+
+ return result_type(index(underlying_type(lhs.count()) * rhs.count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator*(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+ typedef typename result_type::underlying_type underlying_type;
+
+ return result_type(index(underlying_type(lhs.count()) * rhs.count()));
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ unsigned_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator*(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef unsigned_number<
+ R1+R2,
+ P1+P2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+ typedef typename result_type::underlying_type underlying_type;
+
+ return result_type(index(underlying_type(lhs.count()) * rhs.count()));
+ }
+
+ //! divide
+
+ template <
+ typename Res,
+ int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ Res
+ divide(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef Res result_type;
+ typedef typename result_type::underlying_type underlying_type;
+ typedef typename common_type<signed_number<R1,P1,RP1,OP1,Opt1>, signed_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ BOOST_STATIC_CONSTEXPR int P = Res::resolution_exp;
+
+ BOOST_STATIC_ASSERT((mpl::greater_equal<
+ mpl::int_<Res::range_exp>,
+ mpl::int_<R1-P2>
+ >::type::value));
+ BOOST_STATIC_ASSERT((mpl::less_equal<
+ mpl::int_<Res::resolution_exp>,
+ mpl::int_<P1-R2>
+ >::type::value));
+ BOOST_ASSERT_MSG(CT(rhs).count()!=0, "Division by 0");
+
+ underlying_type ci = (underlying_type(CT(lhs).count()) << -P) / CT(rhs).count();
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return result_type(index(ci)); // ....
+ }
+
+ template <
+ typename Res,
+ int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ Res
+ divide(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef Res result_type;
+ typedef typename result_type::underlying_type underlying_type;
+ typedef typename common_type<unsigned_number<R1,P1,RP1,OP1,Opt1>, unsigned_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ BOOST_STATIC_CONSTEXPR int P = Res::resolution_exp;
+
+ BOOST_STATIC_ASSERT((mpl::greater_equal<
+ mpl::int_<Res::range_exp>,
+ mpl::int_<R1-P2>
+ >::type::value));
+ BOOST_STATIC_ASSERT((mpl::less_equal<
+ mpl::int_<Res::resolution_exp>,
+ mpl::int_<P1-R2>
+ >::type::value));
+ BOOST_ASSERT_MSG(CT(rhs).count()!=0, "Division by 0");
+
+ underlying_type ci = (underlying_type(CT(lhs).count()) << -P) / CT(rhs).count();
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return result_type(index(ci)); // ....
+ }
+
+ template <
+ typename Res,
+ int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ Res
+ divide(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef Res result_type;
+ typedef typename result_type::underlying_type underlying_type;
+ typedef typename common_type<signed_number<R1,P1,RP1,OP1,Opt1>, unsigned_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ BOOST_STATIC_CONSTEXPR int P = Res::resolution_exp;
+
+ BOOST_STATIC_ASSERT((mpl::greater_equal<
+ mpl::int_<Res::range_exp>,
+ mpl::int_<R1-P2>
+ >::type::value));
+ BOOST_STATIC_ASSERT((mpl::less_equal<
+ mpl::int_<Res::resolution_exp>,
+ mpl::int_<P1-R2>
+ >::type::value));
+ BOOST_ASSERT_MSG(CT(rhs).count()!=0, "Division by 0");
+
+ underlying_type ci = (underlying_type(CT(lhs).count()) << -P) / CT(rhs).count();
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return result_type(index(ci)); // ....
+ }
+
+ template <
+ typename Res,
+ int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ Res
+ divide(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef Res result_type;
+ typedef typename result_type::underlying_type underlying_type;
+ typedef typename common_type<unsigned_number<R1,P1,RP1,OP1,Opt1>, signed_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ BOOST_STATIC_CONSTEXPR int P = Res::resolution_exp;
+
+ BOOST_STATIC_ASSERT((mpl::greater_equal<
+ mpl::int_<Res::range_exp>,
+ mpl::int_<R1-P2>
+ >::type::value));
+ BOOST_STATIC_ASSERT((mpl::less_equal<
+ mpl::int_<Res::resolution_exp>,
+ mpl::int_<P1-R2>
+ >::type::value));
+ BOOST_ASSERT_MSG(CT(rhs).count()!=0, "Division by 0");
+
+ underlying_type ci = (underlying_type(CT(lhs).count()) << -P) / CT(rhs).count();
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ return result_type(index(ci)); // ....
+ }
+
+ //! /
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator/(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return divide<result_type>(lhs,rhs);
+ }
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator/(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return divide<result_type>(lhs,rhs);
+ }
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ signed_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator/(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef signed_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return divide<result_type>(lhs,rhs);
+ }
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ unsigned_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ >
+ operator/(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef unsigned_number<
+ R1-P2,
+ P1-R2,
+ typename common_type<RP1,RP2>::type,
+ typename common_type<OP1,OP2>::type,
+ typename common_type<Opt1,Opt2>::type
+ > result_type;
+
+ return divide<result_type>(lhs,rhs);
+ }
+
+
+ // comparisons
+
+ // ==
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator==(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef typename common_type<signed_number<R1,P1,RP1,OP1,Opt1>, signed_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ return CT(lhs).count() == CT(rhs).count();
+ }
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator==(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef typename common_type<unsigned_number<R1,P1,RP1,OP1,Opt1>, unsigned_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ return CT(lhs).count() == CT(rhs).count();
+ }
+
+ // !=
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator!=(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return !(lhs == rhs);
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator!=(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
+ // <
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator<(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef typename common_type<signed_number<R1,P1,RP1,OP1,Opt1>, signed_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ return CT(lhs).count() < CT(rhs).count();
+ }
+
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator<(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ typedef typename common_type<unsigned_number<R1,P1,RP1,OP1,Opt1>, unsigned_number<R2,P2,RP2,OP2,Opt2> >::type CT;
+ return CT(lhs).count() < CT(rhs).count();
+ }
+
+ // >
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator>(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return rhs < lhs;
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator>(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return rhs < lhs;
+ }
+
+ // <=
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator<=(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return !(rhs < lhs);
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator<=(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return !(rhs < lhs);
+ }
+
+ // >=
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator>=(signed_number<R1,P1,RP1,OP1,Opt1> const& lhs, signed_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return !(lhs < rhs);
+ }
+ template <int R1, int P1, typename RP1, typename OP1, typename Opt1,
+ int R2, int P2, typename RP2, typename OP2, typename Opt2>
+ inline
+ bool
+ operator>=(unsigned_number<R1,P1,RP1,OP1,Opt1> const& lhs, unsigned_number<R2,P2,RP2,OP2,Opt2> const& rhs)
+ {
+ return !(lhs < rhs);
+ }
+
+ // number_cast
+ template <typename To, typename From>
+ To number_cast(From const& f)
+ {
+ return fixed_point::detail::number_cast<From, To>()(f);
+ }
+ }
+}
+
+namespace std {
+ // numeric limits trait specializations
+ template <int R, int P, typename RP, typename OP, typename Opt>
+ class numeric_limits<boost::fixed_point::signed_number<R,P,RP,OP,Opt> >
+ {
+ typedef boost::fixed_point::signed_number<R,P,RP,OP,Opt> rep;
+ public:
+ BOOST_STATIC_CONSTEXPR bool is_specialized = true;
+ inline static rep min() { return rep::min(); }
+ inline static rep max() { return rep::max(); }
+ inline static rep lowest() { return rep::lowest(); }
+ //BOOST_STATIC_CONSTEXPR int digits = Q::digits;
+ //BOOST_STATIC_CONSTEXPR int digits10 = Q::digits10;
+ //BOOST_STATIC_CONSTEXPR int max_digits10 = Q::max_digits10;
+ BOOST_STATIC_CONSTEXPR bool is_signed = true;
+ BOOST_STATIC_CONSTEXPR bool is_integer = false;
+ BOOST_STATIC_CONSTEXPR bool is_exact = true;
+ BOOST_STATIC_CONSTEXPR int radix = 2;
+ //inline static rep epsilon() { return rep::epsilon(); }
+ //inline static rep round_error() { return rep::round_error(); }
+ //BOOST_STATIC_CONSTEXPR int min_exponent = rep::min_exponent;
+ //BOOST_STATIC_CONSTEXPR int min_exponent10 = rep::min_exponent10;
+ //BOOST_STATIC_CONSTEXPR int max_exponent = rep::max_exponent;
+ //BOOST_STATIC_CONSTEXPR int max_exponent10 = rep::max_exponent10;
+ BOOST_STATIC_CONSTEXPR bool has_infinity = false;
+ BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false;
+ BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
+ //BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
+ //BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
+ //inline static rep infinity() { return rep::infinity(); }
+ //inline static rep quiet_NaN() { return rep::quiet_NaN(); }
+ //inline static rep signaling_NaN() { return rep::signaling_NaN(); }
+ //inline static rep denorm_min() { return rep::denorm_min<Q>(); }
+ //BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
+ BOOST_STATIC_CONSTEXPR bool is_bounded = true;
+ BOOST_STATIC_CONSTEXPR bool is_modulo = RP::is_modulo;
+ BOOST_STATIC_CONSTEXPR bool traps = true;
+ //BOOST_STATIC_CONSTEXPR bool tinyness_before = rep::tinyness_before;
+ BOOST_STATIC_CONSTEXPR float_round_style round_style = RP::round_style;
+ };
+}
+
+#define BOOST_TYPEOF_SILENT
+#include <boost/typeof/typeof.hpp>
+
+#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
+
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::fixed_point::signed_number, (int)(int)(typename)(typename)(typename))
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::fixed_point::unsigned_number, (int)(int)(typename)(typename)(typename))
+#endif // header
Added: sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/libs/fixed_point/example/ex_xx.cpp 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,680 @@
+// Copyright (C) 2012 Vicente J. Botet Escriba
+//
+// 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)
+
+#include <iostream>
+#include <boost/fixed_point/number.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+using namespace boost::fixed_point;
+
+struct pixel { unsigned_number<8,0> r, g, b, a; };
+
+pixel blend( pixel a, pixel b ) {
+ BOOST_AUTO(scale, (to_unsigned_number<255,0>()));
+ BOOST_AUTO(a_r, a.r / scale);
+ BOOST_AUTO(b_r, b.r / scale);
+ BOOST_AUTO(aia, b.a * (to_unsigned_number<1,0>() - a.a));
+ BOOST_AUTO(c_a, a.a + aia);
+ BOOST_AUTO(c_r, (a.r*a.a + b.r*aia) / c_a);
+ pixel c;
+ c.a = number_cast<unsigned_number<8,0> >(c_a * to_unsigned_number<255,0>());
+ c.r = number_cast<unsigned_number<8,0> >(c_r * to_unsigned_number<255,0>());
+ return c;
+}
+
+int main()
+{
+ {
+ unsigned_number<2,-2,round::negative> n;
+ }
+ {
+ signed_number<2,-2,round::negative> n;
+ }
+ {
+ signed_number<2,-2,round::truncated> n;
+ }
+ {
+ signed_number<2,-2,round::positive> n;
+ }
+ {
+ unsigned_number<2,-2,round::negative> n((index(1)));
+ BOOST_TEST(n.count()==1);
+ }
+ {
+ unsigned_number<2,-2,round::negative> n=to_unsigned_number<1,0>(); //
+ std::cout << int(n.count()) << std::endl;
+ BOOST_TEST(n.count()==4);
+ }
+ {
+ signed_number<2,-2,round::negative> n((index(1)));
+ BOOST_TEST(n.count()==1);
+ }
+ {
+ signed_number<2,-2,round::truncated> n((index(1)));
+ BOOST_TEST(n.count()==1);
+ }
+ {
+ signed_number<2,-2,round::positive> n((index(1)));
+ BOOST_TEST(n.count()==1);
+ }
+ {
+ unsigned_number<2,-2> n1((index(1)));
+ unsigned_number<2,-2,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n2.count()==1);
+ }
+ {
+ signed_number<2,-2> n1((index(1)));
+ signed_number<2,-2,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n2.count()==1);
+ }
+ {
+ signed_number<2,-2> n1((index(1)));
+ signed_number<2,-2,round::negative> n2;
+ n2=n1;
+ BOOST_TEST(n1.count()==1);
+ BOOST_TEST(n2.count()==1);
+ }
+ {
+ signed_number<2,-2> n1((index(1)));
+ signed_number<2,-3,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==1);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==2);
+ }
+ {
+ signed_number<2,-2> n1((index(1)));
+ signed_number<2,-3,round::negative> n2;
+ n2=n1;
+ BOOST_TEST(n1.count()==1);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==2);
+ }
+ {
+ unsigned_number<2,-2> n1((index(1)));
+ unsigned_number<2,-3,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==1);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==2);
+ }
+ {
+ 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,round::negative> n2;
+ n2=number_cast<unsigned_number<2,-2,round::negative> >(n1);
+ }
+ {
+ signed_number<2,-3> n1((index(1)));
+ signed_number<2,-2,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==1);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==0);
+ }
+ {
+ 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);
+ }
+ {
+ 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);
+ }
+ {
+ 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);
+ }
+ {
+ 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);
+ }
+ {
+ signed_number<2,-3> n1((index(2)));
+ signed_number<2,-2,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==2);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==1);
+ }
+ {
+ 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);
+ }
+ {
+ 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);
+ }
+ {
+ signed_number<2,-3> n1((index(-1)));
+ signed_number<2,-2,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==-1);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==-1);
+ }
+ {
+ 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()==0);
+ }
+ {
+ 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);
+ }
+ {
+ signed_number<2,-3> n1((index(-2)));
+ signed_number<2,-2,round::negative> n2(n1);
+ BOOST_TEST(n1.count()==-2);
+ std::cout << int(n2.count()) << std::endl;
+ BOOST_TEST(n2.count()==-1);
+ }
+ {
+ 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);
+ }
+ {
+ 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);
+ }
+ {
+ signed_number<2,-1> n1((index(-7)));
+ }
+ {
+ signed_number<2,-1> n1((index(7)));
+ }
+ {
+ unsigned_number<2,-1> n1((index(7)));
+ }
+ {
+ signed_number<2,-2> n1((index(15)));
+ try {
+ signed_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (positive_overflow &) {}
+ }
+ {
+ unsigned_number<2,-2> n1((index(15)));
+ try {
+ unsigned_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (positive_overflow &) {}
+ }
+ {
+ signed_number<2,-2> n1((index(-15)));
+ try {
+ signed_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (negative_overflow &) {}
+ }
+ {
+ signed_number<3,-1> n1((index(15)));
+ try {
+ signed_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (positive_overflow &) {}
+ }
+ {
+ signed_number<3,-1> n1((index(-15)));
+ try {
+ signed_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (negative_overflow &) {}
+ }
+ {
+ signed_number<3,-2> n1((index(31)));
+ try {
+ signed_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (positive_overflow &) {}
+ }
+ {
+ signed_number<3,-2> n1((index(-31)));
+ try {
+ signed_number<2,-1> n2(n1);
+ BOOST_TEST(false);
+ } catch (negative_overflow &) {}
+ }
+ // unary plus
+ {
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2(+n1);
+ BOOST_TEST(n2.count()==7);
+ }
+ {
+ unsigned_number<2,-1> n1((index(3)));
+ unsigned_number<2,-1> n2(+n1);
+ BOOST_TEST(n2.count()==3);
+ }
+ // unary minus
+ {
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2(-n1);
+ BOOST_TEST(n2.count()==-7);
+ signed_number<2,-1> n3(-n2);
+ BOOST_TEST(n3.count()==7);
+ }
+ {
+ unsigned_number<2,-1> n1((index(3)));
+ signed_number<2,-1> n2(-n1);
+ BOOST_TEST(n2.count()==-3);
+ signed_number<2,-1> n3(-n2);
+ BOOST_TEST(n3.count()==3);
+ }
+ // plus
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ signed_number<3,-1> n3 = n1 + n2;
+ BOOST_TEST(n3.count()==14);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<2,-2> n1((index(7)));
+ unsigned_number<2,-2> n2((index(7)));
+ signed_number<3,-2> n3 = n1 + n2;
+ BOOST_TEST(n3.count()==14);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<2,-2> n1((index(7)));
+ signed_number<2,-2> n2((index(7)));
+ signed_number<3,-2> n3 = n2 + n1;
+ BOOST_TEST(n3.count()==14);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ BOOST_AUTO(n3,n1 + n2);
+ BOOST_TEST(n3.count()==14);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(-7)));
+ signed_number<2,-1> n2((index(-7)));
+ signed_number<3,-1> n3 = n1 + n2;
+ BOOST_TEST(n3.count()==-14);
+ }
+ // minus
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ signed_number<3,-1> n3 = n1 - n2;
+ BOOST_TEST(n3.count()==0);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<2,-2> n1((index(7)));
+ unsigned_number<2,-2> n2((index(7)));
+ signed_number<3,-2> n3 = n1 - n2;
+ BOOST_TEST(n3.count()==0);
+ }
+ // multiply
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ signed_number<4,-2> n3 = n1 * n2;
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==49);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<2,-2> n1((index(7)));
+ unsigned_number<2,-2> n2((index(7)));
+ unsigned_number<4,-4> n3 = n1 * n2;
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==49);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-2> n1((index(7)));
+ unsigned_number<2,-2> n2((index(7)));
+ signed_number<4,-4> n3 = n1 * n2;
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==49);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ unsigned_number<2,-2> n1((index(7)));
+ signed_number<2,-2> n2((index(7)));
+ signed_number<4,-4> n3 = n1 * n2;
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==49);
+ }
+ // divide
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(1)));
+ signed_number<2,-1> n2((index(7)));
+ signed_number<3,-6> n3 = divide<signed_number<3,-6> >(n1,n2);
+ BOOST_TEST(n3.count()==9);
+ }
+ {
+ unsigned_number<2,-1> n1((index(1)));
+ unsigned_number<2,-2> n2((index(7)));
+ unsigned_number<4,-6> n3 = divide<unsigned_number<4,-6> >(n1,n2);
+ BOOST_TEST(n3.count()==18);
+ }
+ {
+ signed_number<2,-1> n1((index(1)));
+ unsigned_number<2,-2> n2((index(7)));
+ signed_number<4,-6> n3 = divide<signed_number<4,-6> >(n1,n2);
+ BOOST_TEST(n3.count()==18);
+ }
+ {
+ unsigned_number<2,-1> n1((index(1)));
+ signed_number<2,-2> n2((index(7)));
+ signed_number<4,-6> n3 = divide<signed_number<4,-6> >(n1,n2);
+ BOOST_TEST(n3.count()==18);
+ }
+ {
+ unsigned_number<2,-1> n1((index(1)));
+ signed_number<2,-2> n2((index(7)));
+ signed_number<4,-3> n3 = n1/n2;
+ BOOST_TEST(n3.count()==2);
+ }
+ {
+ signed_number<2,-1> n1((index(1)));
+ signed_number<2,-2> n2((index(7)));
+ signed_number<6,-3> n3 = divide<signed_number<6,-3> >(n1,n2);
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==2);
+ }
+ {
+ signed_number<2,-1> n1((index(-1)));
+ signed_number<2,-1> n2((index(7)));
+ signed_number<3,-6> n3 = divide<signed_number<3,-6> >(n1,n2);
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==-9);
+ }
+ {
+ signed_number<2,-1> n1((index(1)));
+ signed_number<2,-1> n2((index(7)));
+ signed_number<3,-3,round::negative> n3 = n1/n2;
+ BOOST_TEST(n3.count()==1);
+ }
+ {
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(1)));
+ signed_number<3,-6> n3 = divide<signed_number<3,-6> >(n1,n2);
+ BOOST_TEST(n3.count()==7*64);
+ }
+ {
+ signed_number<4,1> n1((index(1)));
+ signed_number<4,1> n2((index(7)));
+ signed_number<3,-6> n3 = divide<signed_number<3,-6> >(n1,n2);
+ BOOST_TEST(n3.count()==9);
+ }
+ {
+ signed_number<4,1> n1((index(1)));
+ signed_number<4,1> n2((index(7)));
+ signed_number<3,-3> n3 = divide<signed_number<3,-3> >(n1,n2);
+ BOOST_TEST(n3.count()==1);
+ }
+ {
+ signed_number<4,1> n1((index(7)));
+ signed_number<4,1> n2((index(1)));
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ std::cout << int(n2.count()) << std::endl;
+ signed_number<3,-6> n3 = divide<signed_number<3,-6> >(n1,n2);
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ std::cout << int(n3.count()) << std::endl;
+ BOOST_TEST(n3.count()==7*64);
+ }
+ // equal
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ BOOST_TEST(n1==n2);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-2> n2((index(14)));
+ BOOST_TEST(n1==n2);
+ }
+ // not_equal
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(1)));
+ BOOST_TEST(n1!=n2);
+ }
+ // gt
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(1)));
+ BOOST_TEST(n1>n2);
+ }
+ // ge
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(1)));
+ BOOST_TEST(n1>=n2);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ BOOST_TEST(n1>=n2);
+ }
+ // lt
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(1)));
+ BOOST_TEST(n2<n1);
+ }
+ // le
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(1)));
+ BOOST_TEST(n2<=n1);
+ }
+// {
+// unsigned_number<2,-1> n1((index(-7))); // assertion failed
+// }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<1,-2> n2((index(1)));
+ BOOST_TEST(n2<=n1);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ signed_number<2,-1> n1((index(7)));
+ signed_number<2,-1> n2((index(7)));
+ BOOST_TEST(n2<=n1);
+ }
+// {
+// signed_number<32,-32> n; // compile fail
+// std::cout << sizeof(signed_number<32,-32>::underlying_type) << std::endl;
+// std::cout << ::std::numeric_limits<long>::digits << std::endl;
+// std::cout << (int)(sizeof(boost::long_long_type) * CHAR_BIT) << std::endl;
+// }
+// {
+// std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+// short b=3;
+// std::cout <<"-b = "<< -b << std::endl;
+// }
+// {
+// unsigned short a=2;
+// short b=-1;
+// std::cout <<"a/b = "<< a/b << std::endl;
+// }
+// {
+// unsigned short a=2;
+// short b=-1;
+// std::cout <<"a*b = "<< a*b << std::endl;
+// }
+// {
+// unsigned short a=2;
+// short b=-3;
+// std::cout <<"a+b = "<< a+b << std::endl;
+// }
+// {
+// unsigned short a=2;
+// short b=3;
+// std::cout <<"a-b = "<< a-b << std::endl;
+// }
+// {
+// unsigned char a=240;
+// unsigned char b=240;
+// std::cout <<"a+b = "<< a+b << std::endl;
+// }
+// {
+// unsigned char a=250;
+// unsigned char b=50;
+// unsigned char c=50;
+// unsigned char r=a-b+c;
+// std::cout <<"a-50+50 = "<< int(r) << std::endl;
+// }
+// {
+// unsigned char a=250;
+// unsigned char b=50;
+// unsigned char c=50;
+// unsigned char r=a+b-c;
+// std::cout <<"a+50-50 = "<< int(r) << std::endl;
+// }
+// {
+// unsigned short a=128+258;
+// unsigned char b=a;
+// std::cout <<"u->u "<< a << std::endl;
+// std::cout <<"a%256 = "<< a%256 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// {
+// unsigned short a=2;
+// char b=a;
+// std::cout <<"u->s "<< a<< std::endl;
+// std::cout <<"a%128 = "<< ((a+128)%256)-128 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// {
+// unsigned short a=130;
+// char b=a;
+// std::cout <<"u->s "<< a<< std::endl;
+// std::cout <<"a%128 = "<< ((a-128)%256)-128 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// {
+// unsigned short a=258;
+// char b=a;
+// std::cout <<"u->s "<< a<< std::endl;
+// std::cout <<"a%128 = "<< ((a-128)%256)-128 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// {
+// std::cout <<"s->s "<< std::endl;
+// for (short a=-(256+2); a<-128; a+=1)
+// {
+// char b=a;
+// std::cout <<"a = "<< a << std::endl;
+// std::cout <<"a% = "<< ((a+128)%256)+128 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// for (short a=-128; a<0; a+=1)
+// {
+// char b=a;
+// std::cout <<"a = "<< a << std::endl;
+// std::cout <<"a% = "<< a << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// for (short a=0; a<128; a+=1)
+// {
+// char b=a;
+// std::cout <<"a = "<< a << std::endl;
+// std::cout <<"a% = "<< a << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// for (short a=128; a<256+32; a+=1)
+// {
+// char b=a;
+// std::cout <<"a = "<< a << std::endl;
+// std::cout <<"a% = "<< ((a-128)%256)-128 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// }
+// {
+// std::cout <<"s->u "<< std::endl;
+// for (short a=-(256+2); a<0; a+=1)
+// {
+// unsigned char b=a;
+// std::cout <<"a = "<< a << std::endl;
+// std::cout <<"a% = "<< (a)%256+256 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// for (short a=0; a<256+32; a+=1)
+// {
+// unsigned char b=a;
+// std::cout <<"a = "<< a << std::endl;
+// std::cout <<"a% = "<< a%256 << std::endl;
+// std::cout <<"b=a = "<< int(b) << std::endl;
+// }
+// }
+
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ BOOST_AUTO(scale, (to_unsigned_number<255,0>()));
+ BOOST_TEST(scale.count()==255);
+ }
+ {
+ std::cout << __FILE__ << "[" <<__LINE__<<"]"<<std::endl;
+ BOOST_AUTO(scale, (to_signed_number<255,0>()));
+ BOOST_TEST(scale.count()==255);
+ }
+ {
+ typedef unsigned_number<8,0> T;
+ std::cout << T::min_index << std::endl;
+ std::cout << T::max_index << std::endl;
+ }
+ {
+ typedef signed_number<8,0> T;
+ std::cout << T::min_index << std::endl;
+ std::cout << T::max_index << std::endl;
+ std::cout << sizeof(long int) << std::endl;
+ }
+
+ return boost::report_errors();
+}
+
Added: sandbox/fixed_point/libs/fixed_point/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/fixed_point/libs/fixed_point/test/Jamfile.v2 2012-02-29 13:10:58 EST (Wed, 29 Feb 2012)
@@ -0,0 +1,27 @@
+#~ Copyright Vicente J. Botet Escriba 2012
+#~ 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)
+
+
+project
+ : requirements
+ #<library>/boost/test//boost_test_exec_monitor/<link>static
+ <include>../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-Wshadow
+ <toolset>gcc:<warnings-as-errors>on
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>gcc:<cxxflags>-Wcast-align
+ <toolset>intel:<warnings-as-errors>on
+ <toolset>msvc:<warnings-as-errors>on
+ ;
+
+import testing ;
+
+
+test-suite examples :
+ [ run ../example/ex_xx.cpp ]
+ ;
+
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