first commit

This commit is contained in:
murdle
2026-03-01 02:38:58 +02:00
commit 19250b9db4
19111 changed files with 4358159 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_BOUNDS_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_BOUNDS_12NOV2002_HPP
#include "boost/numeric/conversion/detail/bounds.hpp"
namespace boost { namespace numeric
{
template<class N>
struct bounds : boundsdetail::get_impl<N>::type
{} ;
} } // namespace boost::numeric
#endif

View File

@@ -0,0 +1,61 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
//
// Revision History
//
// 19 Nov 2001 Syntatic changes as suggested by Darin Adler (Fernando Cacciola)
// 08 Nov 2001 Fixes to accommodate MSVC (Fernando Cacciola)
// 04 Nov 2001 Fixes to accommodate gcc2.92 (Fernando Cacciola)
// 30 Oct 2001 Some fixes suggested by Daryle Walker (Fernando Cacciola)
// 25 Oct 2001 Initial boostification (Fernando Cacciola)
// 23 Jan 2004 Inital add to cvs (post review)s
// 22 Jun 2011 Added support for specializing cast policies via numeric_cast_traits (Brandon Kohn).
//
#ifndef BOOST_NUMERIC_CONVERSION_CAST_25OCT2001_HPP
#define BOOST_NUMERIC_CONVERSION_CAST_25OCT2001_HPP
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
# include<boost/numeric/conversion/detail/old_numeric_cast.hpp>
#else
#include <boost/type.hpp>
#include <boost/numeric/conversion/converter.hpp>
#include <boost/numeric/conversion/numeric_cast_traits.hpp>
namespace boost
{
template <typename Target, typename Source>
inline Target numeric_cast( Source arg )
{
typedef numeric::conversion_traits<Target, Source> conv_traits;
typedef numeric::numeric_cast_traits<Target, Source> cast_traits;
typedef boost::numeric::converter
<
Target,
Source,
conv_traits,
typename cast_traits::overflow_policy,
typename cast_traits::rounding_policy,
boost::numeric::raw_converter< conv_traits >,
typename cast_traits::range_checking_policy
> converter;
return converter::convert(arg);
}
using numeric::bad_numeric_cast;
} // namespace boost
#endif
#endif

View File

@@ -0,0 +1,39 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_CONVERSION_TRAITS_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_CONVERSION_TRAITS_FLC_12NOV2002_HPP
#include "boost/numeric/conversion/detail/conversion_traits.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/config.hpp"
namespace boost { namespace numeric
{
template<class T, class S>
struct conversion_traits
: convdetail::get_conversion_traits<T,S>::type
{
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
typedef typename convdetail::get_conversion_traits<T,S>::type base_;
typedef typename base_::target_type target_type;
typedef typename base_::source_type source_type;
typedef typename base_::result_type result_type;
typedef typename base_::argument_type argument_type;
#endif
} ;
} } // namespace boost::numeric
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,68 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_CONVERTER_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_CONVERTER_FLC_12NOV2002_HPP
#include "boost/numeric/conversion/conversion_traits.hpp"
#include "boost/numeric/conversion/converter_policies.hpp"
#include "boost/numeric/conversion/detail/converter.hpp"
namespace boost { namespace numeric
{
template<class T,
class S,
class Traits = conversion_traits<T,S>,
class OverflowHandler = def_overflow_handler,
class Float2IntRounder = Trunc< BOOST_DEDUCED_TYPENAME Traits::source_type> ,
class RawConverter = raw_converter<Traits>,
class UserRangeChecker = UseInternalRangeChecker
>
struct converter : convdetail::get_converter_impl<Traits,
OverflowHandler,
Float2IntRounder,
RawConverter,
UserRangeChecker
>::type
{
typedef Traits traits ;
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::result_type result_type ;
result_type operator() ( argument_type s ) const { return this->convert(s) ; }
} ;
template<class S,
class OverflowHandler = def_overflow_handler,
class Float2IntRounder = Trunc<S> ,
class UserRangeChecker = UseInternalRangeChecker
>
struct make_converter_from
{
template<class T,
class Traits = conversion_traits<T,S>,
class RawConverter = raw_converter<Traits>
>
struct to
{
typedef converter<T,S,Traits,OverflowHandler,Float2IntRounder,RawConverter,UserRangeChecker> type ;
} ;
} ;
} } // namespace boost::numeric
#endif

View File

@@ -0,0 +1,194 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
#include <typeinfo> // for std::bad_cast
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
#include <boost/throw_exception.hpp>
#include <functional>
#include "boost/type_traits/is_arithmetic.hpp"
#include "boost/mpl/if.hpp"
#include "boost/mpl/integral_c.hpp"
namespace boost { namespace numeric
{
template<class S>
struct Trunc
{
typedef S source_type ;
typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor ;
using std::ceil ;
#endif
return s < static_cast<S>(0) ? ceil(s) : floor(s) ;
}
typedef mpl::integral_c< std::float_round_style, std::round_toward_zero> round_style ;
} ;
template<class S>
struct Floor
{
typedef S source_type ;
typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor ;
#endif
return floor(s) ;
}
typedef mpl::integral_c< std::float_round_style, std::round_toward_neg_infinity> round_style ;
} ;
template<class S>
struct Ceil
{
typedef S source_type ;
typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::ceil ;
#endif
return ceil(s) ;
}
typedef mpl::integral_c< std::float_round_style, std::round_toward_infinity> round_style ;
} ;
template<class S>
struct RoundEven
{
typedef S source_type ;
typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
static source_type nearbyint ( argument_type s )
{
// Algorithm contributed by Guillaume Melquiond
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor ;
using std::ceil ;
#endif
// only works inside the range not at the boundaries
S prev = floor(s);
S next = ceil(s);
S rt = (s - prev) - (next - s); // remainder type
S const zero(0.0);
S const two(2.0);
if ( rt < zero )
return prev;
else if ( rt > zero )
return next;
else
{
bool is_prev_even = two * floor(prev / two) == prev ;
return ( is_prev_even ? prev : next ) ;
}
}
typedef mpl::integral_c< std::float_round_style, std::round_to_nearest> round_style ;
} ;
enum range_check_result
{
cInRange = 0 ,
cNegOverflow = 1 ,
cPosOverflow = 2
} ;
class bad_numeric_cast : public std::bad_cast
{
public:
virtual const char * what() const throw()
{ return "bad numeric conversion: overflow"; }
};
class negative_overflow : public bad_numeric_cast
{
public:
virtual const char * what() const throw()
{ return "bad numeric conversion: negative overflow"; }
};
class positive_overflow : public bad_numeric_cast
{
public:
virtual const char * what() const throw()
{ return "bad numeric conversion: positive overflow"; }
};
struct def_overflow_handler
{
void operator() ( range_check_result r ) // throw(negative_overflow,positive_overflow)
{
#ifndef BOOST_NO_EXCEPTIONS
if ( r == cNegOverflow )
throw negative_overflow() ;
else if ( r == cPosOverflow )
throw positive_overflow() ;
#else
if ( r == cNegOverflow )
::boost::throw_exception(negative_overflow()) ;
else if ( r == cPosOverflow )
::boost::throw_exception(positive_overflow()) ;
#endif
}
} ;
struct silent_overflow_handler
{
void operator() ( range_check_result ) {} // throw()
} ;
template<class Traits>
struct raw_converter
{
typedef typename Traits::result_type result_type ;
typedef typename Traits::argument_type argument_type ;
static result_type low_level_convert ( argument_type s ) { return static_cast<result_type>(s) ; }
} ;
struct UseInternalRangeChecker {} ;
} } // namespace boost::numeric
#endif

View File

@@ -0,0 +1,58 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_BOUNDS_DETAIL_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_BOUNDS_DETAIL_FLC_12NOV2002_HPP
#include "boost/limits.hpp"
#include "boost/config.hpp"
#include "boost/mpl/if.hpp"
namespace boost { namespace numeric { namespace boundsdetail
{
template<class N>
class Integral
{
typedef std::numeric_limits<N> limits ;
public :
static N lowest () { return limits::min BOOST_PREVENT_MACRO_SUBSTITUTION (); }
static N highest () { return limits::max BOOST_PREVENT_MACRO_SUBSTITUTION (); }
static N smallest() { return static_cast<N>(1); }
} ;
template<class N>
class Float
{
typedef std::numeric_limits<N> limits ;
public :
static N lowest () { return static_cast<N>(-limits::max BOOST_PREVENT_MACRO_SUBSTITUTION ()) ; }
static N highest () { return limits::max BOOST_PREVENT_MACRO_SUBSTITUTION (); }
static N smallest() { return limits::min BOOST_PREVENT_MACRO_SUBSTITUTION (); }
} ;
template<class N>
struct get_impl
{
typedef mpl::bool_< ::std::numeric_limits<N>::is_integer > is_int ;
typedef Integral<N> impl_int ;
typedef Float <N> impl_float ;
typedef typename mpl::if_<is_int,impl_int,impl_float>::type type ;
} ;
} } } // namespace boost::numeric::boundsdetail.
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,97 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
#include "boost/type_traits/is_arithmetic.hpp"
#include "boost/type_traits/is_same.hpp"
#include "boost/type_traits/remove_cv.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/numeric/conversion/detail/int_float_mixture.hpp"
#include "boost/numeric/conversion/detail/sign_mixture.hpp"
#include "boost/numeric/conversion/detail/udt_builtin_mixture.hpp"
#include "boost/numeric/conversion/detail/is_subranged.hpp"
namespace boost { namespace numeric { namespace convdetail
{
//-------------------------------------------------------------------
// Implementation of the Conversion Traits for T != S
//
// This is a VISIBLE base class of the user-level conversion_traits<> class.
//-------------------------------------------------------------------
template<class T,class S>
struct non_trivial_traits_impl
{
typedef typename get_int_float_mixture <T,S>::type int_float_mixture ;
typedef typename get_sign_mixture <T,S>::type sign_mixture ;
typedef typename get_udt_builtin_mixture <T,S>::type udt_builtin_mixture ;
typedef typename get_is_subranged<T,S>::type subranged ;
typedef mpl::false_ trivial ;
typedef T target_type ;
typedef S source_type ;
typedef T result_type ;
typedef typename mpl::if_< is_arithmetic<S>, S, S const&>::type argument_type ;
typedef typename mpl::if_<subranged,S,T>::type supertype ;
typedef typename mpl::if_<subranged,T,S>::type subtype ;
} ;
//-------------------------------------------------------------------
// Implementation of the Conversion Traits for T == S
//
// This is a VISIBLE base class of the user-level conversion_traits<> class.
//-------------------------------------------------------------------
template<class N>
struct trivial_traits_impl
{
typedef typename get_int_float_mixture <N,N>::type int_float_mixture ;
typedef typename get_sign_mixture <N,N>::type sign_mixture ;
typedef typename get_udt_builtin_mixture<N,N>::type udt_builtin_mixture ;
typedef mpl::false_ subranged ;
typedef mpl::true_ trivial ;
typedef N target_type ;
typedef N source_type ;
typedef N const& result_type ;
typedef N const& argument_type ;
typedef N supertype ;
typedef N subtype ;
} ;
//-------------------------------------------------------------------
// Top level implementation selector.
//-------------------------------------------------------------------
template<class T, class S>
struct get_conversion_traits
{
typedef typename remove_cv<T>::type target_type ;
typedef typename remove_cv<S>::type source_type ;
typedef typename is_same<target_type,source_type>::type is_trivial ;
typedef trivial_traits_impl <target_type> trivial_imp ;
typedef non_trivial_traits_impl<target_type,source_type> non_trivial_imp ;
typedef typename mpl::if_<is_trivial,trivial_imp,non_trivial_imp>::type type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif

View File

@@ -0,0 +1,602 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_CONVERTER_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_CONVERTER_FLC_12NOV2002_HPP
#include <functional>
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/numeric/conversion/detail/conversion_traits.hpp"
#include "boost/numeric/conversion/bounds.hpp"
#include "boost/type_traits/is_same.hpp"
#include "boost/mpl/integral_c.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants representing rounding modes
typedef mpl::integral_c<std::float_round_style, std::round_toward_zero> round2zero_c ;
typedef mpl::integral_c<std::float_round_style, std::round_to_nearest> round2nearest_c ;
typedef mpl::integral_c<std::float_round_style, std::round_toward_infinity> round2inf_c ;
typedef mpl::integral_c<std::float_round_style, std::round_toward_neg_infinity> round2neg_inf_c ;
// Metafunction:
//
// for_round_style<RoundStyle,RoundToZero,RoundToNearest,RoundToInf,RoundToNegInf>::type
//
// {RoundStyle} Integral Constant specifying a round style as declared above.
// {RoundToZero,RoundToNearest,RoundToInf,RoundToNegInf} arbitrary types.
//
// Selects one of the 4 types according to the value of RoundStyle.
//
template<class RoundStyle,class RoundToZero,class RoundToNearest,class RoundToInf,class RoundToNegInf>
struct for_round_style
{
typedef ct_switch4<RoundStyle
, round2zero_c, round2nearest_c, round2inf_c // round2neg_inf_c
, RoundToZero , RoundToNearest , RoundToInf , RoundToNegInf
> selector ;
typedef typename selector::type type ;
} ;
//--------------------------------------------------------------------------
// Range Checking Logic.
//
// The range checking logic is built up by combining 1 or 2 predicates.
// Each predicate is encapsulated in a template class and exposes
// the static member function 'apply'.
//
//--------------------------------------------------------------------------
// Because a particular logic can combine either 1 or two predicates, the following
// tags are used to allow the predicate applier to receive 2 preds, but optimize away
// one of them if it is 'non-applicable'
struct non_applicable { typedef mpl::false_ do_apply ; } ;
struct applicable { typedef mpl::true_ do_apply ; } ;
//--------------------------------------------------------------------------
//
// Range Checking Logic implementations.
//
// The following classes, collectivelly named 'Predicates', are instantiated within
// the corresponding range checkers.
// Their static member function 'apply' is called to perform the actual range checking logic.
//--------------------------------------------------------------------------
// s < Lowest(T) ? cNegOverflow : cInRange
//
template<class Traits>
struct LT_LoT : applicable
{
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s < static_cast<S>(bounds<T>::lowest()) ? cNegOverflow : cInRange ;
}
} ;
// s < 0 ? cNegOverflow : cInRange
//
template<class Traits>
struct LT_Zero : applicable
{
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s < static_cast<S>(0) ? cNegOverflow : cInRange ;
}
} ;
// s <= Lowest(T)-1 ? cNegOverflow : cInRange
//
template<class Traits>
struct LE_PrevLoT : applicable
{
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s <= static_cast<S>(bounds<T>::lowest()) - static_cast<S>(1.0)
? cNegOverflow : cInRange ;
}
} ;
// s < Lowest(T)-0.5 ? cNegOverflow : cInRange
//
template<class Traits>
struct LT_HalfPrevLoT : applicable
{
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s < static_cast<S>(bounds<T>::lowest()) - static_cast<S>(0.5)
? cNegOverflow : cInRange ;
}
} ;
// s > Highest(T) ? cPosOverflow : cInRange
//
template<class Traits>
struct GT_HiT : applicable
{
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s > static_cast<S>(bounds<T>::highest())
? cPosOverflow : cInRange ;
}
} ;
// s >= Lowest(T) + 1 ? cPosOverflow : cInRange
//
template<class Traits>
struct GE_SuccHiT : applicable
{
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s >= static_cast<S>(bounds<T>::highest()) + static_cast<S>(1.0)
? cPosOverflow : cInRange ;
}
} ;
// s >= Lowest(T) + 0.5 ? cPosgOverflow : cInRange
//
template<class Traits>
struct GT_HalfSuccHiT : applicable
{
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename Traits::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
return s >= static_cast<S>(bounds<T>::highest()) + static_cast<S>(0.5)
? cPosOverflow : cInRange ;
}
} ;
//--------------------------------------------------------------------------
//
// Predicate Combiner.
//
// This helper classes are used to possibly combine the range checking logic
// individually performed by the predicates
//
//--------------------------------------------------------------------------
// Applies both predicates: first 'PredA', and if it equals 'cInRange', 'PredB'
template<class PredA, class PredB>
struct applyBoth
{
typedef typename PredA::argument_type argument_type ;
static range_check_result apply ( argument_type s )
{
range_check_result r = PredA::apply(s) ;
if ( r == cInRange )
r = PredB::apply(s);
return r ;
}
} ;
template<class PredA, class PredB>
struct combine
{
typedef applyBoth<PredA,PredB> Both ;
typedef void NNone ; // 'None' is defined as a macro in (/usr/X11R6/include/X11/X.h)
typedef typename PredA::do_apply do_applyA ;
typedef typename PredB::do_apply do_applyB ;
typedef typename for_both<do_applyA, do_applyB, Both, PredA, PredB, NNone>::type type ;
} ;
//--------------------------------------------------------------------------
// Range Checker classes.
//
// The following classes are VISIBLE base classes of the user-level converter<> class.
// They supply the optimized 'out_of_range()' and 'validate_range()' static member functions
// visible in the user interface.
//
//--------------------------------------------------------------------------
// Dummy range checker.
template<class Traits>
struct dummy_range_checker
{
typedef typename Traits::argument_type argument_type ;
static range_check_result out_of_range ( argument_type ) { return cInRange ; }
static void validate_range ( argument_type ) {}
} ;
// Generic range checker.
//
// All the range checking logic for all possible combinations of source and target
// can be arranged in terms of one or two predicates, which test overflow on both neg/pos 'sides'
// of the ranges.
//
// These predicates are given here as IsNegOverflow and IsPosOverflow.
//
template<class Traits, class IsNegOverflow, class IsPosOverflow, class OverflowHandler>
struct generic_range_checker
{
typedef OverflowHandler overflow_handler ;
typedef typename Traits::argument_type argument_type ;
static range_check_result out_of_range ( argument_type s )
{
typedef typename combine<IsNegOverflow,IsPosOverflow>::type Predicate ;
return Predicate::apply(s);
}
static void validate_range ( argument_type s )
{ OverflowHandler()( out_of_range(s) ) ; }
} ;
//--------------------------------------------------------------------------
//
// Selectors for the optimized Range Checker class.
//
//--------------------------------------------------------------------------
template<class Traits,class OverflowHandler>
struct GetRC_Sig2Sig_or_Unsig2Unsig
{
typedef dummy_range_checker<Traits> Dummy ;
typedef LT_LoT<Traits> Pred1 ;
typedef GT_HiT<Traits> Pred2 ;
typedef generic_range_checker<Traits,Pred1,Pred2,OverflowHandler> Normal ;
typedef typename Traits::subranged subranged ;
typedef typename mpl::if_<subranged,Normal,Dummy>::type type ;
} ;
template<class Traits, class OverflowHandler>
struct GetRC_Sig2Unsig
{
typedef LT_Zero<Traits> Pred1 ;
typedef GT_HiT <Traits> Pred2 ;
typedef generic_range_checker<Traits,Pred1,Pred2,OverflowHandler> ChoiceA ;
typedef generic_range_checker<Traits,Pred1,non_applicable,OverflowHandler> ChoiceB ;
typedef typename Traits::target_type T ;
typedef typename Traits::source_type S ;
typedef typename subranged_Unsig2Sig<S,T>::type oposite_subranged ;
typedef typename mpl::not_<oposite_subranged>::type positively_subranged ;
typedef typename mpl::if_<positively_subranged,ChoiceA,ChoiceB>::type type ;
} ;
template<class Traits, class OverflowHandler>
struct GetRC_Unsig2Sig
{
typedef GT_HiT<Traits> Pred1 ;
typedef generic_range_checker<Traits,non_applicable,Pred1,OverflowHandler> type ;
} ;
template<class Traits,class OverflowHandler>
struct GetRC_Int2Int
{
typedef GetRC_Sig2Sig_or_Unsig2Unsig<Traits,OverflowHandler> Sig2SigQ ;
typedef GetRC_Sig2Unsig <Traits,OverflowHandler> Sig2UnsigQ ;
typedef GetRC_Unsig2Sig <Traits,OverflowHandler> Unsig2SigQ ;
typedef Sig2SigQ Unsig2UnsigQ ;
typedef typename Traits::sign_mixture sign_mixture ;
typedef typename
for_sign_mixture<sign_mixture,Sig2SigQ,Sig2UnsigQ,Unsig2SigQ,Unsig2UnsigQ>::type
selector ;
typedef typename selector::type type ;
} ;
template<class Traits>
struct GetRC_Int2Float
{
typedef dummy_range_checker<Traits> type ;
} ;
template<class Traits, class OverflowHandler, class Float2IntRounder>
struct GetRC_Float2Int
{
typedef LE_PrevLoT <Traits> Pred1 ;
typedef GE_SuccHiT <Traits> Pred2 ;
typedef LT_HalfPrevLoT<Traits> Pred3 ;
typedef GT_HalfSuccHiT<Traits> Pred4 ;
typedef GT_HiT <Traits> Pred5 ;
typedef LT_LoT <Traits> Pred6 ;
typedef generic_range_checker<Traits,Pred1,Pred2,OverflowHandler> ToZero ;
typedef generic_range_checker<Traits,Pred3,Pred4,OverflowHandler> ToNearest ;
typedef generic_range_checker<Traits,Pred1,Pred5,OverflowHandler> ToInf ;
typedef generic_range_checker<Traits,Pred6,Pred2,OverflowHandler> ToNegInf ;
typedef typename Float2IntRounder::round_style round_style ;
typedef typename for_round_style<round_style,ToZero,ToNearest,ToInf,ToNegInf>::type type ;
} ;
template<class Traits, class OverflowHandler>
struct GetRC_Float2Float
{
typedef dummy_range_checker<Traits> Dummy ;
typedef LT_LoT<Traits> Pred1 ;
typedef GT_HiT<Traits> Pred2 ;
typedef generic_range_checker<Traits,Pred1,Pred2,OverflowHandler> Normal ;
typedef typename Traits::subranged subranged ;
typedef typename mpl::if_<subranged,Normal,Dummy>::type type ;
} ;
template<class Traits, class OverflowHandler, class Float2IntRounder>
struct GetRC_BuiltIn2BuiltIn
{
typedef GetRC_Int2Int<Traits,OverflowHandler> Int2IntQ ;
typedef GetRC_Int2Float<Traits> Int2FloatQ ;
typedef GetRC_Float2Int<Traits,OverflowHandler,Float2IntRounder> Float2IntQ ;
typedef GetRC_Float2Float<Traits,OverflowHandler> Float2FloatQ ;
typedef typename Traits::int_float_mixture int_float_mixture ;
typedef typename for_int_float_mixture<int_float_mixture, Int2IntQ, Int2FloatQ, Float2IntQ, Float2FloatQ>::type selector ;
typedef typename selector::type type ;
} ;
template<class Traits, class OverflowHandler, class Float2IntRounder>
struct GetRC
{
typedef GetRC_BuiltIn2BuiltIn<Traits,OverflowHandler,Float2IntRounder> BuiltIn2BuiltInQ ;
typedef dummy_range_checker<Traits> Dummy ;
typedef mpl::identity<Dummy> DummyQ ;
typedef typename Traits::udt_builtin_mixture udt_builtin_mixture ;
typedef typename for_udt_builtin_mixture<udt_builtin_mixture,BuiltIn2BuiltInQ,DummyQ,DummyQ,DummyQ>::type selector ;
typedef typename selector::type type ;
} ;
//--------------------------------------------------------------------------
// Converter classes.
//
// The following classes are VISIBLE base classes of the user-level converter<> class.
// They supply the optimized 'nearbyint()' and 'convert()' static member functions
// visible in the user interface.
//
//--------------------------------------------------------------------------
//
// Trivial Converter : used when (cv-unqualified) T == (cv-unqualified) S
//
template<class Traits>
struct trivial_converter_impl : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public dummy_range_checker<Traits>
{
typedef Traits traits ;
typedef typename Traits::source_type source_type ;
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::result_type result_type ;
static result_type low_level_convert ( argument_type s ) { return s ; }
static source_type nearbyint ( argument_type s ) { return s ; }
static result_type convert ( argument_type s ) { return s ; }
} ;
//
// Rounding Converter : used for float to integral conversions.
//
template<class Traits,class RangeChecker,class RawConverter,class Float2IntRounder>
struct rounding_converter : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public RangeChecker
,public Float2IntRounder
,public RawConverter
{
typedef RangeChecker RangeCheckerBase ;
typedef Float2IntRounder Float2IntRounderBase ;
typedef RawConverter RawConverterBase ;
typedef Traits traits ;
typedef typename Traits::source_type source_type ;
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::result_type result_type ;
static result_type convert ( argument_type s )
{
RangeCheckerBase::validate_range(s);
source_type s1 = Float2IntRounderBase::nearbyint(s);
return RawConverterBase::low_level_convert(s1);
}
} ;
//
// Non-Rounding Converter : used for all other conversions.
//
template<class Traits,class RangeChecker,class RawConverter>
struct non_rounding_converter : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public RangeChecker
,public RawConverter
{
typedef RangeChecker RangeCheckerBase ;
typedef RawConverter RawConverterBase ;
typedef Traits traits ;
typedef typename Traits::source_type source_type ;
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::result_type result_type ;
static source_type nearbyint ( argument_type s ) { return s ; }
static result_type convert ( argument_type s )
{
RangeCheckerBase::validate_range(s);
return RawConverterBase::low_level_convert(s);
}
} ;
//--------------------------------------------------------------------------
//
// Selectors for the optimized Converter class.
//
//--------------------------------------------------------------------------
template<class Traits,class OverflowHandler,class Float2IntRounder,class RawConverter, class UserRangeChecker>
struct get_non_trivial_converter
{
typedef GetRC<Traits,OverflowHandler,Float2IntRounder> InternalRangeCheckerQ ;
typedef is_same<UserRangeChecker,UseInternalRangeChecker> use_internal_RC ;
typedef mpl::identity<UserRangeChecker> UserRangeCheckerQ ;
typedef typename
mpl::eval_if<use_internal_RC,InternalRangeCheckerQ,UserRangeCheckerQ>::type
RangeChecker ;
typedef non_rounding_converter<Traits,RangeChecker,RawConverter> NonRounding ;
typedef rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder> Rounding ;
typedef mpl::identity<NonRounding> NonRoundingQ ;
typedef mpl::identity<Rounding> RoundingQ ;
typedef typename Traits::int_float_mixture int_float_mixture ;
typedef typename
for_int_float_mixture<int_float_mixture, NonRoundingQ, NonRoundingQ, RoundingQ, NonRoundingQ>::type
selector ;
typedef typename selector::type type ;
} ;
template< class Traits
,class OverflowHandler
,class Float2IntRounder
,class RawConverter
,class UserRangeChecker
>
struct get_converter_impl
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT( 0x0561 ) )
// bcc55 prefers sometimes template parameters to be explicit local types.
// (notice that is is illegal to reuse the names like this)
typedef Traits Traits ;
typedef OverflowHandler OverflowHandler ;
typedef Float2IntRounder Float2IntRounder ;
typedef RawConverter RawConverter ;
typedef UserRangeChecker UserRangeChecker ;
#endif
typedef trivial_converter_impl<Traits> Trivial ;
typedef mpl::identity <Trivial> TrivialQ ;
typedef get_non_trivial_converter< Traits
,OverflowHandler
,Float2IntRounder
,RawConverter
,UserRangeChecker
> NonTrivialQ ;
typedef typename Traits::trivial trivial ;
typedef typename mpl::eval_if<trivial,TrivialQ,NonTrivialQ>::type type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif

View File

@@ -0,0 +1,72 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_INT_FLOAT_MIXTURE_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_INT_FLOAT_MIXTURE_FLC_12NOV2002_HPP
#include "boost/config.hpp"
#include "boost/limits.hpp"
#include "boost/numeric/conversion/int_float_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'IntFloatMixture'
typedef mpl::integral_c<int_float_mixture_enum, integral_to_integral> int2int_c ;
typedef mpl::integral_c<int_float_mixture_enum, integral_to_float> int2float_c ;
typedef mpl::integral_c<int_float_mixture_enum, float_to_integral> float2int_c ;
typedef mpl::integral_c<int_float_mixture_enum, float_to_float> float2float_c ;
// Metafunction:
//
// get_int_float_mixture<T,S>::type
//
// Selects the appropriate Int-Float Mixture Integral Constant for the combination T,S.
//
template<class T,class S>
struct get_int_float_mixture
{
typedef mpl::bool_< ::std::numeric_limits<S>::is_integer > S_int ;
typedef mpl::bool_< ::std::numeric_limits<T>::is_integer > T_int ;
typedef typename
for_both<S_int, T_int, int2int_c, int2float_c, float2int_c, float2float_c>::type
type ;
} ;
// Metafunction:
//
// for_int_float_mixture<Mixture,int_int,int_float,float_int,float_float>::type
//
// {Mixture} is one of the Integral Constants for Mixture, declared above.
// {int_int,int_float,float_int,float_float} are aribtrary types. (not metafunctions)
//
// According to the value of 'IntFloatMixture', selects the corresponding type.
//
template<class IntFloatMixture, class Int2Int, class Int2Float, class Float2Int, class Float2Float>
struct for_int_float_mixture
{
typedef typename
ct_switch4<IntFloatMixture
,int2int_c, int2float_c, float2int_c // default
,Int2Int , Int2Float , Float2Int , Float2Float
>::type
type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,234 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_IS_SUBRANGED_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_IS_SUBRANGED_FLC_12NOV2002_HPP
#include "boost/config.hpp"
#include "boost/limits.hpp"
#include "boost/mpl/int.hpp"
#include "boost/mpl/multiplies.hpp"
#include "boost/mpl/less.hpp"
#include "boost/mpl/equal_to.hpp"
#include "boost/type_traits/is_same.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/numeric/conversion/detail/int_float_mixture.hpp"
#include "boost/numeric/conversion/detail/sign_mixture.hpp"
#include "boost/numeric/conversion/detail/udt_builtin_mixture.hpp"
namespace boost { namespace numeric { namespace convdetail
{
//---------------------------------------------------------------
// Implementations of the compile time predicate "T is subranged"
//---------------------------------------------------------------
// for integral to integral conversions
template<class T,class S>
struct subranged_Sig2Unsig
{
// Signed to unsigned conversions are 'subranged' because of possible loose
// of negative values.
typedef mpl::true_ type ;
} ;
// for unsigned integral to signed integral conversions
template<class T,class S>
struct subranged_Unsig2Sig
{
// IMPORTANT NOTE:
//
// This code assumes that signed/unsigned integral values are represented
// such that:
//
// numeric_limits<signed T>::digits + 1 == numeric_limits<unsigned T>::digits
//
// The '+1' is required since numeric_limits<>::digits gives 1 bit less for signed integral types.
//
// This fact is used by the following logic:
//
// if ( (numeric_limits<T>::digits+1) < (2*numeric_limits<S>::digits) )
// then the conversion is subranged.
//
typedef mpl::int_< ::std::numeric_limits<S>::digits > S_digits ;
typedef mpl::int_< ::std::numeric_limits<T>::digits > T_digits ;
// T is signed, so take digits+1
typedef typename T_digits::next u_T_digits ;
typedef mpl::int_<2> Two ;
typedef typename mpl::multiplies<S_digits,Two>::type S_digits_times_2 ;
typedef typename mpl::less<u_T_digits,S_digits_times_2>::type type ;
} ;
// for integral to integral conversions of the same sign.
template<class T,class S>
struct subranged_SameSign
{
// An integral conversion of the same sign is subranged if digits(T) < digits(S).
typedef mpl::int_< ::std::numeric_limits<S>::digits > S_digits ;
typedef mpl::int_< ::std::numeric_limits<T>::digits > T_digits ;
typedef typename mpl::less<T_digits,S_digits>::type type ;
} ;
// for integral to float conversions
template<class T,class S>
struct subranged_Int2Float
{
typedef mpl::false_ type ;
} ;
// for float to integral conversions
template<class T,class S>
struct subranged_Float2Int
{
typedef mpl::true_ type ;
} ;
// for float to float conversions
template<class T,class S>
struct subranged_Float2Float
{
// If both T and S are floats,
// compare exponent bits and if they match, mantisa bits.
typedef mpl::int_< ::std::numeric_limits<S>::digits > S_mantisa ;
typedef mpl::int_< ::std::numeric_limits<T>::digits > T_mantisa ;
typedef mpl::int_< ::std::numeric_limits<S>::max_exponent > S_exponent ;
typedef mpl::int_< ::std::numeric_limits<T>::max_exponent > T_exponent ;
typedef typename mpl::less<T_exponent,S_exponent>::type T_smaller_exponent ;
typedef typename mpl::equal_to<T_exponent,S_exponent>::type equal_exponents ;
typedef mpl::less<T_mantisa,S_mantisa> T_smaller_mantisa ;
typedef mpl::eval_if<equal_exponents,T_smaller_mantisa,mpl::false_> not_bigger_exponent_case ;
typedef typename
mpl::eval_if<T_smaller_exponent,mpl::true_,not_bigger_exponent_case>::type
type ;
} ;
// for Udt to built-in conversions
template<class T,class S>
struct subranged_Udt2BuiltIn
{
typedef mpl::true_ type ;
} ;
// for built-in to Udt conversions
template<class T,class S>
struct subranged_BuiltIn2Udt
{
typedef mpl::false_ type ;
} ;
// for Udt to Udt conversions
template<class T,class S>
struct subranged_Udt2Udt
{
typedef mpl::false_ type ;
} ;
//-------------------------------------------------------------------
// Selectors for the implementations of the subranged predicate
//-------------------------------------------------------------------
template<class T,class S>
struct get_subranged_Int2Int
{
typedef subranged_SameSign<T,S> Sig2Sig ;
typedef subranged_Sig2Unsig<T,S> Sig2Unsig ;
typedef subranged_Unsig2Sig<T,S> Unsig2Sig ;
typedef Sig2Sig Unsig2Unsig ;
typedef typename get_sign_mixture<T,S>::type sign_mixture ;
typedef typename
for_sign_mixture<sign_mixture, Sig2Sig, Sig2Unsig, Unsig2Sig, Unsig2Unsig>::type
type ;
} ;
template<class T,class S>
struct get_subranged_BuiltIn2BuiltIn
{
typedef get_subranged_Int2Int<T,S> Int2IntQ ;
typedef subranged_Int2Float <T,S> Int2Float ;
typedef subranged_Float2Int <T,S> Float2Int ;
typedef subranged_Float2Float<T,S> Float2Float ;
typedef mpl::identity<Int2Float > Int2FloatQ ;
typedef mpl::identity<Float2Int > Float2IntQ ;
typedef mpl::identity<Float2Float> Float2FloatQ ;
typedef typename get_int_float_mixture<T,S>::type int_float_mixture ;
typedef for_int_float_mixture<int_float_mixture, Int2IntQ, Int2FloatQ, Float2IntQ, Float2FloatQ> for_ ;
typedef typename for_::type selected ;
typedef typename selected::type type ;
} ;
template<class T,class S>
struct get_subranged
{
typedef get_subranged_BuiltIn2BuiltIn<T,S> BuiltIn2BuiltInQ ;
typedef subranged_BuiltIn2Udt<T,S> BuiltIn2Udt ;
typedef subranged_Udt2BuiltIn<T,S> Udt2BuiltIn ;
typedef subranged_Udt2Udt<T,S> Udt2Udt ;
typedef mpl::identity<BuiltIn2Udt> BuiltIn2UdtQ ;
typedef mpl::identity<Udt2BuiltIn> Udt2BuiltInQ ;
typedef mpl::identity<Udt2Udt > Udt2UdtQ ;
typedef typename get_udt_builtin_mixture<T,S>::type udt_builtin_mixture ;
typedef typename
for_udt_builtin_mixture<udt_builtin_mixture, BuiltIn2BuiltInQ, BuiltIn2UdtQ, Udt2BuiltInQ, Udt2UdtQ>::type
selected ;
typedef typename selected::type selected2 ;
typedef typename selected2::type type ;
} ;
//-------------------------------------------------------------------
// Top level implementation selector.
//-------------------------------------------------------------------
template<class T, class S>
struct get_is_subranged
{
typedef get_subranged<T,S> non_trivial_case ;
typedef mpl::identity<mpl::false_> trivial_case ;
typedef is_same<T,S> is_trivial ;
typedef typename mpl::if_<is_trivial,trivial_case,non_trivial_case>::type selected ;
typedef typename selected::type type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif

View File

@@ -0,0 +1,120 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_META_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_META_FLC_12NOV2002_HPP
#include "boost/type_traits/remove_cv.hpp"
#include "boost/mpl/if.hpp"
#include "boost/mpl/eval_if.hpp"
#include "boost/mpl/equal_to.hpp"
#include "boost/mpl/not.hpp"
#include "boost/mpl/and.hpp"
#include "boost/mpl/bool.hpp"
#include "boost/mpl/identity.hpp"
namespace boost { namespace numeric { namespace convdetail
{
template< class T1, class T2>
struct equal_to
{
#if !defined(__BORLANDC__)
enum { x = ( BOOST_MPL_AUX_VALUE_WKND(T1)::value == BOOST_MPL_AUX_VALUE_WKND(T2)::value ) };
BOOST_STATIC_CONSTANT(bool, value = x);
typedef mpl::bool_<value> type;
#else
BOOST_STATIC_CONSTANT(bool, value = (
BOOST_MPL_AUX_VALUE_WKND(T1)::value
== BOOST_MPL_AUX_VALUE_WKND(T2)::value
));
typedef mpl::bool_<(
BOOST_MPL_AUX_VALUE_WKND(T1)::value
== BOOST_MPL_AUX_VALUE_WKND(T2)::value
)> type;
#endif
};
// Metafunction:
//
// ct_switch4<Value,Case0Val,Case1Val,Case2Val,Case0Type,Case1Type,Case2Type,DefaultType>::type
//
// {Value,Case(X)Val} are Integral Constants (such as: mpl::int_<>)
// {Case(X)Type,DefaultType} are arbitrary types. (not metafunctions)
//
// Returns Case(X)Type if Val==Case(X)Val; DefaultType otherwise.
//
template<class Value,
class Case0Val,
class Case1Val,
class Case2Val,
class Case0Type,
class Case1Type,
class Case2Type,
class DefaultType
>
struct ct_switch4
{
typedef mpl::identity<Case0Type> Case0TypeQ ;
typedef mpl::identity<Case1Type> Case1TypeQ ;
typedef equal_to<Value,Case0Val> is_case0 ;
typedef equal_to<Value,Case1Val> is_case1 ;
typedef equal_to<Value,Case2Val> is_case2 ;
typedef mpl::if_<is_case2,Case2Type,DefaultType> choose_2_3Q ;
typedef mpl::eval_if<is_case1,Case1TypeQ,choose_2_3Q> choose_1_2_3Q ;
typedef typename
mpl::eval_if<is_case0,Case0TypeQ,choose_1_2_3Q>::type
type ;
} ;
// Metafunction:
//
// for_both<expr0,expr1,TT,TF,FT,FF>::type
//
// {exp0,expr1} are Boolean Integral Constants
// {TT,TF,FT,FF} are aribtrary types. (not metafunctions)
//
// According to the combined boolean value of 'expr0 && expr1', selects the corresponding type.
//
template<class expr0, class expr1, class TT, class TF, class FT, class FF>
struct for_both
{
typedef mpl::identity<TF> TF_Q ;
typedef mpl::identity<TT> TT_Q ;
typedef typename mpl::not_<expr0>::type not_expr0 ;
typedef typename mpl::not_<expr1>::type not_expr1 ;
typedef typename mpl::and_<expr0,expr1>::type caseTT ;
typedef typename mpl::and_<expr0,not_expr1>::type caseTF ;
typedef typename mpl::and_<not_expr0,expr1>::type caseFT ;
typedef mpl::if_<caseFT,FT,FF> choose_FT_FF_Q ;
typedef mpl::eval_if<caseTF,TF_Q,choose_FT_FF_Q> choose_TF_FT_FF_Q ;
typedef typename mpl::eval_if<caseTT,TT_Q,choose_TF_FT_FF_Q>::type type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif

View File

@@ -0,0 +1,138 @@
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
#if !defined(BOOST_NUMERIC_CONVERSION_DONT_USE_PREPROCESSED_FILES)
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits_common.hpp>
#if !defined(BOOST_NO_LONG_LONG)
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits_long_long.hpp>
#endif
#else
#if !BOOST_PP_IS_ITERATING
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits_common.hpp")
#endif
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 1)
#endif
//! These are the assumed common built in fundamental types (not typedefs/macros.)
#define BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES() \
(char) \
(signed char) \
(unsigned char) \
(short) \
(unsigned short) \
(int) \
(unsigned int) \
(long) \
(unsigned long) \
(float) \
(double) \
(long double) \
/***/
#define BOOST_NUMERIC_CONVERSION_SEQ_A() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()
#define BOOST_NUMERIC_CONVERSION_SEQ_B() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()
namespace boost { namespace numeric {
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_A())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
#include BOOST_PP_ITERATE()
}}//namespace boost::numeric;
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(output: null)
#endif
#if ( defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES) ) || !defined(BOOST_NO_LONG_LONG)
#undef BOOST_NUMERIC_CONVERSION_SEQ_A
#undef BOOST_NUMERIC_CONVERSION_SEQ_B
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits_long_long.hpp")
#endif
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 1)
#endif
namespace boost { namespace numeric {
#define BOOST_NUMERIC_CONVERSION_SEQ_A() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()(boost::long_long_type)(boost::ulong_long_type)
#define BOOST_NUMERIC_CONVERSION_SEQ_B() (boost::long_long_type)(boost::ulong_long_type)
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_A())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
#include BOOST_PP_ITERATE()
}}//namespace boost::numeric;
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(output: null)
#endif
#endif
#undef BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES
#undef BOOST_NUMERIC_CONVERSION_SEQ_A
#undef BOOST_NUMERIC_CONVERSION_SEQ_B
#elif BOOST_PP_ITERATION_DEPTH() == 1
#define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_B())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
#include BOOST_PP_ITERATE()
#elif BOOST_PP_ITERATION_DEPTH() == 2
//! Generate default traits for the specified source and target.
#define BOOST_NUMERIC_CONVERSION_A BOOST_PP_FRAME_ITERATION(1)
#define BOOST_NUMERIC_CONVERSION_B BOOST_PP_FRAME_ITERATION(2)
template <>
struct numeric_cast_traits
<
BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_A, BOOST_NUMERIC_CONVERSION_SEQ_A())
, BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_SEQ_B())
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_SEQ_B())> rounding_policy;
};
#undef BOOST_NUMERIC_CONVERSION_A
#undef BOOST_NUMERIC_CONVERSION_B
#endif//! Depth 2.
#endif// BOOST_NUMERIC_CONVERSION_DONT_USE_PREPROCESSED_FILES

View File

@@ -0,0 +1,339 @@
// boost cast.hpp header file ----------------------------------------------//
// (C) Copyright Kevlin Henney and Dave Abrahams 1999.
// 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/conversion for Documentation.
// Revision History
// 23 JUN 05 Code extracted from /boost/cast.hpp into this new header.
// Keeps this legacy version of numeric_cast<> for old compilers
// wich can't compile the new version in /boost/numeric/conversion/cast.hpp
// (Fernando Cacciola)
// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included
// <boost/limits.hpp> instead (the workaround did not
// actually compile when BOOST_NO_LIMITS was defined in
// any case, so we loose nothing). (John Maddock)
// 21 Jan 01 Undid a bug I introduced yesterday. numeric_cast<> never
// worked with stock GCC; trying to get it to do that broke
// vc-stlport.
// 20 Jan 01 Moved BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS to config.hpp.
// Removed unused BOOST_EXPLICIT_TARGET macro. Moved
// boost::detail::type to boost/type.hpp. Made it compile with
// stock gcc again (Dave Abrahams)
// 29 Nov 00 Remove nested namespace cast, cleanup spacing before Formal
// Review (Beman Dawes)
// 19 Oct 00 Fix numeric_cast for floating-point types (Dave Abrahams)
// 15 Jul 00 Suppress numeric_cast warnings for GCC, Borland and MSVC
// (Dave Abrahams)
// 30 Jun 00 More MSVC6 wordarounds. See comments below. (Dave Abrahams)
// 28 Jun 00 Removed implicit_cast<>. See comment below. (Beman Dawes)
// 27 Jun 00 More MSVC6 workarounds
// 15 Jun 00 Add workarounds for MSVC6
// 2 Feb 00 Remove bad_numeric_cast ";" syntax error (Doncho Angelov)
// 26 Jan 00 Add missing throw() to bad_numeric_cast::what(0 (Adam Levar)
// 29 Dec 99 Change using declarations so usages in other namespaces work
// correctly (Dave Abrahams)
// 23 Sep 99 Change polymorphic_downcast assert to also detect M.I. errors
// as suggested Darin Adler and improved by Valentin Bonnard.
// 2 Sep 99 Remove controversial asserts, simplify, rename.
// 30 Aug 99 Move to cast.hpp, replace value_cast with numeric_cast,
// place in nested namespace.
// 3 Aug 99 Initial version
#ifndef BOOST_OLD_NUMERIC_CAST_HPP
#define BOOST_OLD_NUMERIC_CAST_HPP
# include <boost/config.hpp>
# include <cassert>
# include <typeinfo>
# include <boost/type.hpp>
# include <boost/limits.hpp>
# include <boost/numeric/conversion/converter_policies.hpp>
// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
// time if you use a template function which has template parameters that don't
// appear in the function's argument list.
//
// TODO: Add this to config.hpp?
// FLC: This macro is repeated in boost/cast.hpp but only locally (is undefined at the bottom)
// so is OK to reproduce it here.
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
# else
# define BOOST_EXPLICIT_DEFAULT_TARGET
# endif
namespace boost
{
using numeric::bad_numeric_cast;
// LEGACY numeric_cast [only for some old broken compilers] --------------------------------------//
// Contributed by Kevlin Henney
// numeric_cast ------------------------------------------------------------//
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_SGI_CPP_LIMITS)
namespace detail
{
template <class T>
struct signed_numeric_limits : std::numeric_limits<T>
{
static inline T min BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
return (std::numeric_limits<T>::min)() >= 0
// unary minus causes integral promotion, thus the static_cast<>
? static_cast<T>(-(std::numeric_limits<T>::max)())
: (std::numeric_limits<T>::min)();
};
};
// Move to namespace boost in utility.hpp?
template <class T, bool specialized>
struct fixed_numeric_limits_base
: public if_true< std::numeric_limits<T>::is_signed >
::BOOST_NESTED_TEMPLATE then< signed_numeric_limits<T>,
std::numeric_limits<T>
>::type
{};
template <class T>
struct fixed_numeric_limits
: fixed_numeric_limits_base<T,(std::numeric_limits<T>::is_specialized)>
{};
# ifdef BOOST_HAS_LONG_LONG
// cover implementations which supply no specialization for long
// long / unsigned long long. Not intended to be full
// numeric_limits replacements, but good enough for numeric_cast<>
template <>
struct fixed_numeric_limits_base< ::boost::long_long_type, false>
{
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
BOOST_STATIC_CONSTANT(bool, is_signed = true);
static ::boost::long_long_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
# ifdef LONGLONG_MAX
return LONGLONG_MAX;
# else
return 9223372036854775807LL; // hope this is portable
# endif
}
static ::boost::long_long_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
# ifdef LONGLONG_MIN
return LONGLONG_MIN;
# else
return -( 9223372036854775807LL )-1; // hope this is portable
# endif
}
};
template <>
struct fixed_numeric_limits_base< ::boost::ulong_long_type, false>
{
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
BOOST_STATIC_CONSTANT(bool, is_signed = false);
static ::boost::ulong_long_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
# ifdef ULONGLONG_MAX
return ULONGLONG_MAX;
# else
return 0xffffffffffffffffULL; // hope this is portable
# endif
}
static ::boost::ulong_long_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
};
# endif
} // namespace detail
// less_than_type_min -
// x_is_signed should be numeric_limits<X>::is_signed
// y_is_signed should be numeric_limits<Y>::is_signed
// y_min should be numeric_limits<Y>::min()
//
// check(x, y_min) returns true iff x < y_min without invoking comparisons
// between signed and unsigned values.
//
// "poor man's partial specialization" is in use here.
template <bool x_is_signed, bool y_is_signed>
struct less_than_type_min
{
template <class X, class Y>
static bool check(X x, Y y_min)
{ return x < y_min; }
};
template <>
struct less_than_type_min<false, true>
{
template <class X, class Y>
static bool check(X, Y)
{ return false; }
};
template <>
struct less_than_type_min<true, false>
{
template <class X, class Y>
static bool check(X x, Y)
{ return x < 0; }
};
// greater_than_type_max -
// same_sign should be:
// numeric_limits<X>::is_signed == numeric_limits<Y>::is_signed
// y_max should be numeric_limits<Y>::max()
//
// check(x, y_max) returns true iff x > y_max without invoking comparisons
// between signed and unsigned values.
//
// "poor man's partial specialization" is in use here.
template <bool same_sign, bool x_is_signed>
struct greater_than_type_max;
template<>
struct greater_than_type_max<true, true>
{
template <class X, class Y>
static inline bool check(X x, Y y_max)
{ return x > y_max; }
};
template <>
struct greater_than_type_max<false, true>
{
// What does the standard say about this? I think it's right, and it
// will work with every compiler I know of.
template <class X, class Y>
static inline bool check(X x, Y)
{ return x >= 0 && static_cast<X>(static_cast<Y>(x)) != x; }
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
// MSVC6 can't static_cast unsigned __int64 -> floating types
# define BOOST_UINT64_CAST(src_type) \
static inline bool check(src_type x, unsigned __int64) \
{ \
if (x < 0) return false; \
unsigned __int64 y = static_cast<unsigned __int64>(x); \
bool odd = y & 0x1; \
__int64 div2 = static_cast<__int64>(y >> 1); \
return ((static_cast<src_type>(div2) * 2.0) + odd) != x; \
}
BOOST_UINT64_CAST(long double);
BOOST_UINT64_CAST(double);
BOOST_UINT64_CAST(float);
# undef BOOST_UINT64_CAST
# endif
};
template<>
struct greater_than_type_max<true, false>
{
template <class X, class Y>
static inline bool check(X x, Y y_max)
{ return x > y_max; }
};
template <>
struct greater_than_type_max<false, false>
{
// What does the standard say about this? I think it's right, and it
// will work with every compiler I know of.
template <class X, class Y>
static inline bool check(X x, Y)
{ return static_cast<X>(static_cast<Y>(x)) != x; }
};
#else // use #pragma hacks if available
namespace detail
{
# if BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4018)
# pragma warning(disable : 4146)
#elif defined(__BORLANDC__)
# pragma option push -w-8041
# endif
// Move to namespace boost in utility.hpp?
template <class T>
struct fixed_numeric_limits : public std::numeric_limits<T>
{
static inline T min BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
return std::numeric_limits<T>::is_signed && (std::numeric_limits<T>::min)() >= 0
? T(-(std::numeric_limits<T>::max)()) : (std::numeric_limits<T>::min)();
}
};
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
# pragma option pop
# endif
} // namespace detail
#endif
template<typename Target, typename Source>
inline Target numeric_cast(Source arg BOOST_EXPLICIT_DEFAULT_TARGET)
{
// typedefs abbreviating respective trait classes
typedef detail::fixed_numeric_limits<Source> arg_traits;
typedef detail::fixed_numeric_limits<Target> result_traits;
#if defined(BOOST_STRICT_CONFIG) \
|| (!defined(__HP_aCC) || __HP_aCC > 33900) \
&& (!defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) \
|| defined(BOOST_SGI_CPP_LIMITS))
// typedefs that act as compile time assertions
// (to be replaced by boost compile time assertions
// as and when they become available and are stable)
typedef bool argument_must_be_numeric[arg_traits::is_specialized];
typedef bool result_must_be_numeric[result_traits::is_specialized];
const bool arg_is_signed = arg_traits::is_signed;
const bool result_is_signed = result_traits::is_signed;
const bool same_sign = arg_is_signed == result_is_signed;
if (less_than_type_min<arg_is_signed, result_is_signed>::check(arg, (result_traits::min)())
|| greater_than_type_max<same_sign, arg_is_signed>::check(arg, (result_traits::max)())
)
#else // We need to use #pragma hacks if available
# if BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4018)
#elif defined(__BORLANDC__)
#pragma option push -w-8012
# endif
if ((arg < 0 && !result_traits::is_signed) // loss of negative range
|| (arg_traits::is_signed && arg < (result_traits::min)()) // underflow
|| arg > (result_traits::max)()) // overflow
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
#pragma option pop
# endif
#endif
{
throw bad_numeric_cast();
}
return static_cast<Target>(arg);
} // numeric_cast
# undef BOOST_EXPLICIT_DEFAULT_TARGET
} // namespace boost
#endif // BOOST_OLD_NUMERIC_CAST_HPP

View File

@@ -0,0 +1,347 @@
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
namespace boost { namespace numeric {
template <>
struct numeric_cast_traits
<
char
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
char
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
signed char
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
signed char
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned char
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned char
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
short
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
short
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned short
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned short
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
int
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
int
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned int
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned int
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned long
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned long
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
float
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
float
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
double
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
double
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long double
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long double
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::long_long_type
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::long_long_type
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::ulong_long_type
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::ulong_long_type
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
}}

View File

@@ -0,0 +1,72 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_SIGN_MIXTURE_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_SIGN_MIXTURE_FLC_12NOV2002_HPP
#include "boost/config.hpp"
#include "boost/limits.hpp"
#include "boost/numeric/conversion/sign_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'SignMixture'
typedef mpl::integral_c<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
typedef mpl::integral_c<sign_mixture_enum, signed_to_signed> sig2sig_c ;
typedef mpl::integral_c<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
typedef mpl::integral_c<sign_mixture_enum, unsigned_to_signed> unsig2sig_c ;
// Metafunction:
//
// get_sign_mixture<T,S>::type
//
// Selects the appropriate SignMixture Integral Constant for the combination T,S.
//
template<class T,class S>
struct get_sign_mixture
{
typedef mpl::bool_< ::std::numeric_limits<S>::is_signed > S_signed ;
typedef mpl::bool_< ::std::numeric_limits<T>::is_signed > T_signed ;
typedef typename
for_both<S_signed, T_signed, sig2sig_c, sig2unsig_c, unsig2sig_c, unsig2unsig_c>::type
type ;
} ;
// Metafunction:
//
// for_sign_mixture<SignMixture,Sig2Sig,Sig2Unsig,Unsig2Sig,Unsig2Unsig>::type
//
// {SignMixture} is one of the Integral Constants for SignMixture, declared above.
// {Sig2Sig,Sig2Unsig,Unsig2Sig,Unsig2Unsig} are aribtrary types. (not metafunctions)
//
// According to the value of 'SignMixture', selects the corresponding type.
//
template<class SignMixture, class Sig2Sig, class Sig2Unsig, class Unsig2Sig, class Unsig2Unsig>
struct for_sign_mixture
{
typedef typename
ct_switch4<SignMixture
, sig2sig_c, sig2unsig_c, unsig2sig_c // default
, Sig2Sig , Sig2Unsig , Unsig2Sig , Unsig2Unsig
>::type
type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,69 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_UDT_BUILTIN_MIXTURE_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_DETAIL_UDT_BUILTIN_MIXTURE_FLC_12NOV2002_HPP
#include "boost/type_traits/is_arithmetic.hpp"
#include "boost/numeric/conversion/udt_builtin_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'UdtMixture'
typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_udt> udt2udt_c ;
// Metafunction:
//
// for_udt_mixture<UdtMixture,BuiltIn2BuiltIn,BuiltIn2Udt,Udt2BuiltIn,Udt2Udt>::type
//
// {UdtMixture} is one of the Integral Constants for UdMixture, declared above.
// {BuiltIn2BuiltIn,BuiltIn2Udt,Udt2BuiltIn,Udt2Udt} are aribtrary types. (not metafunctions)
//
// According to the value of 'UdtMixture', selects the corresponding type.
//
template<class UdtMixture, class BuiltIn2BuiltIn, class BuiltIn2Udt, class Udt2BuiltIn, class Udt2Udt>
struct for_udt_builtin_mixture
{
typedef typename
ct_switch4<UdtMixture
, builtin2builtin_c, builtin2udt_c, udt2builtin_c // default
, BuiltIn2BuiltIn , BuiltIn2Udt , Udt2BuiltIn , Udt2Udt
>::type
type ;
} ;
// Metafunction:
//
// get_udt_mixture<T,S>::type
//
// Selects the appropriate UdtMixture Integral Constant for the combination T,S.
//
template<class T,class S>
struct get_udt_builtin_mixture
{
typedef is_arithmetic<S> S_builtin ;
typedef is_arithmetic<T> T_builtin ;
typedef typename
for_both<S_builtin, T_builtin, builtin2builtin_c, builtin2udt_c, udt2builtin_c, udt2udt_c>::type
type ;
} ;
} } } // namespace boost::numeric::convdetail
#endif

View File

@@ -0,0 +1,30 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_INT_FLOAT_MIXTURE_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_INT_FLOAT_MIXTURE_FLC_12NOV2002_HPP
#include "boost/numeric/conversion/detail/int_float_mixture.hpp"
namespace boost { namespace numeric
{
template<class T, class S>
struct int_float_mixture
: convdetail::get_int_float_mixture< BOOST_DEDUCED_TYPENAME remove_cv<T>::type
,BOOST_DEDUCED_TYPENAME remove_cv<S>::type
>::type {} ;
} } // namespace boost::numeric
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,29 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_INT_FLOAT_MIXTURE_ENUM_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_INT_FLOAT_MIXTURE_ENUM_FLC_12NOV2002_HPP
namespace boost { namespace numeric
{
enum int_float_mixture_enum
{
integral_to_integral
,integral_to_float
,float_to_integral
,float_to_float
} ;
} } // namespace boost::numeric
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,27 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_IS_SUBRANGED_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_IS_SUBRANGED_FLC_12NOV2002_HPP
#include "boost/numeric/conversion/detail/is_subranged.hpp"
namespace boost { namespace numeric {
template<class T, class S>
struct is_subranged
: convdetail::get_is_subranged< BOOST_DEDUCED_TYPENAME remove_cv<T>::type
,BOOST_DEDUCED_TYPENAME remove_cv<S>::type
>::type {} ;
} } // namespace boost::numeric
#endif

View File

@@ -0,0 +1,31 @@
//
//! Copyright (c) 2011
//! Brandon Kohn
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_NUMERIC_CAST_TRAITS_HPP
#define BOOST_NUMERIC_CAST_TRAITS_HPP
#include <boost/numeric/conversion/converter_policies.hpp>
namespace boost { namespace numeric {
template <typename Target, typename Source, typename EnableIf = void>
struct numeric_cast_traits
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<Source> rounding_policy;
};
}}//namespace boost::numeric;
#if !defined( BOOST_NUMERIC_CONVERSION_RELAX_BUILT_IN_CAST_TRAITS )
#include <boost/cstdint.hpp>
#include <boost/numeric/conversion/detail/numeric_cast_traits.hpp>
#endif//!defined BOOST_NUMERIC_CONVERSION_RELAX_BUILT_IN_CAST_TRAITS
#endif//BOOST_NUMERIC_CAST_TRAITS_HPP

View File

@@ -0,0 +1,30 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_SIGN_MIXTURE_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_SIGN_MIXTURE_FLC_12NOV2002_HPP
#include "boost/numeric/conversion/detail/sign_mixture.hpp"
namespace boost { namespace numeric
{
template<class T, class S>
struct sign_mixture
: convdetail::get_sign_mixture< BOOST_DEDUCED_TYPENAME remove_cv<T>::type
,BOOST_DEDUCED_TYPENAME remove_cv<S>::type
>::type {} ;
} } // namespace boost::numeric
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,29 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_SIGN_MIXTURE_ENUM_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_SIGN_MIXTURE_ENUM_FLC_12NOV2002_HPP
namespace boost { namespace numeric
{
enum sign_mixture_enum
{
unsigned_to_unsigned
,signed_to_signed
,signed_to_unsigned
,unsigned_to_signed
} ;
} } // namespace boost::numeric
#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,28 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_UDT_BUILTIN_MIXTURE_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_UDT_BUILTIN_MIXTURE_FLC_12NOV2002_HPP
#include "boost/numeric/conversion/detail/udt_builtin_mixture.hpp"
namespace boost { namespace numeric
{
template<class T, class S>
struct udt_builtin_mixture
: convdetail::get_udt_builtin_mixture< BOOST_DEDUCED_TYPENAME remove_cv<T>::type
,BOOST_DEDUCED_TYPENAME remove_cv<S>::type
>::type {} ;
} } // namespace boost::numeric
#endif

View File

@@ -0,0 +1,26 @@
// (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
// Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
//
#ifndef BOOST_NUMERIC_CONVERSION_UDT_BUILTIN_MIXTURE_ENUM_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_UDT_BUILTIN_MIXTURE_ENUM_FLC_12NOV2002_HPP
namespace boost { namespace numeric
{
enum udt_builtin_mixture_enum
{
builtin_to_builtin
,builtin_to_udt
,udt_to_builtin
,udt_to_udt
} ;
} } // namespace boost::numeric
#endif

View File

@@ -0,0 +1,32 @@
/* Boost interval.hpp header file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_HPP
#define BOOST_NUMERIC_INTERVAL_HPP
#include <boost/limits.hpp>
#include <boost/numeric/interval/interval.hpp>
#include <boost/numeric/interval/policies.hpp>
#include <boost/numeric/interval/hw_rounding.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>
#include <boost/numeric/interval/rounded_transc.hpp>
#include <boost/numeric/interval/constants.hpp>
#include <boost/numeric/interval/checking.hpp>
#include <boost/numeric/interval/compare.hpp>
#include <boost/numeric/interval/utility.hpp>
#include <boost/numeric/interval/arith.hpp>
#include <boost/numeric/interval/arith2.hpp>
#include <boost/numeric/interval/arith3.hpp>
#include <boost/numeric/interval/transc.hpp>
#endif // BOOST_NUMERIC_INTERVAL_HPP

View File

@@ -0,0 +1,305 @@
/* Boost interval/arith.hpp template implementation file
*
* Copyright 2000 Jens Maurer
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_ARITH_HPP
#define BOOST_NUMERIC_INTERVAL_ARITH_HPP
#include <boost/config.hpp>
#include <boost/numeric/interval/interval.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/detail/division.hpp>
#include <algorithm>
namespace boost {
namespace numeric {
/*
* Basic arithmetic operators
*/
template<class T, class Policies> inline
const interval<T, Policies>& operator+(const interval<T, Policies>& x)
{
return x;
}
template<class T, class Policies> inline
interval<T, Policies> operator-(const interval<T, Policies>& x)
{
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
return interval<T, Policies>(-x.upper(), -x.lower(), true);
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator+=(const interval<T, Policies>& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.add_down(low, r.low), rnd.add_up(up, r.up));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator+=(const T& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.add_down(low, r), rnd.add_up(up, r));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator-=(const interval<T, Policies>& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.sub_down(low, r.up), rnd.sub_up(up, r.low));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator-=(const T& r)
{
if (interval_lib::detail::test_input(*this, r))
set_empty();
else {
typename Policies::rounding rnd;
set(rnd.sub_down(low, r), rnd.sub_up(up, r));
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator*=(const interval<T, Policies>& r)
{
return *this = *this * r;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator*=(const T& r)
{
return *this = r * *this;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator/=(const interval<T, Policies>& r)
{
return *this = *this / r;
}
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator/=(const T& r)
{
return *this = *this / r;
}
template<class T, class Policies> inline
interval<T, Policies> operator+(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.add_down(x.lower(), y.lower()),
rnd.add_up (x.upper(), y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator+(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.add_down(x, y.lower()),
rnd.add_up (x, y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator+(const interval<T, Policies>& x, const T& y)
{ return y + x; }
template<class T, class Policies> inline
interval<T, Policies> operator-(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.sub_down(x.lower(), y.upper()),
rnd.sub_up (x.upper(), y.lower()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator-(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.sub_down(x, y.upper()),
rnd.sub_up (x, y.lower()), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator-(const interval<T, Policies>& x, const T& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T,Policies>(rnd.sub_down(x.lower(), y),
rnd.sub_up (x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator*(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
typename Policies::rounding rnd;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
if (interval_lib::user::is_neg(xl))
if (interval_lib::user::is_pos(xu))
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // M * M
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_down(xl, yu), rnd.mul_down(xu, yl)),
max BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_up (xl, yl), rnd.mul_up (xu, yu)), true);
else // M * N
return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yl), true);
else
if (interval_lib::user::is_pos(yu)) // M * P
return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yu), true);
else // M * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // N * M
return I(rnd.mul_down(xl, yu), rnd.mul_up(xl, yl), true);
else // N * N
return I(rnd.mul_down(xu, yu), rnd.mul_up(xl, yl), true);
else
if (interval_lib::user::is_pos(yu)) // N * P
return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yl), true);
else // N * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else
if (interval_lib::user::is_pos(xu))
if (interval_lib::user::is_neg(yl))
if (interval_lib::user::is_pos(yu)) // P * M
return I(rnd.mul_down(xu, yl), rnd.mul_up(xu, yu), true);
else // P * N
return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yu), true);
else
if (interval_lib::user::is_pos(yu)) // P * P
return I(rnd.mul_down(xl, yl), rnd.mul_up(xu, yu), true);
else // P * Z
return I(static_cast<T>(0), static_cast<T>(0), true);
else // Z * ?
return I(static_cast<T>(0), static_cast<T>(0), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator*(const T& x, const interval<T, Policies>& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
typename Policies::rounding rnd;
const T& yl = y.lower();
const T& yu = y.upper();
// x is supposed not to be infinite
if (interval_lib::user::is_neg(x))
return I(rnd.mul_down(x, yu), rnd.mul_up(x, yl), true);
else if (interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
else
return I(rnd.mul_down(x, yl), rnd.mul_up(x, yu), true);
}
template<class T, class Policies> inline
interval<T, Policies> operator*(const interval<T, Policies>& x, const T& y)
{ return y * x; }
template<class T, class Policies> inline
interval<T, Policies> operator/(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
if (zero_in(y))
if (!interval_lib::user::is_zero(y.lower()))
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_zero(x);
else
return interval_lib::detail::div_negative(x, y.lower());
else
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_positive(x, y.upper());
else
return interval<T, Policies>::empty();
else
return interval_lib::detail::div_non_zero(x, y);
}
template<class T, class Policies> inline
interval<T, Policies> operator/(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
if (zero_in(y))
if (!interval_lib::user::is_zero(y.lower()))
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_zero<T, Policies>(x);
else
return interval_lib::detail::div_negative<T, Policies>(x, y.lower());
else
if (!interval_lib::user::is_zero(y.upper()))
return interval_lib::detail::div_positive<T, Policies>(x, y.upper());
else
return interval<T, Policies>::empty();
else
return interval_lib::detail::div_non_zero(x, y);
}
template<class T, class Policies> inline
interval<T, Policies> operator/(const interval<T, Policies>& x, const T& y)
{
if (interval_lib::detail::test_input(x, y) || interval_lib::user::is_zero(y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
const T& xl = x.lower();
const T& xu = x.upper();
if (interval_lib::user::is_neg(y))
return interval<T, Policies>(rnd.div_down(xu, y), rnd.div_up(xl, y), true);
else
return interval<T, Policies>(rnd.div_down(xl, y), rnd.div_up(xu, y), true);
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_ARITH_HPP

View File

@@ -0,0 +1,305 @@
/* Boost interval/arith2.hpp template implementation file
*
* This header provides some auxiliary arithmetic
* functions: fmod, sqrt, square, pov, inverse and
* a multi-interval division.
*
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_ARITH2_HPP
#define BOOST_NUMERIC_INTERVAL_ARITH2_HPP
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/division.hpp>
#include <boost/numeric/interval/arith.hpp>
#include <boost/numeric/interval/policies.hpp>
#include <algorithm>
#include <cassert>
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
template<class T, class Policies> inline
interval<T, Policies> fmod(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies> >::type I;
T const &yb = interval_lib::user::is_neg(x.lower()) ? y.lower() : y.upper();
T n = rnd.int_down(rnd.div_down(x.lower(), yb));
return (const I&)x - n * (const I&)y;
}
template<class T, class Policies> inline
interval<T, Policies> fmod(const interval<T, Policies>& x, const T& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies> >::type I;
T n = rnd.int_down(rnd.div_down(x.lower(), y));
return (const I&)x - n * I(y);
}
template<class T, class Policies> inline
interval<T, Policies> fmod(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<interval<T, Policies> >::type I;
T const &yb = interval_lib::user::is_neg(x) ? y.lower() : y.upper();
T n = rnd.int_down(rnd.div_down(x, yb));
return x - n * (const I&)y;
}
namespace interval_lib {
template<class T, class Policies> inline
interval<T, Policies> division_part1(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool& b)
{
typedef interval<T, Policies> I;
b = false;
if (detail::test_input(x, y))
return I::empty();
if (zero_in(y))
if (!user::is_zero(y.lower()))
if (!user::is_zero(y.upper()))
return detail::div_zero_part1(x, y, b);
else
return detail::div_negative(x, y.lower());
else
if (!user::is_zero(y.upper()))
return detail::div_positive(x, y.upper());
else
return I::empty();
else
return detail::div_non_zero(x, y);
}
template<class T, class Policies> inline
interval<T, Policies> division_part2(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool b = true)
{
if (!b) return interval<T, Policies>::empty();
return detail::div_zero_part2(x, y);
}
template<class T, class Policies> inline
interval<T, Policies> multiplicative_inverse(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (detail::test_input(x))
return I::empty();
T one = static_cast<T>(1);
typename Policies::rounding rnd;
if (zero_in(x)) {
typedef typename Policies::checking checking;
if (!user::is_zero(x.lower()))
if (!user::is_zero(x.upper()))
return I::whole();
else
return I(checking::neg_inf(), rnd.div_up(one, x.lower()), true);
else
if (!user::is_zero(x.upper()))
return I(rnd.div_down(one, x.upper()), checking::pos_inf(), true);
else
return I::empty();
} else
return I(rnd.div_down(one, x.upper()), rnd.div_up(one, x.lower()), true);
}
namespace detail {
template<class T, class Rounding> inline
T pow_dn(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive
{
T x = x_;
T y = (pwr & 1) ? x_ : static_cast<T>(1);
pwr >>= 1;
while (pwr > 0) {
x = rnd.mul_down(x, x);
if (pwr & 1) y = rnd.mul_down(x, y);
pwr >>= 1;
}
return y;
}
template<class T, class Rounding> inline
T pow_up(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive
{
T x = x_;
T y = (pwr & 1) ? x_ : static_cast<T>(1);
pwr >>= 1;
while (pwr > 0) {
x = rnd.mul_up(x, x);
if (pwr & 1) y = rnd.mul_up(x, y);
pwr >>= 1;
}
return y;
}
} // namespace detail
} // namespace interval_lib
template<class T, class Policies> inline
interval<T, Policies> pow(const interval<T, Policies>& x, int pwr)
{
BOOST_USING_STD_MAX();
using interval_lib::detail::pow_dn;
using interval_lib::detail::pow_up;
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
if (pwr == 0)
if (interval_lib::user::is_zero(x.lower())
&& interval_lib::user::is_zero(x.upper()))
return I::empty();
else
return I(static_cast<T>(1));
else if (pwr < 0)
return interval_lib::multiplicative_inverse(pow(x, -pwr));
typename Policies::rounding rnd;
if (interval_lib::user::is_neg(x.upper())) { // [-2,-1]
T yl = pow_dn(static_cast<T>(-x.upper()), pwr, rnd);
T yu = pow_up(static_cast<T>(-x.lower()), pwr, rnd);
if (pwr & 1) // [-2,-1]^1
return I(-yu, -yl, true);
else // [-2,-1]^2
return I(yl, yu, true);
} else if (interval_lib::user::is_neg(x.lower())) { // [-1,1]
if (pwr & 1) { // [-1,1]^1
return I(-pow_up(static_cast<T>(-x.lower()), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
} else { // [-1,1]^2
return I(static_cast<T>(0), pow_up(max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), pwr, rnd), true);
}
} else { // [1,2]
return I(pow_dn(x.lower(), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
}
}
template<class T, class Policies> inline
interval<T, Policies> sqrt(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || interval_lib::user::is_neg(x.upper()))
return I::empty();
typename Policies::rounding rnd;
T l = !interval_lib::user::is_pos(x.lower()) ? static_cast<T>(0) : rnd.sqrt_down(x.lower());
return I(l, rnd.sqrt_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> square(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
const T& xl = x.lower();
const T& xu = x.upper();
if (interval_lib::user::is_neg(xu))
return I(rnd.mul_down(xu, xu), rnd.mul_up(xl, xl), true);
else if (interval_lib::user::is_pos(x.lower()))
return I(rnd.mul_down(xl, xl), rnd.mul_up(xu, xu), true);
else
return I(static_cast<T>(0), (-xl > xu ? rnd.mul_up(xl, xl) : rnd.mul_up(xu, xu)), true);
}
namespace interval_lib {
namespace detail {
template< class I > inline
I root_aux(typename I::base_type const &x, int k) // x and k are bigger than one
{
typedef typename I::base_type T;
T tk(k);
I y(static_cast<T>(1), x, true);
for(;;) {
T y0 = median(y);
I yy = intersect(y, y0 - (pow(I(y0, y0, true), k) - x) / (tk * pow(y, k - 1)));
if (equal(y, yy)) return y;
y = yy;
}
}
template< class I > inline // x is positive and k bigger than one
typename I::base_type root_aux_dn(typename I::base_type const &x, int k)
{
typedef typename I::base_type T;
typedef typename I::traits_type Policies;
typename Policies::rounding rnd;
T one(1);
if (x > one) return root_aux<I>(x, k).lower();
if (x == one) return one;
return rnd.div_down(one, root_aux<I>(rnd.div_up(one, x), k).upper());
}
template< class I > inline // x is positive and k bigger than one
typename I::base_type root_aux_up(typename I::base_type const &x, int k)
{
typedef typename I::base_type T;
typedef typename I::traits_type Policies;
typename Policies::rounding rnd;
T one(1);
if (x > one) return root_aux<I>(x, k).upper();
if (x == one) return one;
return rnd.div_up(one, root_aux<I>(rnd.div_down(one, x), k).lower());
}
} // namespace detail
} // namespace interval_lib
template< class T, class Policies > inline
interval<T, Policies> nth_root(interval<T, Policies> const &x, int k)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)) return I::empty();
assert(k > 0);
if (k == 1) return x;
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
if (!interval_lib::user::is_pos(x.upper())) {
if (interval_lib::user::is_zero(x.upper())) {
T zero(0);
if (!(k & 1) || interval_lib::user::is_zero(x.lower())) // [-1,0]^/2 or [0,0]
return I(zero, zero, true);
else // [-1,0]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k), zero, true);
} else if (!(k & 1)) // [-2,-1]^/2
return I::empty();
else { // [-2,-1]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k),
-interval_lib::detail::root_aux_dn<R>(-x.upper(), k), true);
}
}
T u = interval_lib::detail::root_aux_up<R>(x.upper(), k);
if (!interval_lib::user::is_pos(x.lower()))
if (!(k & 1) || interval_lib::user::is_zero(x.lower())) // [-1,1]^/2 or [0,1]
return I(static_cast<T>(0), u, true);
else // [-1,1]^/3
return I(-interval_lib::detail::root_aux_up<R>(-x.lower(), k), u, true);
else // [1,2]
return I(interval_lib::detail::root_aux_dn<R>(x.lower(), k), u, true);
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_ARITH2_HPP

View File

@@ -0,0 +1,69 @@
/* Boost interval/arith3.hpp template implementation file
*
* This headers provides arithmetical functions
* which compute an interval given some base
* numbers. The resulting interval encloses the
* real result of the arithmetic operation.
*
* Copyright 2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_ARITH3_HPP
#define BOOST_NUMERIC_INTERVAL_ARITH3_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
template<class I> inline
I add(const typename I::base_type& x, const typename I::base_type& y)
{
typedef typename I::traits_type Policies;
if (detail::test_input<typename I::base_type, Policies>(x, y))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.add_down(x, y), rnd.add_up(x, y), true);
}
template<class I> inline
I sub(const typename I::base_type& x, const typename I::base_type& y)
{
typedef typename I::traits_type Policies;
if (detail::test_input<typename I::base_type, Policies>(x, y))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.sub_down(x, y), rnd.sub_up(x, y), true);
}
template<class I> inline
I mul(const typename I::base_type& x, const typename I::base_type& y)
{
typedef typename I::traits_type Policies;
if (detail::test_input<typename I::base_type, Policies>(x, y))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.mul_down(x, y), rnd.mul_up(x, y), true);
}
template<class I> inline
I div(const typename I::base_type& x, const typename I::base_type& y)
{
typedef typename I::traits_type Policies;
if (detail::test_input<typename I::base_type, Policies>(x, y) || user::is_zero(y))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.div_down(x, y), rnd.div_up(x, y), true);
}
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_ARITH3_HPP

View File

@@ -0,0 +1,130 @@
/* Boost interval/checking.hpp template implementation file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_CHECKING_HPP
#define BOOST_NUMERIC_INTERVAL_CHECKING_HPP
#include <stdexcept>
#include <string>
#include <cassert>
#include <boost/limits.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
struct exception_create_empty
{
void operator()()
{
throw std::runtime_error("boost::interval: empty interval created");
}
};
struct exception_invalid_number
{
void operator()()
{
throw std::invalid_argument("boost::interval: invalid number");
}
};
template<class T>
struct checking_base
{
static T pos_inf()
{
assert(std::numeric_limits<T>::has_infinity);
return std::numeric_limits<T>::infinity();
}
static T neg_inf()
{
assert(std::numeric_limits<T>::has_infinity);
return -std::numeric_limits<T>::infinity();
}
static T nan()
{
assert(std::numeric_limits<T>::has_quiet_NaN);
return std::numeric_limits<T>::quiet_NaN();
}
static bool is_nan(const T& x)
{
return std::numeric_limits<T>::has_quiet_NaN && (x != x);
}
static T empty_lower()
{
return (std::numeric_limits<T>::has_quiet_NaN ?
std::numeric_limits<T>::quiet_NaN() : static_cast<T>(1));
}
static T empty_upper()
{
return (std::numeric_limits<T>::has_quiet_NaN ?
std::numeric_limits<T>::quiet_NaN() : static_cast<T>(0));
}
static bool is_empty(const T& l, const T& u)
{
return !(l <= u); // safety for partial orders
}
};
template<class T, class Checking = checking_base<T>,
class Exception = exception_create_empty>
struct checking_no_empty: Checking
{
static T nan()
{
assert(false);
return Checking::nan();
}
static T empty_lower()
{
Exception()();
return Checking::empty_lower();
}
static T empty_upper()
{
Exception()();
return Checking::empty_upper();
}
static bool is_empty(const T&, const T&)
{
return false;
}
};
template<class T, class Checking = checking_base<T> >
struct checking_no_nan: Checking
{
static bool is_nan(const T&)
{
return false;
}
};
template<class T, class Checking = checking_base<T>,
class Exception = exception_invalid_number>
struct checking_catch_nan: Checking
{
static bool is_nan(const T& x)
{
if (Checking::is_nan(x)) Exception()();
return false;
}
};
template<class T>
struct checking_strict:
checking_no_nan<T, checking_no_empty<T> >
{};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_CHECKING_HPP

View File

@@ -0,0 +1,19 @@
/* Boost interval/compare.hpp template implementation file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_HPP
#include <boost/numeric/interval/compare/certain.hpp>
#include <boost/numeric/interval/compare/possible.hpp>
#include <boost/numeric/interval/compare/explicit.hpp>
#include <boost/numeric/interval/compare/lexicographic.hpp>
#include <boost/numeric/interval/compare/set.hpp>
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_HPP

View File

@@ -0,0 +1,113 @@
/* Boost interval/compare/certain.hpp template implementation file
*
* Copyright 2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_CERTAIN_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_CERTAIN_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace compare {
namespace certain {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y.lower();
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y;
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() <= y.lower();
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() <= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() > y.upper();
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() > y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() >= y.upper();
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() == y.lower() && x.lower() == y.upper();
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() == y && x.lower() == y;
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y.lower() || x.lower() > y.upper();
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() < y || x.lower() > y;
}
} // namespace certain
} // namespace compare
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_CERTAIN_HPP

View File

@@ -0,0 +1,248 @@
/* Boost interval/compare/explicit.hpp template implementation file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
/*
* Certainly... operations
*/
template<class T, class Policies1, class Policies2> inline
bool cerlt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() < y.lower();
}
template<class T, class Policies> inline
bool cerlt(const interval<T, Policies>& x, const T& y)
{
return x.upper() < y;
}
template<class T, class Policies> inline
bool cerlt(const T& x, const interval<T, Policies>& y)
{
return x < y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool cerle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() <= y.lower();
}
template<class T, class Policies> inline
bool cerle(const interval<T, Policies>& x, const T& y)
{
return x.upper() <= y;
}
template<class T, class Policies> inline
bool cerle(const T& x, const interval<T, Policies>& y)
{
return x <= y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool cergt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.lower() > y.upper();
}
template<class T, class Policies> inline
bool cergt(const interval<T, Policies>& x, const T& y)
{
return x.lower() > y;
}
template<class T, class Policies> inline
bool cergt(const T& x, const interval<T, Policies>& y)
{
return x > y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool cerge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.lower() >= y.upper();
}
template<class T, class Policies> inline
bool cerge(const interval<T, Policies>& x, const T& y)
{
return x.lower() >= y;
}
template<class T, class Policies> inline
bool cerge(const T& x, const interval<T, Policies>& y)
{
return x >= y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool cereq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.lower() == y.upper() && y.lower() == x.upper();
}
template<class T, class Policies> inline
bool cereq(const interval<T, Policies>& x, const T& y)
{
return x.lower() == y && x.upper() == y;
}
template<class T, class Policies> inline
bool cereq(const T& x, const interval<T, Policies>& y)
{
return x == y.lower() && x == y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool cerne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() < y.lower() || y.upper() < x.lower();
}
template<class T, class Policies> inline
bool cerne(const interval<T, Policies>& x, const T& y)
{
return x.upper() < y || y < x.lower();
}
template<class T, class Policies> inline
bool cerne(const T& x, const interval<T, Policies>& y)
{
return x < y.lower() || y.upper() < x;
}
/*
* Possibly... comparisons
*/
template<class T, class Policies1, class Policies2> inline
bool poslt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.lower() < y.upper();
}
template<class T, class Policies> inline
bool poslt(const interval<T, Policies>& x, const T& y)
{
return x.lower() < y;
}
template<class T, class Policies> inline
bool poslt(const T& x, const interval<T, Policies>& y)
{
return x < y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool posle(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.lower() <= y.upper();
}
template<class T, class Policies> inline
bool posle(const interval<T, Policies>& x, const T& y)
{
return x.lower() <= y;
}
template<class T, class Policies> inline
bool posle(const T& x, const interval<T, Policies>& y)
{
return x <= y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool posgt(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() > y.lower();
}
template<class T, class Policies> inline
bool posgt(const interval<T, Policies>& x, const T& y)
{
return x.upper() > y;
}
template<class T, class Policies> inline
bool posgt(const T& x, const interval<T, Policies> & y)
{
return x > y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool posge(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() >= y.lower();
}
template<class T, class Policies> inline
bool posge(const interval<T, Policies>& x, const T& y)
{
return x.upper() >= y;
}
template<class T, class Policies> inline
bool posge(const T& x, const interval<T, Policies>& y)
{
return x >= y.lower();
}
template<class T, class Policies1, class Policies2> inline
bool poseq(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() >= y.lower() && y.upper() >= x.lower();
}
template<class T, class Policies> inline
bool poseq(const interval<T, Policies>& x, const T& y)
{
return x.upper() >= y && y >= x.lower();
}
template<class T, class Policies> inline
bool poseq(const T& x, const interval<T, Policies>& y)
{
return x >= y.lower() && y.upper() >= x;
}
template<class T, class Policies1, class Policies2> inline
bool posne(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return x.upper() != y.lower() || y.upper() != x.lower();
}
template<class T, class Policies> inline
bool posne(const interval<T, Policies>& x, const T& y)
{
return x.upper() != y || y != x.lower();
}
template<class T, class Policies> inline
bool posne(const T& x, const interval<T, Policies>& y)
{
return x != y.lower() || y.upper() != x;
}
} // namespace interval_lib
} // namespace numeric
} //namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP

View File

@@ -0,0 +1,122 @@
/* Boost interval/compare/lexicographic.hpp template implementation file
*
* Copyright 2002-2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace compare {
namespace lexicographic {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl < yl || (xl == yl && x.upper() < y.upper());
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() < y;
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl < yl || (xl == yl && x.upper() <= y.upper());
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
return xl < y || (xl == y && x.upper() <= y);
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl > yl || (xl == yl && x.upper() > y.upper());
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
return xl > y || (xl == y && x.upper() > y);
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
const T& xl = x.lower();
const T& yl = y.lower();
return xl > yl || (xl == yl && x.upper() >= y.upper());
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() == y.lower() && x.upper() == y.upper();
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() == y && x.upper() == y;
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y.lower() || x.upper() != y.upper();
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y || x.upper() != y;
}
} // namespace lexicographic
} // namespace compare
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP

View File

@@ -0,0 +1,113 @@
/* Boost interval/compare/possible.hpp template implementation file
*
* Copyright 2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_POSSIBLE_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_POSSIBLE_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace compare {
namespace possible {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() < y.upper();
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() < y;
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y.upper();
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() > y.lower();
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() > y;
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() >= y.lower();
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.upper() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y.upper() && x.upper() >= y.lower();
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() <= y && x.upper() >= y;
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y.upper() || x.upper() != y.lower();
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
return x.lower() != y || x.upper() != y;
}
} // namespace possible
} // namespace compare
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_POSSIBLE_HPP

View File

@@ -0,0 +1,101 @@
/* Boost interval/compare/set.hpp template implementation file
*
* Copyright 2002-2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/utility.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace compare {
namespace set {
template<class T, class Policies1, class Policies2> inline
bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return proper_subset(x, y);
}
template<class T, class Policies> inline
bool operator<(const interval<T, Policies>& x, const T& y)
{
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return subset(x, y);
}
template<class T, class Policies> inline
bool operator<=(const interval<T, Policies>& x, const T& y)
{
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return proper_subset(y, x);
}
template<class T, class Policies> inline
bool operator>(const interval<T, Policies>& x, const T& y)
{
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return subset(y, x);
}
template<class T, class Policies> inline
bool operator>=(const interval<T, Policies>& x, const T& y)
{
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return equal(y, x);
}
template<class T, class Policies> inline
bool operator==(const interval<T, Policies>& x, const T& y)
{
throw comparison_error();
}
template<class T, class Policies1, class Policies2> inline
bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
return !equal(y, x);
}
template<class T, class Policies> inline
bool operator!=(const interval<T, Policies>& x, const T& y)
{
throw comparison_error();
}
} // namespace set
} // namespace compare
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP

View File

@@ -0,0 +1,138 @@
/* Boost interval/compare/tribool.hpp template implementation file
*
* Copyright 2002-2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
#define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/logic/tribool.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace compare {
namespace tribool {
template<class T, class Policies1, class Policies2> inline
logic::tribool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y.lower()) return true;
if (x.lower() >= y.upper()) return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator<(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y) return true;
if (x.lower() >= y) return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() <= y.lower()) return true;
if (x.lower() > y.upper()) return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator<=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() <= y) return true;
if (x.lower() > y) return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() > y.upper()) return true;
if (x.upper() <= y.lower()) return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator>(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() > y) return true;
if (x.upper() <= y) return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() >= y.upper()) return true;
if (x.upper() < y.lower()) return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator>=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.lower() >= y) return true;
if (x.upper() < y) return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() == y.lower() && x.lower() == y.upper()) return true;
if (x.upper() < y.lower() || x.lower() > y.upper()) return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator==(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() == y && x.lower() == y) return true;
if (x.upper() < y || x.lower() > y) return false;
return logic::indeterminate;
}
template<class T, class Policies1, class Policies2> inline
logic::tribool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y.lower() || x.lower() > y.upper()) return true;
if (x.upper() == y.lower() && x.lower() == y.upper()) return false;
return logic::indeterminate;
}
template<class T, class Policies> inline
logic::tribool operator!=(const interval<T, Policies>& x, const T& y)
{
if (detail::test_input(x, y)) throw comparison_error();
if (x.upper() < y || x.lower() > y) return true;
if (x.upper() == y && x.lower() == y) return false;
return logic::indeterminate;
}
} // namespace tribool
} // namespace compare
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP

View File

@@ -0,0 +1,85 @@
/* Boost interval/constants.hpp template implementation file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP
#define BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP
namespace boost {
namespace numeric {
namespace interval_lib {
namespace constants {
// These constants should be exactly computed.
// Decimal representations wouldn't do it since the standard doesn't
// specify the rounding (even nearest) that should be used.
static const float pi_f_l = 13176794.0f/(1<<22);
static const float pi_f_u = 13176795.0f/(1<<22);
static const double pi_d_l = (3373259426.0 + 273688.0 / (1<<21)) / (1<<30);
static const double pi_d_u = (3373259426.0 + 273689.0 / (1<<21)) / (1<<30);
template<class T> inline T pi_lower() { return 3; }
template<class T> inline T pi_upper() { return 4; }
template<class T> inline T pi_half_lower() { return 1; }
template<class T> inline T pi_half_upper() { return 2; }
template<class T> inline T pi_twice_lower() { return 6; }
template<class T> inline T pi_twice_upper() { return 7; }
template<> inline float pi_lower<float>() { return pi_f_l; }
template<> inline float pi_upper<float>() { return pi_f_u; }
template<> inline float pi_half_lower<float>() { return pi_f_l / 2; }
template<> inline float pi_half_upper<float>() { return pi_f_u / 2; }
template<> inline float pi_twice_lower<float>() { return pi_f_l * 2; }
template<> inline float pi_twice_upper<float>() { return pi_f_u * 2; }
template<> inline double pi_lower<double>() { return pi_d_l; }
template<> inline double pi_upper<double>() { return pi_d_u; }
template<> inline double pi_half_lower<double>() { return pi_d_l / 2; }
template<> inline double pi_half_upper<double>() { return pi_d_u / 2; }
template<> inline double pi_twice_lower<double>() { return pi_d_l * 2; }
template<> inline double pi_twice_upper<double>() { return pi_d_u * 2; }
template<> inline long double pi_lower<long double>() { return pi_d_l; }
template<> inline long double pi_upper<long double>() { return pi_d_u; }
template<> inline long double pi_half_lower<long double>() { return pi_d_l / 2; }
template<> inline long double pi_half_upper<long double>() { return pi_d_u / 2; }
template<> inline long double pi_twice_lower<long double>() { return pi_d_l * 2; }
template<> inline long double pi_twice_upper<long double>() { return pi_d_u * 2; }
} // namespace constants
template<class I> inline
I pi()
{
typedef typename I::base_type T;
return I(constants::pi_lower<T>(),
constants::pi_upper<T>(), true);
}
template<class I> inline
I pi_half()
{
typedef typename I::base_type T;
return I(constants::pi_half_lower<T>(),
constants::pi_half_upper<T>(), true);
}
template<class I> inline
I pi_twice()
{
typedef typename I::base_type T;
return I(constants::pi_twice_lower<T>(),
constants::pi_twice_upper<T>(), true);
}
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP

View File

@@ -0,0 +1,113 @@
/* Boost interval/detail/alpha_rounding_control.hpp file
*
* Copyright 2005 Felix H<>fling, Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_ALPHA_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_ALPHA_ROUNDING_CONTROL_HPP
#if !defined(alpha) && !defined(__alpha__)
#error This header only works on Alpha CPUs.
#endif
#if defined(__GNUC__) || defined(__digital__) || defined(__DECCXX)
#include <float.h> // write_rnd() and read_rnd()
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#if defined(__GNUC__ )
typedef union {
::boost::long_long_type imode;
double dmode;
} rounding_mode_struct;
// set bits 59-58 (DYN),
// clear all exception bits and disable overflow (51) and inexact exceptions (62)
static const rounding_mode_struct mode_upward = { 0x4C08000000000000LL };
static const rounding_mode_struct mode_downward = { 0x4408000000000000LL };
static const rounding_mode_struct mode_to_nearest = { 0x4808000000000000LL };
static const rounding_mode_struct mode_toward_zero = { 0x4008000000000000LL };
struct alpha_rounding_control
{
typedef double rounding_mode;
static void set_rounding_mode(const rounding_mode mode)
{ __asm__ __volatile__ ("mt_fpcr %0" : : "f"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("mf_fpcr %0" : "=f"(mode)); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
};
#elif defined(__digital__) || defined(__DECCXX)
#if defined(__DECCXX) && !(defined(__FLT_ROUNDS) && __FLT_ROUNDS == -1)
#error Dynamic rounding mode not enabled. See cxx man page for details.
#endif
struct alpha_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode) { write_rnd(mode); }
static void get_rounding_mode(rounding_mode& mode) { mode = read_rnd(); }
static void downward() { set_rounding_mode(FP_RND_RM); }
static void upward() { set_rounding_mode(FP_RND_RP); }
static void to_nearest() { set_rounding_mode(FP_RND_RN); }
static void toward_zero() { set_rounding_mode(FP_RND_RZ); }
};
#endif
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
long double rintl(long double);
}
template<>
struct rounding_control<float>:
detail::alpha_rounding_control
{
static float force_rounding(const float r)
{ volatile float _r = r; return _r; }
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::alpha_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::alpha_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rintl(r); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_ALPHA_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,57 @@
/* Boost interval/detail/bcc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
#ifndef __BORLANDC__
# error This header is only intended for Borland C++.
#endif
#ifndef _M_IX86
# error This header only works on x86 CPUs.
#endif
#include <float.h> // Borland C++ rounding control
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#ifndef BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
extern "C" { unsigned int _RTLENTRY _fm_init(void); }
struct borland_workaround {
borland_workaround() { _fm_init(); }
};
static borland_workaround borland_workaround_exec;
#endif // BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
__inline double rint(double)
{ __emit__(0xD9); __emit__(0xFC); /* asm FRNDINT */ }
struct x86_rounding
{
typedef unsigned int rounding_mode;
static void get_rounding_mode(rounding_mode& mode)
{ mode = _control87(0, 0); }
static void set_rounding_mode(const rounding_mode mode)
{ _control87(mode, 0xffff); }
static double to_int(const double& x) { return rint(x); }
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,79 @@
/* Boost interval/detail/bugs.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BUGS
#define BOOST_NUMERIC_INTERVAL_DETAIL_BUGS
#include <boost/config.hpp>
#if defined(__GLIBC__) && (defined(__USE_MISC) || defined(__USE_XOPEN_EXTENDED) || defined(__USE_ISOC99)) && !defined(__ICC)
# define BOOST_HAS_INV_HYPERBOLIC
#endif
#ifdef BOOST_NO_STDC_NAMESPACE
# define BOOST_NUMERIC_INTERVAL_using_math(a) using ::a
# ifdef BOOST_HAS_INV_HYPERBOLIC
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
# endif
#else
# define BOOST_NUMERIC_INTERVAL_using_math(a) using std::a
# if defined(BOOST_HAS_INV_HYPERBOLIC)
# if defined(__GLIBCPP__) || defined(__GLIBCXX__)
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
# else
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using std::a
# endif
# endif
#endif
#if defined(__COMO__) || defined(BOOST_INTEL)
# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#elif defined(BOOST_NO_STDC_NAMESPACE)
# define BOOST_NUMERIC_INTERVAL_using_max(a) using ::a
#else
# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#endif
#ifndef BOOST_NUMERIC_INTERVAL_using_ahyp
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
#endif
#if defined(__GNUC__) && (__GNUC__ <= 2)
// cf PR c++/1981 for a description of the bug
#include <algorithm>
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
using std::min;
using std::max;
using std::sqrt;
using std::exp;
using std::log;
using std::cos;
using std::tan;
using std::asin;
using std::acos;
using std::atan;
using std::ceil;
using std::floor;
using std::sinh;
using std::cosh;
using std::tanh;
# undef BOOST_NUMERIC_INTERVAL_using_max
# undef BOOST_NUMERIC_INTERVAL_using_math
# define BOOST_NUMERIC_INTERVAL_using_max(a)
# define BOOST_NUMERIC_INTERVAL_using_math(a)
# undef BOOST_NUMERIC_INTERVAL_using_ahyp
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
} // namespace numeric
} // namespace boost
#endif
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_BUGS

View File

@@ -0,0 +1,50 @@
/* Boost interval/detail/c99_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP
#include <boost/numeric/interval/detail/c99sub_rounding_control.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
template<>
struct rounding_control<float>:
detail::c99_rounding_control
{
static float force_rounding(float const &r)
{ volatile float r_ = r; return r_; }
};
template<>
struct rounding_control<double>:
detail::c99_rounding_control
{
static double force_rounding(double const &r)
{ volatile double r_ = r; return r_; }
};
template<>
struct rounding_control<long double>:
detail::c99_rounding_control
{
static long double force_rounding(long double const &r)
{ volatile long double r_ = r; return r_; }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP

View File

@@ -0,0 +1,43 @@
/* Boost interval/detail/c99sub_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
#include <boost/detail/fenv.hpp> // ISO C 99 rounding mode control
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
extern "C" { double rint(double); }
struct c99_rounding_control
{
typedef int rounding_mode;
static void set_rounding_mode(rounding_mode mode) { fesetround(mode); }
static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
template<class T>
static T to_int(const T& r) { return rint(r); }
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP

View File

@@ -0,0 +1,194 @@
/* Boost interval/detail/division.hpp file
*
* Copyright 2003 Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>
#include <algorithm>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(xu))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yl), rnd.div_up(xl, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yl), true);
else
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true);
else
return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const T& x, const interval<T, Policies>& y)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& yl = y.lower();
const T& yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), rnd.div_up(x, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_positive(const interval<T, Policies>& x, const T& yu)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(checking::neg_inf(), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(rnd.div_down(xl, yu), checking::pos_inf(), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_positive(const T& x, const T& yu)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(checking::neg_inf(), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), checking::pos_inf(), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_negative(const interval<T, Policies>& x, const T& yl)
{
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(rnd.div_down(xu, yl), checking::pos_inf(), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(xl, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_negative(const T& x, const T& yl)
{
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(x, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_zero(const interval<T, Policies>& x)
{
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
else return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_zero(const T& x)
{
if (::boost::numeric::interval_lib::user::is_zero(x))
return interval<T, Policies>(static_cast<T>(0), static_cast<T>(0), true);
else return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_zero_part1(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool& b)
{
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && ::boost::numeric::interval_lib::user::is_zero(x.upper()))
{ b = false; return x; }
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
{ b = true; return I(checking::neg_inf(), rnd.div_up(xu, yu), true); }
else if (::boost::numeric::interval_lib::user::is_neg(xl))
{ b = false; return I(checking::neg_inf(), checking::pos_inf(), true); }
else
{ b = true; return I(checking::neg_inf(), rnd.div_up(xl, yl), true); }
}
template<class T, class Policies> inline
interval<T, Policies> div_zero_part2(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()) && (div_zero_part1(x, y, b), b));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x.upper()))
return I(rnd.div_down(x.upper(), y.lower()), checking::pos_inf(), true);
else
return I(rnd.div_down(x.lower(), y.upper()), checking::pos_inf(), true);
}
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP

View File

@@ -0,0 +1,83 @@
/* Boost interval/detail/ia64_rounding_control.hpp file
*
* Copyright 2006-2007 Boris Gubenko
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP
#if !defined(ia64) && !defined(__ia64) && !defined(__ia64__)
#error This header only works on ia64 CPUs.
#endif
#if defined(__hpux)
# include <fenv.h>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
struct ia64_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode) {
fesetround(mode); }
static void get_rounding_mode(rounding_mode& mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
};
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
long double rintl(long double);
}
template<>
struct rounding_control<float>:
detail::ia64_rounding_control
{
static float force_rounding(const float r)
{ volatile float _r = r; return _r; }
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::ia64_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::ia64_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rintl(r); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif /* __hpux */
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,41 @@
/* Boost interval/detail/interval_prototype.hpp file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP
namespace boost {
namespace numeric {
namespace interval_lib {
template<class T> struct rounded_math;
template<class T> struct checking_strict;
class comparison_error;
template<class Rounding, class Checking> struct policies;
/*
* default policies class
*/
template<class T>
struct default_policies
{
typedef policies<rounded_math<T>, checking_strict<T> > type;
};
} // namespace interval_lib
template<class T, class Policies = typename interval_lib::default_policies<T>::type >
class interval;
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP

View File

@@ -0,0 +1,100 @@
/* Boost interval/detail/msvc_rounding_control.hpp file
*
* Copyright 2000 Maarten Keijzer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP
#ifndef _MSC_VER
# error This header is only intended for MSVC, but might work for Borland as well
#endif
#include <float.h> // MSVC rounding control
// Although the function is called _control87, it seems to work for
// other FPUs too, so it does not have to be changed to _controlfp.
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#if BOOST_MSVC < 1400 || defined(_WIN64)
extern "C" { double rint(double); }
#else
inline double rint(double x)
{
_asm FLD [x] ;
_asm FRNDINT ;
//_asm RET ;
}
#endif
struct x86_rounding
{
static unsigned int hard2msvc(unsigned short m) {
unsigned int n = 0;
if (m & 0x01) n |= _EM_INVALID;
if (m & 0x02) n |= _EM_DENORMAL;
if (m & 0x04) n |= _EM_ZERODIVIDE;
if (m & 0x08) n |= _EM_OVERFLOW;
if (m & 0x10) n |= _EM_UNDERFLOW;
if (m & 0x20) n |= _EM_INEXACT;
switch (m & 0x300) {
case 0x000: n |= _PC_24; break;
case 0x200: n |= _PC_53; break;
case 0x300: n |= _PC_64; break;
}
switch (m & 0xC00) {
case 0x000: n |= _RC_NEAR; break;
case 0x400: n |= _RC_DOWN; break;
case 0x800: n |= _RC_UP; break;
case 0xC00: n |= _RC_CHOP; break;
}
if (m & 0x1000) n |= _IC_AFFINE; // only useful on 287
return n;
}
static unsigned short msvc2hard(unsigned int n) {
unsigned short m = 0;
if (n & _EM_INVALID) m |= 0x01;
if (n & _EM_DENORMAL) m |= 0x02;
if (n & _EM_ZERODIVIDE) m |= 0x04;
if (n & _EM_OVERFLOW) m |= 0x08;
if (n & _EM_UNDERFLOW) m |= 0x10;
if (n & _EM_INEXACT) m |= 0x20;
switch (n & _MCW_RC) {
case _RC_NEAR: m |= 0x000; break;
case _RC_DOWN: m |= 0x400; break;
case _RC_UP: m |= 0x800; break;
case _RC_CHOP: m |= 0xC00; break;
}
switch (n & _MCW_PC) {
case _PC_24: m |= 0x000; break;
case _PC_53: m |= 0x200; break;
case _PC_64: m |= 0x300; break;
}
if ((n & _MCW_IC) == _IC_AFFINE) m |= 0x1000;
return m;
}
typedef unsigned short rounding_mode;
static void get_rounding_mode(rounding_mode& mode)
{ mode = msvc2hard(_control87(0, 0)); }
static void set_rounding_mode(const rounding_mode mode)
{ _control87(hard2msvc(mode), _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC); }
static double to_int(const double& x) { return rint(x); }
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,99 @@
/* Boost interval/detail/ppc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
* Copyright 2005 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP
#if !defined(powerpc) && !defined(__powerpc__) && !defined(__ppc__)
#error This header only works on PPC CPUs.
#endif
#if defined(__GNUC__ ) || (__IBMCPP__ >= 700)
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
typedef union {
::boost::long_long_type imode;
double dmode;
} rounding_mode_struct;
static const rounding_mode_struct mode_upward = { 0xFFF8000000000002LL };
static const rounding_mode_struct mode_downward = { 0xFFF8000000000003LL };
static const rounding_mode_struct mode_to_nearest = { 0xFFF8000000000000LL };
static const rounding_mode_struct mode_toward_zero = { 0xFFF8000000000001LL };
struct ppc_rounding_control
{
typedef double rounding_mode;
static void set_rounding_mode(const rounding_mode mode)
{ __asm__ __volatile__ ("mtfsf 255,%0" : : "f"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("mffs %0" : "=f"(mode)); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
};
} // namespace detail
// Do not declare the following C99 symbols if <math.h> provides them.
// Otherwise, conflicts may occur, due to differences between prototypes.
#if !defined(_ISOC99_SOURCE) && !defined(__USE_ISOC99)
extern "C" {
float rintf(float);
double rint(double);
}
#endif
template<>
struct rounding_control<float>:
detail::ppc_rounding_control
{
static float force_rounding(const float r)
{
float tmp;
__asm__ __volatile__ ("frsp %0, %1" : "=f" (tmp) : "f" (r));
return tmp;
}
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::ppc_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::ppc_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rint(r); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,112 @@
/* Boost interval/detail/sparc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*
* The basic code in this file was kindly provided by Jeremy Siek.
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
#if !defined(sparc) && !defined(__sparc__)
# error This header is only intended for SPARC CPUs.
#endif
#ifdef __SUNPRO_CC
# include <ieeefp.h>
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
struct sparc_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode)
{
# if defined(__GNUC__)
__asm__ __volatile__("ld %0, %%fsr" : : "m"(mode));
# elif defined (__SUNPRO_CC)
fpsetround(fp_rnd(mode));
# elif defined(__KCC)
asm("sethi %hi(mode), %o1");
asm("ld [%o1+%lo(mode)], %fsr");
# else
# error Unsupported compiler for Sparc rounding control.
# endif
}
static void get_rounding_mode(rounding_mode& mode)
{
# if defined(__GNUC__)
__asm__ __volatile__("st %%fsr, %0" : "=m"(mode));
# elif defined (__SUNPRO_CC)
mode = fpgetround();
# elif defined(__KCC)
# error KCC on Sun SPARC get_round_mode: please fix me
asm("st %fsr, [mode]");
# else
# error Unsupported compiler for Sparc rounding control.
# endif
}
#if defined(__SUNPRO_CC)
static void downward() { set_rounding_mode(FP_RM); }
static void upward() { set_rounding_mode(FP_RP); }
static void to_nearest() { set_rounding_mode(FP_RN); }
static void toward_zero() { set_rounding_mode(FP_RZ); }
#else
static void downward() { set_rounding_mode(0xc0000000); }
static void upward() { set_rounding_mode(0x80000000); }
static void to_nearest() { set_rounding_mode(0x00000000); }
static void toward_zero() { set_rounding_mode(0x40000000); }
#endif
};
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
}
template<>
struct rounding_control<float>:
detail::sparc_rounding_control
{
static const float& force_rounding(const float& x) { return x; }
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::sparc_rounding_control
{
static const double& force_rounding(const double& x) { return x; }
static double to_int(const double& x) { return rint(x); }
};
template<>
struct rounding_control<long double>:
detail::sparc_rounding_control
{
static const long double& force_rounding(const long double& x) { return x; }
static long double to_int(const long double& x) { return rint(x); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,76 @@
/* Boost interval/detail/test_input.hpp file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace user {
template<class T> inline
bool is_zero(T const &v) { return v == static_cast<T>(0); }
template<class T> inline
bool is_neg (T const &v) { return v < static_cast<T>(0); }
template<class T> inline
bool is_pos (T const &v) { return v > static_cast<T>(0); }
} // namespace user
namespace detail {
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x) {
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper());
}
template<class T, class Policies1, class Policies2> inline
bool test_input(const interval<T, Policies1>& x, const interval<T, Policies2>& y) {
typedef typename Policies1::checking checking1;
typedef typename Policies2::checking checking2;
return checking1::is_empty(x.lower(), x.upper()) ||
checking2::is_empty(y.lower(), y.upper());
}
template<class T, class Policies> inline
bool test_input(const T& x, const interval<T, Policies>& y) {
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper());
}
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x, const T& y) {
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y);
}
template<class T, class Policies> inline
bool test_input(const T& x) {
typedef typename Policies::checking checking;
return checking::is_nan(x);
}
template<class T, class Policies> inline
bool test_input(const T& x, const T& y) {
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_nan(y);
}
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP

View File

@@ -0,0 +1,108 @@
/* Boost interval/detail/x86_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP
#ifdef __GNUC__
# include <boost/numeric/interval/detail/x86gcc_rounding_control.hpp>
#elif defined(__BORLANDC__)
# include <boost/numeric/interval/detail/bcc_rounding_control.hpp>
#elif defined(_MSC_VER)
# include <boost/numeric/interval/detail/msvc_rounding_control.hpp>
#elif defined(__MWERKS__) || defined(__ICC) || defined (__SUNPRO_CC)
# define BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
# include <boost/numeric/interval/detail/c99sub_rounding_control.hpp>
#else
# error Unsupported C++ compiler.
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#ifdef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
typedef c99_rounding_control x86_rounding_control;
#undef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
#else
struct fpu_rounding_modes
{
unsigned short to_nearest;
unsigned short downward;
unsigned short upward;
unsigned short toward_zero;
};
// exceptions masked, extended precision
// hardware default is 0x037f (0x1000 only has a meaning on 287)
static const fpu_rounding_modes rnd_mode = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
struct x86_rounding_control: x86_rounding
{
static void to_nearest() { set_rounding_mode(rnd_mode.to_nearest); }
static void downward() { set_rounding_mode(rnd_mode.downward); }
static void upward() { set_rounding_mode(rnd_mode.upward); }
static void toward_zero() { set_rounding_mode(rnd_mode.toward_zero); }
};
#endif // BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
} // namespace detail
template<>
struct rounding_control<float>: detail::x86_rounding_control
{
static float force_rounding(const float& r)
{ volatile float r_ = r; return r_; }
};
template<>
struct rounding_control<double>: detail::x86_rounding_control
{
/*static double force_rounding(double r)
{ asm volatile ("" : "+m"(r) : ); return r; }*/
static double force_rounding(const double& r)
{ volatile double r_ = r; return r_; }
};
namespace detail {
template<bool>
struct x86_rounding_control_long_double;
template<>
struct x86_rounding_control_long_double<false>: x86_rounding_control
{
static long double force_rounding(long double const &r)
{ volatile long double r_ = r; return r_; }
};
template<>
struct x86_rounding_control_long_double<true>: x86_rounding_control
{
static long double const &force_rounding(long double const &r)
{ return r; }
};
} // namespace detail
template<>
struct rounding_control<long double>:
detail::x86_rounding_control_long_double< (sizeof(long double) >= 10) >
{};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,51 @@
/* Boost interval/detail/x86gcc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
#ifndef __GNUC__
# error This header only works with GNU CC.
#endif
#ifndef __i386__
# error This header only works on x86 CPUs.
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
struct x86_rounding
{
typedef unsigned short rounding_mode;
static void set_rounding_mode(const rounding_mode& mode)
{ __asm__ __volatile__ ("fldcw %0" : : "m"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("fnstcw %0" : "=m"(mode)); }
template<class T>
static T to_int(T r)
{
T r_;
__asm__ ("frndint" : "=&t"(r_) : "0"(r));
return r_;
}
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,70 @@
/* Boost interval/ext/integer.hpp template implementation file
*
* Copyright 2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_EXT_INTEGER_HPP
#define BOOST_NUMERIC_INTERVAL_EXT_INTEGER_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
namespace boost {
namespace numeric {
template<class T, class Policies> inline
interval<T, Policies> operator+ (const interval<T, Policies>& x, int y)
{
return x + static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator+ (int x, const interval<T, Policies>& y)
{
return static_cast<T>(x) + y;
}
template<class T, class Policies> inline
interval<T, Policies> operator- (const interval<T, Policies>& x, int y)
{
return x - static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator- (int x, const interval<T, Policies>& y)
{
return static_cast<T>(x) - y;
}
template<class T, class Policies> inline
interval<T, Policies> operator* (const interval<T, Policies>& x, int y)
{
return x * static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator* (int x, const interval<T, Policies>& y)
{
return static_cast<T>(x) * y;
}
template<class T, class Policies> inline
interval<T, Policies> operator/ (const interval<T, Policies>& x, int y)
{
return x / static_cast<T>(y);
}
template<class T, class Policies> inline
interval<T, Policies> operator/ (int x, const interval<T, Policies>& y)
{
return static_cast<T>(x) / y;
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_EXT_INTEGER_HPP

View File

@@ -0,0 +1,70 @@
/* Boost interval/detail/x86gcc_rounding_control.hpp file
*
* This header provides a rounding control policy
* that avoids flushing results to memory. In
* order for this optimization to be reliable, it
* should be used only when no underflow or
* overflow would happen without it. Indeed, only
* values in range are correctly rounded.
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
// exceptions masked, expected precision (the mask is 0x0300)
static const fpu_rounding_modes rnd_mode_f = { 0x107f, 0x147f, 0x187f, 0x1c7f };
static const fpu_rounding_modes rnd_mode_d = { 0x127f, 0x167f, 0x1a7f, 0x1e7f };
static const fpu_rounding_modes rnd_mode_l = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
} // namespace detail
template<class T>
struct x86_fast_rounding_control;
template<>
struct x86_fast_rounding_control<float>: detail::x86_rounding
{
static void to_nearest() { set_rounding_mode(detail::rnd_mode_f.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_f.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_f.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_f.toward_zero); }
static const float& force_rounding(const float& r) { return r; }
};
template<>
struct x86_fast_rounding_control<double>: detail::x86_rounding
{
static void to_nearest() { set_rounding_mode(detail::rnd_mode_d.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_d.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_d.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_d.toward_zero); }
static const double& force_rounding(const double& r) { return r; }
};
template<>
struct x86_fast_rounding_control<long double>: detail::x86_rounding
{
static void to_nearest() { set_rounding_mode(detail::rnd_mode_l.to_nearest); }
static void downward() { set_rounding_mode(detail::rnd_mode_l.downward); }
static void upward() { set_rounding_mode(detail::rnd_mode_l.upward); }
static void toward_zero() { set_rounding_mode(detail::rnd_mode_l.toward_zero); }
static const long double& force_rounding(const long double& r) { return r; }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP

View File

@@ -0,0 +1,70 @@
/* Boost interval/hw_rounding.hpp template implementation file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
* Copyright 2005 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP
#define BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>
#define BOOST_NUMERIC_INTERVAL_NO_HARDWARE
// define appropriate specialization of rounding_control for built-in types
#if defined(__x86_64__) && (defined(__USE_ISOC99) || defined(__APPLE__))
# include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#elif defined(__i386__) || defined(_M_IX86) || defined(__BORLANDC__) || defined(_M_X64)
# include <boost/numeric/interval/detail/x86_rounding_control.hpp>
#elif defined(powerpc) || defined(__powerpc__) || defined(__ppc__)
# include <boost/numeric/interval/detail/ppc_rounding_control.hpp>
#elif defined(sparc) || defined(__sparc__)
# include <boost/numeric/interval/detail/sparc_rounding_control.hpp>
#elif defined(alpha) || defined(__alpha__)
# include <boost/numeric/interval/detail/alpha_rounding_control.hpp>
#elif defined(ia64) || defined(__ia64) || defined(__ia64__)
# include <boost/numeric/interval/detail/ia64_rounding_control.hpp>
#endif
#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE) && (defined(__USE_ISOC99) || defined(__MSL__))
# include <boost/numeric/interval/detail/c99_rounding_control.hpp>
#endif
#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE)
# undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
# error Boost.Numeric.Interval: Please specify rounding control mechanism.
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
/*
* Three specializations of rounded_math<T>
*/
template<>
struct rounded_math<float>
: save_state<rounded_arith_opp<float> >
{};
template<>
struct rounded_math<double>
: save_state<rounded_arith_opp<double> >
{};
template<>
struct rounded_math<long double>
: save_state<rounded_arith_opp<long double> >
{};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP

View File

@@ -0,0 +1,450 @@
/* Boost interval/interval.hpp header file
*
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_INTERVAL_HPP
#define BOOST_NUMERIC_INTERVAL_INTERVAL_HPP
#include <stdexcept>
#include <string>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
class comparison_error
: public std::runtime_error
{
public:
comparison_error()
: std::runtime_error("boost::interval: uncertain comparison")
{ }
};
} // namespace interval_lib
/*
* interval class
*/
template<class T, class Policies>
class interval
{
private:
struct interval_holder;
struct number_holder;
public:
typedef T base_type;
typedef Policies traits_type;
T const &lower() const;
T const &upper() const;
interval();
interval(T const &v);
template<class T1> interval(T1 const &v);
interval(T const &l, T const &u);
template<class T1, class T2> interval(T1 const &l, T2 const &u);
interval(interval<T, Policies> const &r);
template<class Policies1> interval(interval<T, Policies1> const &r);
template<class T1, class Policies1> interval(interval<T1, Policies1> const &r);
interval &operator=(T const &v);
template<class T1> interval &operator=(T1 const &v);
interval &operator=(interval<T, Policies> const &r);
template<class Policies1> interval &operator=(interval<T, Policies1> const &r);
template<class T1, class Policies1> interval &operator=(interval<T1, Policies1> const &r);
void assign(const T& l, const T& u);
static interval empty();
static interval whole();
static interval hull(const T& x, const T& y);
interval& operator+= (const T& r);
interval& operator+= (const interval& r);
interval& operator-= (const T& r);
interval& operator-= (const interval& r);
interval& operator*= (const T& r);
interval& operator*= (const interval& r);
interval& operator/= (const T& r);
interval& operator/= (const interval& r);
bool operator< (const interval_holder& r) const;
bool operator> (const interval_holder& r) const;
bool operator<= (const interval_holder& r) const;
bool operator>= (const interval_holder& r) const;
bool operator== (const interval_holder& r) const;
bool operator!= (const interval_holder& r) const;
bool operator< (const number_holder& r) const;
bool operator> (const number_holder& r) const;
bool operator<= (const number_holder& r) const;
bool operator>= (const number_holder& r) const;
bool operator== (const number_holder& r) const;
bool operator!= (const number_holder& r) const;
// the following is for internal use only, it is not a published interface
// nevertheless, it's public because friends don't always work correctly.
interval(const T& l, const T& u, bool): low(l), up(u) {}
void set_empty();
void set_whole();
void set(const T& l, const T& u);
private:
struct interval_holder {
template<class Policies2>
interval_holder(const interval<T, Policies2>& r)
: low(r.lower()), up(r.upper())
{
typedef typename Policies2::checking checking2;
if (checking2::is_empty(low, up))
throw interval_lib::comparison_error();
}
const T& low;
const T& up;
};
struct number_holder {
number_holder(const T& r) : val(r)
{
typedef typename Policies::checking checking;
if (checking::is_nan(r))
throw interval_lib::comparison_error();
}
const T& val;
};
typedef typename Policies::checking checking;
typedef typename Policies::rounding rounding;
T low;
T up;
};
template<class T, class Policies> inline
interval<T, Policies>::interval():
low(static_cast<T>(0)), up(static_cast<T>(0))
{}
template<class T, class Policies> inline
interval<T, Policies>::interval(T const &v): low(v), up(v)
{
if (checking::is_nan(v)) set_empty();
}
template<class T, class Policies> template<class T1> inline
interval<T, Policies>::interval(T1 const &v)
{
if (checking::is_nan(v)) set_empty();
else {
rounding rnd;
low = rnd.conv_down(v);
up = rnd.conv_up (v);
}
}
template<class T, class Policies> template<class T1, class T2> inline
interval<T, Policies>::interval(T1 const &l, T2 const &u)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u)) set_empty();
else {
rounding rnd;
low = rnd.conv_down(l);
up = rnd.conv_up (u);
}
}
template<class T, class Policies> inline
interval<T, Policies>::interval(T const &l, T const &u): low(l), up(u)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
}
template<class T, class Policies> inline
interval<T, Policies>::interval(interval<T, Policies> const &r): low(r.lower()), up(r.upper())
{}
template<class T, class Policies> template<class Policies1> inline
interval<T, Policies>::interval(interval<T, Policies1> const &r): low(r.lower()), up(r.upper())
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
}
template<class T, class Policies> template<class T1, class Policies1> inline
interval<T, Policies>::interval(interval<T1, Policies1> const &r)
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
else {
rounding rnd;
low = rnd.conv_down(r.lower());
up = rnd.conv_up (r.upper());
}
}
template<class T, class Policies> inline
interval<T, Policies> &interval<T, Policies>::operator=(T const &v)
{
if (checking::is_nan(v)) set_empty();
else low = up = v;
return *this;
}
template<class T, class Policies> template<class T1> inline
interval<T, Policies> &interval<T, Policies>::operator=(T1 const &v)
{
if (checking::is_nan(v)) set_empty();
else {
rounding rnd;
low = rnd.conv_down(v);
up = rnd.conv_up (v);
}
return *this;
}
template<class T, class Policies> inline
interval<T, Policies> &interval<T, Policies>::operator=(interval<T, Policies> const &r)
{
low = r.lower();
up = r.upper();
return *this;
}
template<class T, class Policies> template<class Policies1> inline
interval<T, Policies> &interval<T, Policies>::operator=(interval<T, Policies1> const &r)
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
else {
low = r.lower();
up = r.upper();
}
return *this;
}
template<class T, class Policies> template<class T1, class Policies1> inline
interval<T, Policies> &interval<T, Policies>::operator=(interval<T1, Policies1> const &r)
{
typedef typename Policies1::checking checking1;
if (checking1::is_empty(r.lower(), r.upper())) set_empty();
else {
rounding rnd;
low = rnd.conv_down(r.lower());
up = rnd.conv_up (r.upper());
}
return *this;
}
template<class T, class Policies> inline
void interval<T, Policies>::assign(const T& l, const T& u)
{
if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u))
set_empty();
else set(l, u);
}
template<class T, class Policies> inline
void interval<T, Policies>::set(const T& l, const T& u)
{
low = l;
up = u;
}
template<class T, class Policies> inline
void interval<T, Policies>::set_empty()
{
low = checking::empty_lower();
up = checking::empty_upper();
}
template<class T, class Policies> inline
void interval<T, Policies>::set_whole()
{
low = checking::neg_inf();
up = checking::pos_inf();
}
template<class T, class Policies> inline
interval<T, Policies> interval<T, Policies>::hull(const T& x, const T& y)
{
bool bad_x = checking::is_nan(x);
bool bad_y = checking::is_nan(y);
if (bad_x)
if (bad_y) return interval::empty();
else return interval(y, y, true);
else
if (bad_y) return interval(x, x, true);
if (x <= y) return interval(x, y, true);
else return interval(y, x, true);
}
template<class T, class Policies> inline
interval<T, Policies> interval<T, Policies>::empty()
{
return interval<T, Policies>(checking::empty_lower(),
checking::empty_upper(), true);
}
template<class T, class Policies> inline
interval<T, Policies> interval<T, Policies>::whole()
{
return interval<T, Policies>(checking::neg_inf(), checking::pos_inf(), true);
}
template<class T, class Policies> inline
const T& interval<T, Policies>::lower() const
{
return low;
}
template<class T, class Policies> inline
const T& interval<T, Policies>::upper() const
{
return up;
}
/*
* interval/interval comparisons
*/
template<class T, class Policies> inline
bool interval<T, Policies>::operator< (const interval_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.low) return true;
else if (low >= r.up) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator> (const interval_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (low > r.up) return true;
else if (up <= r.low) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator<= (const interval_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up <= r.low) return true;
else if (low > r.up) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator>= (const interval_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (low >= r.up) return true;
else if (up < r.low) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator== (const interval_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up == r.low && low == r.up) return true;
else if (up < r.low || low > r.up) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator!= (const interval_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.low || low > r.up) return true;
else if (up == r.low && low == r.up) return false;
}
throw interval_lib::comparison_error();
}
/*
* interval/number comparisons
*/
template<class T, class Policies> inline
bool interval<T, Policies>::operator< (const number_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.val) return true;
else if (low >= r.val) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator> (const number_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (low > r.val) return true;
else if (up <= r.val) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator<= (const number_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up <= r.val) return true;
else if (low > r.val) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator>= (const number_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (low >= r.val) return true;
else if (up < r.val) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator== (const number_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up == r.val && low == r.val) return true;
else if (up < r.val || low > r.val) return false;
}
throw interval_lib::comparison_error();
}
template<class T, class Policies> inline
bool interval<T, Policies>::operator!= (const number_holder& r) const
{
if (!checking::is_empty(low, up)) {
if (up < r.val || low > r.val) return true;
else if (up == r.val && low == r.val) return false;
}
throw interval_lib::comparison_error();
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_INTERVAL_HPP

View File

@@ -0,0 +1,41 @@
/* Boost interval/io.hpp header file
*
* This file is only meant to provide a quick
* implementation of the output operator. It is
* provided for test programs that aren't even
* interested in the precision of the results.
* A real progam should define its own operators
* and never include this header.
*
* Copyright 2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_IO_HPP
#define BOOST_NUMERIC_INTERVAL_IO_HPP
#include <boost/numeric/interval/interval.hpp>
#include <boost/numeric/interval/utility.hpp>
#include <ostream>
namespace boost {
namespace numeric {
template<class CharType, class CharTraits, class T, class Policies>
std::basic_ostream<CharType, CharTraits> &operator<<
(std::basic_ostream<CharType, CharTraits> &stream,
interval<T, Policies> const &value)
{
if (empty(value))
return stream << "[]";
else
return stream << '[' << lower(value) << ',' << upper(value) << ']';
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_IO_HPP

View File

@@ -0,0 +1,51 @@
/* Boost interval/limits.hpp template implementation file
*
* Copyright 2000 Jens Maurer
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_LIMITS_HPP
#define BOOST_NUMERIC_INTERVAL_LIMITS_HPP
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#include <boost/config.hpp>
#include <boost/limits.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
namespace std {
template<class T, class Policies>
class numeric_limits<boost::numeric::interval<T, Policies> >
: public numeric_limits<T>
{
private:
typedef boost::numeric::interval<T, Policies> I;
typedef numeric_limits<T> bl;
public:
static I min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return I((bl::min)(), (bl::min)()); }
static I max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return I((bl::max)(), (bl::max)()); }
static I epsilon() throw() { return I(bl::epsilon(), bl::epsilon()); }
BOOST_STATIC_CONSTANT(float_round_style, round_style = round_indeterminate);
BOOST_STATIC_CONSTANT(bool, is_iec559 = false);
static I infinity () throw() { return I::whole(); }
static I quiet_NaN() throw() { return I::empty(); }
static I signaling_NaN() throw()
{ return I(bl::signaling_NaN(), bl::signaling_Nan()); }
static I denorm_min() throw()
{ return I(bl::denorm_min(), bl::denorm_min()); }
private:
static I round_error(); // hide this on purpose, not yet implemented
};
} // namespace std
#endif
#endif // BOOST_NUMERIC_INTERVAL_LIMITS_HPP

View File

@@ -0,0 +1,75 @@
/* Boost interval/policies.hpp template implementation file
*
* Copyright 2003 Guillaume Melquiond
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_POLICIES_HPP
#define BOOST_NUMERIC_INTERVAL_POLICIES_HPP
#include <boost/numeric/interval/interval.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
/*
* policies class
*/
template<class Rounding, class Checking>
struct policies
{
typedef Rounding rounding;
typedef Checking checking;
};
/*
* policies switching classes
*/
template<class OldInterval, class NewRounding>
class change_rounding
{
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::checking checking;
public:
typedef interval<T, policies<NewRounding, checking> > type;
};
template<class OldInterval, class NewChecking>
class change_checking
{
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::rounding rounding;
public:
typedef interval<T, policies<rounding, NewChecking> > type;
};
/*
* Protect / unprotect: control whether the rounding mode is set/reset
* at each operation, rather than once and for all.
*/
template<class OldInterval>
class unprotect
{
typedef typename OldInterval::base_type T;
typedef typename OldInterval::traits_type p;
typedef typename p::rounding r;
typedef typename r::unprotected_rounding newRounding;
public:
typedef typename change_rounding<OldInterval, newRounding>::type type;
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_POLICIES_HPP

View File

@@ -0,0 +1,120 @@
/* Boost interval/rounded_arith.hpp template implementation file
*
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP
#define BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
/*
* Three classes of rounding: exact, std, opp
* See documentation for details.
*/
template<class T, class Rounding>
struct rounded_arith_exact: Rounding {
void init() { }
template<class U> T conv_down(U const &v) { return v; }
template<class U> T conv_up (U const &v) { return v; }
T add_down (const T& x, const T& y) { return x + y; }
T add_up (const T& x, const T& y) { return x + y; }
T sub_down (const T& x, const T& y) { return x - y; }
T sub_up (const T& x, const T& y) { return x - y; }
T mul_down (const T& x, const T& y) { return x * y; }
T mul_up (const T& x, const T& y) { return x * y; }
T div_down (const T& x, const T& y) { return x / y; }
T div_up (const T& x, const T& y) { return x / y; }
T median (const T& x, const T& y) { return (x + y) / 2; }
T sqrt_down(const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); return sqrt(x); }
T sqrt_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); return sqrt(x); }
T int_down (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(floor); return floor(x); }
T int_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(ceil); return ceil(x); }
};
template<class T, class Rounding>
struct rounded_arith_std: Rounding {
# define BOOST_DN(EXPR) this->downward(); return this->force_rounding(EXPR)
# define BOOST_NR(EXPR) this->to_nearest(); return this->force_rounding(EXPR)
# define BOOST_UP(EXPR) this->upward(); return this->force_rounding(EXPR)
void init() { }
template<class U> T conv_down(U const &v) { BOOST_DN(v); }
template<class U> T conv_up (U const &v) { BOOST_UP(v); }
T add_down(const T& x, const T& y) { BOOST_DN(x + y); }
T sub_down(const T& x, const T& y) { BOOST_DN(x - y); }
T mul_down(const T& x, const T& y) { BOOST_DN(x * y); }
T div_down(const T& x, const T& y) { BOOST_DN(x / y); }
T add_up (const T& x, const T& y) { BOOST_UP(x + y); }
T sub_up (const T& x, const T& y) { BOOST_UP(x - y); }
T mul_up (const T& x, const T& y) { BOOST_UP(x * y); }
T div_up (const T& x, const T& y) { BOOST_UP(x / y); }
T median(const T& x, const T& y) { BOOST_NR((x + y) / 2); }
T sqrt_down(const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_DN(sqrt(x)); }
T sqrt_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_UP(sqrt(x)); }
T int_down(const T& x) { this->downward(); return to_int(x); }
T int_up (const T& x) { this->upward(); return to_int(x); }
# undef BOOST_DN
# undef BOOST_NR
# undef BOOST_UP
};
template<class T, class Rounding>
struct rounded_arith_opp: Rounding {
void init() { this->upward(); }
# define BOOST_DN(EXPR) \
this->downward(); \
T r = this->force_rounding(EXPR); \
this->upward(); \
return r
# define BOOST_NR(EXPR) \
this->to_nearest(); \
T r = this->force_rounding(EXPR); \
this->upward(); \
return r
# define BOOST_UP(EXPR) return this->force_rounding(EXPR)
# define BOOST_UP_NEG(EXPR) return -this->force_rounding(EXPR)
template<class U> T conv_down(U const &v) { BOOST_UP_NEG(-v); }
template<class U> T conv_up (U const &v) { BOOST_UP(v); }
T add_down(const T& x, const T& y) { BOOST_UP_NEG((-x) - y); }
T sub_down(const T& x, const T& y) { BOOST_UP_NEG(y - x); }
T mul_down(const T& x, const T& y) { BOOST_UP_NEG(x * (-y)); }
T div_down(const T& x, const T& y) { BOOST_UP_NEG(x / (-y)); }
T add_up (const T& x, const T& y) { BOOST_UP(x + y); }
T sub_up (const T& x, const T& y) { BOOST_UP(x - y); }
T mul_up (const T& x, const T& y) { BOOST_UP(x * y); }
T div_up (const T& x, const T& y) { BOOST_UP(x / y); }
T median (const T& x, const T& y) { BOOST_NR((x + y) / 2); }
T sqrt_down(const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_DN(sqrt(x)); }
T sqrt_up (const T& x)
{ BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_UP(sqrt(x)); }
T int_down(const T& x) { return -to_int(-x); }
T int_up (const T& x) { return to_int(x); }
# undef BOOST_DN
# undef BOOST_NR
# undef BOOST_UP
# undef BOOST_UP_NEG
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP

View File

@@ -0,0 +1,140 @@
/* Boost interval/rounded_transc.hpp template implementation file
*
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP
#define BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
template<class T, class Rounding>
struct rounded_transc_exact: Rounding
{
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); } \
T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); }
BOOST_NUMERIC_INTERVAL_new_func(exp)
BOOST_NUMERIC_INTERVAL_new_func(log)
BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(acos)
BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh)
BOOST_NUMERIC_INTERVAL_new_func(cosh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); } \
T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); }
BOOST_NUMERIC_INTERVAL_new_func(asinh)
BOOST_NUMERIC_INTERVAL_new_func(acosh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
};
template<class T, class Rounding>
struct rounded_transc_std: Rounding
{
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
this->downward(); return this->force_rounding(f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
this->upward(); return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(exp)
BOOST_NUMERIC_INTERVAL_new_func(log)
BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(acos)
BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh)
BOOST_NUMERIC_INTERVAL_new_func(cosh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->downward(); return this->force_rounding(f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->upward(); return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(asinh)
BOOST_NUMERIC_INTERVAL_new_func(acosh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
};
template<class T, class Rounding>
struct rounded_transc_opp: Rounding
{
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
this->downward(); T y = this->force_rounding(f(x)); \
this->upward(); return y; } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(exp)
BOOST_NUMERIC_INTERVAL_new_func(log)
BOOST_NUMERIC_INTERVAL_new_func(cos)
BOOST_NUMERIC_INTERVAL_new_func(acos)
BOOST_NUMERIC_INTERVAL_new_func(cosh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
return -this->force_rounding(-f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_math(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(sin)
BOOST_NUMERIC_INTERVAL_new_func(tan)
BOOST_NUMERIC_INTERVAL_new_func(asin)
BOOST_NUMERIC_INTERVAL_new_func(atan)
BOOST_NUMERIC_INTERVAL_new_func(sinh)
BOOST_NUMERIC_INTERVAL_new_func(tanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
this->downward(); T y = this->force_rounding(f(x)); \
this->upward(); return y; } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(asinh)
BOOST_NUMERIC_INTERVAL_new_func(atanh)
# undef BOOST_NUMERIC_INTERVAL_new_func
# define BOOST_NUMERIC_INTERVAL_new_func(f) \
T f##_down(const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return -this->force_rounding(-f(x)); } \
T f##_up (const T& x) \
{ BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
return this->force_rounding(f(x)); }
BOOST_NUMERIC_INTERVAL_new_func(acosh)
# undef BOOST_NUMERIC_INTERVAL_new_func
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP

View File

@@ -0,0 +1,101 @@
/* Boost interval/rounding.hpp template implementation file
*
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
#define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
namespace boost {
namespace numeric {
namespace interval_lib {
/*
* Default rounding_control class (does nothing)
*/
template<class T>
struct rounding_control
{
typedef int rounding_mode;
static void get_rounding_mode(rounding_mode&) {}
static void set_rounding_mode(rounding_mode) {}
static void upward() {}
static void downward() {}
static void to_nearest() {}
static const T& to_int(const T& x) { return x; }
static const T& force_rounding(const T& x) { return x; }
};
/*
* A few rounding control classes (exact/std/opp: see documentation)
* rounded_arith_* control the rounding of the arithmetic operators
* rounded_transc_* control the rounding of the transcendental functions
*/
template<class T, class Rounding = rounding_control<T> >
struct rounded_arith_exact;
template<class T, class Rounding = rounding_control<T> >
struct rounded_arith_std;
template<class T, class Rounding = rounding_control<T> >
struct rounded_arith_opp;
template<class T, class Rounding>
struct rounded_transc_dummy;
template<class T, class Rounding = rounded_arith_exact<T> >
struct rounded_transc_exact;
template<class T, class Rounding = rounded_arith_std<T> >
struct rounded_transc_std;
template<class T, class Rounding = rounded_arith_opp<T> >
struct rounded_transc_opp;
/*
* State-saving classes: allow to set and reset rounding control
*/
namespace detail {
template<class Rounding>
struct save_state_unprotected: Rounding
{
typedef save_state_unprotected<Rounding> unprotected_rounding;
};
} // namespace detail
template<class Rounding>
struct save_state: Rounding
{
typename Rounding::rounding_mode mode;
save_state() {
this->get_rounding_mode(mode);
this->init();
}
~save_state() { this->set_rounding_mode(mode); }
typedef detail::save_state_unprotected<Rounding> unprotected_rounding;
};
template<class Rounding>
struct save_state_nothing: Rounding
{
typedef save_state_nothing<Rounding> unprotected_rounding;
};
template<class T>
struct rounded_math: save_state_nothing<rounded_arith_exact<T> >
{};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP

View File

@@ -0,0 +1,232 @@
/* Boost interval/transc.hpp template implementation file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_TRANSC_HPP
#define BOOST_NUMERIC_INTERVAL_TRANSC_HPP
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/rounding.hpp>
#include <boost/numeric/interval/constants.hpp>
#include <boost/numeric/interval/arith.hpp>
#include <boost/numeric/interval/arith2.hpp>
#include <algorithm>
namespace boost {
namespace numeric {
template<class T, class Policies> inline
interval<T, Policies> exp(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.exp_down(x.lower()), rnd.exp_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> log(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) ||
!interval_lib::user::is_pos(x.upper()))
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = !interval_lib::user::is_pos(x.lower())
? checking::neg_inf() : rnd.log_down(x.lower());
return I(l, rnd.log_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> cos(const interval<T, Policies>& x)
{
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename interval_lib::unprotect<I>::type R;
// get lower bound within [0, pi]
const R pi2 = interval_lib::pi_twice<R>();
R tmp = fmod((const R&)x, pi2);
if (width(tmp) >= pi2.lower())
return I(static_cast<T>(-1), static_cast<T>(1), true); // we are covering a full period
if (tmp.lower() >= interval_lib::constants::pi_upper<T>())
return -cos(tmp - interval_lib::pi<R>());
T l = tmp.lower();
T u = tmp.upper();
BOOST_USING_STD_MIN();
// separate into monotone subintervals
if (u <= interval_lib::constants::pi_lower<T>())
return I(rnd.cos_down(u), rnd.cos_up(l), true);
else if (u <= pi2.lower())
return I(static_cast<T>(-1), rnd.cos_up(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.sub_down(pi2.lower(), u), l)), true);
else
return I(static_cast<T>(-1), static_cast<T>(1), true);
}
template<class T, class Policies> inline
interval<T, Policies> sin(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
I r = cos((const R&)x - interval_lib::pi_half<R>());
(void)&rnd;
return r;
}
template<class T, class Policies> inline
interval<T, Policies> tan(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
typedef typename interval_lib::unprotect<I>::type R;
// get lower bound within [-pi/2, pi/2]
const R pi = interval_lib::pi<R>();
R tmp = fmod((const R&)x, pi);
const T pi_half_d = interval_lib::constants::pi_half_lower<T>();
if (tmp.lower() >= pi_half_d)
tmp -= pi;
if (tmp.lower() <= -pi_half_d || tmp.upper() >= pi_half_d)
return I::whole();
return I(rnd.tan_down(tmp.lower()), rnd.tan_up(tmp.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> asin(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)
|| x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = (x.lower() <= static_cast<T>(-1))
? -interval_lib::constants::pi_half_upper<T>()
: rnd.asin_down(x.lower());
T u = (x.upper() >= static_cast<T>(1) )
? interval_lib::constants::pi_half_upper<T>()
: rnd.asin_up (x.upper());
return I(l, u, true);
}
template<class T, class Policies> inline
interval<T, Policies> acos(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)
|| x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = (x.upper() >= static_cast<T>(1) )
? static_cast<T>(0)
: rnd.acos_down(x.upper());
T u = (x.lower() <= static_cast<T>(-1))
? interval_lib::constants::pi_upper<T>()
: rnd.acos_up (x.lower());
return I(l, u, true);
}
template<class T, class Policies> inline
interval<T, Policies> atan(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.atan_down(x.lower()), rnd.atan_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> sinh(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.sinh_down(x.lower()), rnd.sinh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> cosh(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
if (interval_lib::user::is_neg(x.upper()))
return I(rnd.cosh_down(x.upper()), rnd.cosh_up(x.lower()), true);
else if (!interval_lib::user::is_neg(x.lower()))
return I(rnd.cosh_down(x.lower()), rnd.cosh_up(x.upper()), true);
else
return I(static_cast<T>(1), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> tanh(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.tanh_down(x.lower()), rnd.tanh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> asinh(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
typename Policies::rounding rnd;
return I(rnd.asinh_down(x.lower()), rnd.asinh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> acosh(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
T l = x.lower() <= static_cast<T>(1) ? static_cast<T>(0) : rnd.acosh_down(x.lower());
return I(l, rnd.acosh_up(x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> atanh(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)
|| x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
return I::empty();
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
T l = (x.lower() <= static_cast<T>(-1))
? checking::neg_inf() : rnd.atanh_down(x.lower());
T u = (x.upper() >= static_cast<T>(1) )
? checking::pos_inf() : rnd.atanh_up (x.upper());
return I(l, u, true);
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_TRANSC_HPP

View File

@@ -0,0 +1,337 @@
/* Boost interval/utility.hpp template implementation file
*
* Copyright 2000 Jens Maurer
* Copyright 2002-2003 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_INTERVAL_UTILITY_HPP
#define BOOST_NUMERIC_INTERVAL_UTILITY_HPP
#include <boost/config.hpp>
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <algorithm>
#include <utility>
/*
* Implementation of simple functions
*/
namespace boost {
namespace numeric {
/*
* Utility Functions
*/
template<class T, class Policies> inline
const T& lower(const interval<T, Policies>& x)
{
return x.lower();
}
template<class T, class Policies> inline
const T& upper(const interval<T, Policies>& x)
{
return x.upper();
}
template<class T, class Policies> inline
T checked_lower(const interval<T, Policies>& x)
{
if (empty(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
return x.lower();
}
template<class T, class Policies> inline
T checked_upper(const interval<T, Policies>& x)
{
if (empty(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
return x.upper();
}
template<class T, class Policies> inline
T width(const interval<T, Policies>& x)
{
if (interval_lib::detail::test_input(x)) return static_cast<T>(0);
typename Policies::rounding rnd;
return rnd.sub_up(x.upper(), x.lower());
}
template<class T, class Policies> inline
T median(const interval<T, Policies>& x)
{
if (interval_lib::detail::test_input(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
typename Policies::rounding rnd;
return rnd.median(x.lower(), x.upper());
}
template<class T, class Policies> inline
interval<T, Policies> widen(const interval<T, Policies>& x, const T& v)
{
if (interval_lib::detail::test_input(x))
return interval<T, Policies>::empty();
typename Policies::rounding rnd;
return interval<T, Policies>(rnd.sub_down(x.lower(), v),
rnd.add_up (x.upper(), v), true);
}
/*
* Set-like operations
*/
template<class T, class Policies> inline
bool empty(const interval<T, Policies>& x)
{
return interval_lib::detail::test_input(x);
}
template<class T, class Policies> inline
bool zero_in(const interval<T, Policies>& x)
{
if (interval_lib::detail::test_input(x)) return false;
return (!interval_lib::user::is_pos(x.lower())) &&
(!interval_lib::user::is_neg(x.upper()));
}
template<class T, class Policies> inline
bool in_zero(const interval<T, Policies>& x) // DEPRECATED
{
return zero_in<T, Policies>(x);
}
template<class T, class Policies> inline
bool in(const T& x, const interval<T, Policies>& y)
{
if (interval_lib::detail::test_input(x, y)) return false;
return y.lower() <= x && x <= y.upper();
}
template<class T, class Policies> inline
bool subset(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
if (empty(x)) return true;
return !empty(y) && y.lower() <= x.lower() && x.upper() <= y.upper();
}
template<class T, class Policies1, class Policies2> inline
bool proper_subset(const interval<T, Policies1>& x,
const interval<T, Policies2>& y)
{
if (empty(y)) return false;
if (empty(x)) return true;
return y.lower() <= x.lower() && x.upper() <= y.upper() &&
(y.lower() != x.lower() || x.upper() != y.upper());
}
template<class T, class Policies1, class Policies2> inline
bool overlap(const interval<T, Policies1>& x,
const interval<T, Policies2>& y)
{
if (interval_lib::detail::test_input(x, y)) return false;
return (x.lower() <= y.lower() && y.lower() <= x.upper()) ||
(y.lower() <= x.lower() && x.lower() <= y.upper());
}
template<class T, class Policies> inline
bool singleton(const interval<T, Policies>& x)
{
return !empty(x) && x.lower() == x.upper();
}
template<class T, class Policies1, class Policies2> inline
bool equal(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
{
if (empty(x)) return empty(y);
return !empty(y) && x.lower() == y.lower() && x.upper() == y.upper();
}
template<class T, class Policies> inline
interval<T, Policies> intersect(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
if (interval_lib::detail::test_input(x, y))
return interval<T, Policies>::empty();
const T& l = max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower());
const T& u = min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper());
if (l <= u) return interval<T, Policies>(l, u, true);
else return interval<T, Policies>::empty();
}
template<class T, class Policies> inline
interval<T, Policies> hull(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input(x);
bool bad_y = interval_lib::detail::test_input(y);
if (bad_x)
if (bad_y) return interval<T, Policies>::empty();
else return y;
else
if (bad_y) return x;
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> hull(const interval<T, Policies>& x, const T& y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input(x);
bool bad_y = interval_lib::detail::test_input<T, Policies>(y);
if (bad_y)
if (bad_x) return interval<T, Policies>::empty();
else return x;
else
if (bad_x) return interval<T, Policies>(y, y, true);
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> hull(const T& x, const interval<T, Policies>& y)
{
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
bool bad_x = interval_lib::detail::test_input<T, Policies>(x);
bool bad_y = interval_lib::detail::test_input(y);
if (bad_x)
if (bad_y) return interval<T, Policies>::empty();
else return y;
else
if (bad_y) return interval<T, Policies>(x, x, true);
return interval<T, Policies>(min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()),
max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
}
template<class T> inline
interval<T> hull(const T& x, const T& y)
{
return interval<T>::hull(x, y);
}
template<class T, class Policies> inline
std::pair<interval<T, Policies>, interval<T, Policies> >
bisect(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return std::pair<I,I>(I::empty(), I::empty());
const T m = median(x);
return std::pair<I,I>(I(x.lower(), m, true), I(m, x.upper(), true));
}
/*
* Elementary functions
*/
template<class T, class Policies> inline
T norm(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x)) {
typedef typename Policies::checking checking;
return checking::nan();
}
BOOST_USING_STD_MAX();
return max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper());
}
template<class T, class Policies> inline
interval<T, Policies> abs(const interval<T, Policies>& x)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x))
return I::empty();
if (!interval_lib::user::is_neg(x.lower())) return x;
if (!interval_lib::user::is_pos(x.upper())) return -x;
BOOST_USING_STD_MAX();
return I(static_cast<T>(0), max BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x, const T& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> max BOOST_PREVENT_MACRO_SUBSTITUTION (const T& x, const interval<T, Policies>& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MAX();
return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true);
}
template<class T, class Policies> inline
interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION (const interval<T, Policies>& x, const T& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true);
}
template<class T, class Policies> inline
interval<T, Policies> min BOOST_PREVENT_MACRO_SUBSTITUTION (const T& x, const interval<T, Policies>& y)
{
typedef interval<T, Policies> I;
if (interval_lib::detail::test_input(x, y))
return I::empty();
BOOST_USING_STD_MIN();
return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true);
}
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_UTILITY_HPP

View File

@@ -0,0 +1,75 @@
/*
[auto_generated]
boost/numeric/odeint.hpp
[begin_description]
Forward include for odeint. Includes nearly everything.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_HPP_INCLUDED
#include <boost/numeric/odeint/version.hpp>
#include <boost/numeric/odeint/config.hpp>
// start with ublas wrapper because we need its specializations before including state_wrapper.hpp
#include <boost/numeric/odeint/util/ublas_wrapper.hpp>
#include <boost/numeric/odeint/stepper/euler.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
#include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
#include <boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp>
#include <boost/numeric/odeint/stepper/bulirsch_stoer.hpp>
#ifndef __CUDACC__
/* Bulirsch Stoer with Dense Output does not compile with nvcc
* because of the binomial library used there which relies on unsupported SSE functions
*/
#include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
#endif
#include <boost/numeric/odeint/stepper/symplectic_euler.hpp>
#include <boost/numeric/odeint/stepper/symplectic_rkn_sb3a_mclachlan.hpp>
#include <boost/numeric/odeint/stepper/adams_bashforth_moulton.hpp>
#include <boost/numeric/odeint/stepper/implicit_euler.hpp>
#include <boost/numeric/odeint/stepper/rosenbrock4.hpp>
#include <boost/numeric/odeint/stepper/rosenbrock4_controller.hpp>
#include <boost/numeric/odeint/stepper/rosenbrock4_dense_output.hpp>
/*
* Including this algebra slows down the compilation time
*/
// #include <boost/numeric/odeint/algebra/fusion_algebra.hpp>
#include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
#include <boost/numeric/odeint/integrate/integrate.hpp>
#include <boost/numeric/odeint/integrate/integrate_adaptive.hpp>
#include <boost/numeric/odeint/integrate/integrate_const.hpp>
#include <boost/numeric/odeint/integrate/integrate_n_steps.hpp>
#include <boost/numeric/odeint/integrate/integrate_times.hpp>
#include <boost/numeric/odeint/integrate/observer_collection.hpp>
#include <boost/numeric/odeint/stepper/generation.hpp>
#endif // BOOST_NUMERIC_ODEINT_HPP_INCLUDED

View File

@@ -0,0 +1,265 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/array_algebra.hpp
[begin_description]
Algebra for boost::array. Highly specialized for odeint. Const arguments are introduce to work with odeint.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
#include <boost/array.hpp>
namespace boost {
namespace numeric {
namespace odeint {
struct array_algebra
{
template< typename T , size_t dim , class Op >
static void for_each1( boost::array< T , dim > &s1 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] );
}
template< typename T1 , typename T2 , size_t dim , class Op >
static void for_each2( boost::array< T1 , dim > &s1 ,
const boost::array< T2 , dim > &s2 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] );
}
template< typename T , size_t dim , class Op >
static void for_each3( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] );
}
/* different const signature - required for the scale_sum_swap2 operation */
template< typename T , size_t dim , class Op >
static void for_each3( boost::array< T , dim > &s1 ,
boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] );
}
template< typename T , size_t dim , class Op >
static void for_each4( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] );
}
template< typename T , size_t dim , class Op >
static void for_each5( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] );
}
template< typename T , size_t dim , class Op >
static void for_each6( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] );
}
template< typename T , size_t dim , class Op >
static void for_each7( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] );
}
template< typename T , size_t dim , class Op >
static void for_each8( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] );
}
template< typename T , size_t dim , class Op >
static void for_each9( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] );
}
template< typename T , size_t dim , class Op >
static void for_each10( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 ,
const boost::array< T , dim > &s10 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] );
}
template< typename T , size_t dim , class Op >
static void for_each11( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 ,
const boost::array< T , dim > &s10 ,
const boost::array< T , dim > &s11 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] );
}
template< typename T , size_t dim , class Op >
static void for_each12( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 ,
const boost::array< T , dim > &s10 ,
const boost::array< T , dim > &s11 ,
const boost::array< T , dim > &s12 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] );
}
template< typename T , size_t dim , class Op >
static void for_each13( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 ,
const boost::array< T , dim > &s10 ,
const boost::array< T , dim > &s11 ,
const boost::array< T , dim > &s12 ,
const boost::array< T , dim > &s13 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] );
}
template< typename T , size_t dim , class Op >
static void for_each14( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 ,
const boost::array< T , dim > &s10 ,
const boost::array< T , dim > &s11 ,
const boost::array< T , dim > &s12 ,
const boost::array< T , dim > &s13 ,
const boost::array< T , dim > &s14 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] , s14[i] );
}
template< typename T , size_t dim , class Op >
static void for_each15( boost::array< T , dim > &s1 ,
const boost::array< T , dim > &s2 ,
const boost::array< T , dim > &s3 ,
const boost::array< T , dim > &s4 ,
const boost::array< T , dim > &s5 ,
const boost::array< T , dim > &s6 ,
const boost::array< T , dim > &s7 ,
const boost::array< T , dim > &s8 ,
const boost::array< T , dim > &s9 ,
const boost::array< T , dim > &s10 ,
const boost::array< T , dim > &s11 ,
const boost::array< T , dim > &s12 ,
const boost::array< T , dim > &s13 ,
const boost::array< T , dim > &s14 ,
const boost::array< T , dim > &s15 , Op op )
{
for( size_t i=0 ; i<dim ; ++i )
op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] , s14[i] , s15[i] );
}
template< class Value , class T , size_t dim , class Red >
static Value reduce( const boost::array< T , dim > &s , Red red , Value init)
{
for( size_t i=0 ; i<dim ; ++i )
init = red( init , s[i] );
return init;
}
};
}
}
}
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED

View File

@@ -0,0 +1,602 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/default_operations.hpp
[begin_description]
Default operations. They work with the default numerical types, like float, double, complex< double> ...
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_DEFAULT_OPERATIONS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_DEFAULT_OPERATIONS_HPP_INCLUDED
#include <algorithm>
#include <boost/config.hpp>
#include <boost/array.hpp>
#include <boost/numeric/odeint/util/unit_helper.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* Notes:
*
* * the results structs are needed in order to work with fusion_algebra
*/
struct default_operations
{
template< class Fac1 = double >
struct scale
{
const Fac1 m_alpha1;
scale( Fac1 alpha1 ) : m_alpha1( alpha1 ) { }
template< class T1 >
void operator()( T1 &t1 ) const
{
t1 *= m_alpha1;
}
typedef void result_type;
};
template< class Fac1 = double >
struct scale_sum1
{
const Fac1 m_alpha1;
scale_sum1( Fac1 alpha1 ) : m_alpha1( alpha1 ) { }
template< class T1 , class T2 >
void operator()( T1 &t1 , const T2 &t2 ) const
{
t1 = m_alpha1 * t2;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum2( Fac1 alpha1 , Fac2 alpha2 ) : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class T1 , class T2 , class T3 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 >
struct scale_sum3
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
scale_sum3( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) { }
template< class T1 , class T2 , class T3 , class T4 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 >
struct scale_sum4
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
scale_sum4( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 >
struct scale_sum5
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
scale_sum5( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 , Fac5 alpha5 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 >
struct scale_sum6
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
scale_sum6( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 , Fac5 alpha5 , Fac6 alpha6 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ){ }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 ,const T7 &t7) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 >
struct scale_sum7
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
scale_sum7( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 >
struct scale_sum8
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
scale_sum8( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 , class Fac9 = Fac8 >
struct scale_sum9
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
const Fac9 m_alpha9;
scale_sum9( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 , Fac9 alpha9 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) , m_alpha9( alpha9 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 , class T10 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 , const T10 &t10 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9 + m_alpha9 * t10;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 , class Fac9 = Fac8 , class Fac10 = Fac9 >
struct scale_sum10
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
const Fac9 m_alpha9;
const Fac10 m_alpha10;
scale_sum10( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 , Fac9 alpha9 , Fac10 alpha10 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) , m_alpha9( alpha9 ) , m_alpha10( alpha10 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 , class T10 , class T11 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 , const T10 &t10 , const T11 &t11 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9 + m_alpha9 * t10 + m_alpha10 * t11;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 , class Fac9 = Fac8 , class Fac10 = Fac9 , class Fac11 = Fac10 >
struct scale_sum11
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
const Fac9 m_alpha9;
const Fac10 m_alpha10;
const Fac11 m_alpha11;
scale_sum11( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 , Fac9 alpha9 ,
Fac10 alpha10 , Fac11 alpha11 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) , m_alpha9( alpha9 ) , m_alpha10( alpha10 ) , m_alpha11( alpha11 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 , class T10 , class T11 , class T12 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 , const T10 &t10 , const T11 &t11 , const T12 &t12 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9 + m_alpha9 * t10 + m_alpha10 * t11 + m_alpha11 * t12;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 , class Fac9 = Fac8 , class Fac10 = Fac9 , class Fac11 = Fac10 , class Fac12 = Fac11 >
struct scale_sum12
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
const Fac9 m_alpha9;
const Fac10 m_alpha10;
const Fac11 m_alpha11;
const Fac12 m_alpha12;
scale_sum12( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 , Fac9 alpha9 ,
Fac10 alpha10 , Fac11 alpha11 , Fac12 alpha12 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) , m_alpha9( alpha9 ) , m_alpha10( alpha10 ) , m_alpha11( alpha11 ) , m_alpha12( alpha12 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 , class T10 , class T11 , class T12 , class T13 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 , const T10 &t10 , const T11 &t11 , const T12 &t12 , const T13 &t13 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9 + m_alpha9 * t10 + m_alpha10 * t11 + m_alpha11 * t12 + m_alpha12 * t13;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 , class Fac9 = Fac8 , class Fac10 = Fac9 , class Fac11 = Fac10 , class Fac12 = Fac11 , class Fac13 = Fac12 >
struct scale_sum13
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
const Fac9 m_alpha9;
const Fac10 m_alpha10;
const Fac11 m_alpha11;
const Fac12 m_alpha12;
const Fac13 m_alpha13;
scale_sum13( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 , Fac9 alpha9 ,
Fac10 alpha10 , Fac11 alpha11 , Fac12 alpha12 , Fac13 alpha13 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) , m_alpha9( alpha9 ) , m_alpha10( alpha10 ) , m_alpha11( alpha11 ) , m_alpha12( alpha12 ) , m_alpha13( alpha13 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 , class T10 , class T11 , class T12 , class T13 , class T14 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 , const T10 &t10 , const T11 &t11 , const T12 &t12 , const T13 &t13 , const T14 &t14 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9 + m_alpha9 * t10 + m_alpha10 * t11 + m_alpha11 * t12 + m_alpha12 * t13 + m_alpha13 * t14;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 , class Fac8 = Fac7 , class Fac9 = Fac8 , class Fac10 = Fac9 , class Fac11 = Fac10 , class Fac12 = Fac11 , class Fac13 = Fac12 , class Fac14 = Fac13 >
struct scale_sum14
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
const Fac8 m_alpha8;
const Fac9 m_alpha9;
const Fac10 m_alpha10;
const Fac11 m_alpha11;
const Fac12 m_alpha12;
const Fac13 m_alpha13;
const Fac14 m_alpha14;
scale_sum14( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 ,
Fac5 alpha5 , Fac6 alpha6 , Fac7 alpha7 , Fac8 alpha8 , Fac9 alpha9 ,
Fac10 alpha10 , Fac11 alpha11 , Fac12 alpha12 , Fac13 alpha13 , Fac14 alpha14 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) , m_alpha8( alpha8 ) , m_alpha9( alpha9 ) , m_alpha10( alpha10 ) , m_alpha11( alpha11 ) , m_alpha12( alpha12 ) , m_alpha13( alpha13 ) , m_alpha14( alpha14 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 , class T8 , class T9 , class T10 , class T11 , class T12 , class T13 , class T14 , class T15 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 , const T7 &t7 , const T8 &t8 , const T9 &t9 , const T10 &t10 , const T11 &t11 , const T12 &t12 , const T13 &t13 , const T14 &t14 , const T15 &t15 ) const
{
t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6 + m_alpha6 * t7 + m_alpha7 * t8 + m_alpha8 * t9 + m_alpha9 * t10 + m_alpha10 * t11 + m_alpha11 * t12 + m_alpha12 * t13 + m_alpha13 * t14 + m_alpha14 * t15;
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum_swap2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum_swap2( Fac1 alpha1 , Fac2 alpha2 ) : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class T1 , class T2 , class T3 >
void operator()( T1 &t1 , T2 &t2 , const T3 &t3) const
{
const T1 tmp( t1 );
t1 = m_alpha1 * t2 + m_alpha2 * t3;
t2 = tmp;
}
typedef void result_type;
};
/*
* for usage in for_each2
*
* Works with boost::units by eliminating the unit
*/
template< class Fac1 = double >
struct rel_error
{
const Fac1 m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt;
rel_error( Fac1 eps_abs , Fac1 eps_rel , Fac1 a_x , Fac1 a_dxdt )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) { }
template< class T1 , class T2 , class T3 >
void operator()( T3 &t3 , const T1 &t1 , const T2 &t2 ) const
{
using std::abs;
set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );
}
typedef void result_type;
};
/*
* for usage in for_each3
*
* used in the controller for the rosenbrock4 method
*
* Works with boost::units by eliminating the unit
*/
template< class Fac1 = double >
struct default_rel_error
{
const Fac1 m_eps_abs , m_eps_rel ;
default_rel_error( Fac1 eps_abs , Fac1 eps_rel )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) { }
/*
* xerr = xerr / ( eps_abs + eps_rel * max( x , x_old ) )
*/
template< class T1 , class T2 , class T3 >
void operator()( T3 &t3 , const T1 &t1 , const T2 &t2 ) const
{
BOOST_USING_STD_MAX();
using std::abs;
Fac1 x1 = abs( get_unit_value( t1 ) ) , x2 = abs( get_unit_value( t2 ) );
set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * max BOOST_PREVENT_MACRO_SUBSTITUTION ( x1 , x2 ) ) );
}
typedef void result_type;
};
/*
* for usage in reduce
*/
template< class Value >
struct maximum
{
template< class Fac1 , class Fac2 >
Value operator()( Fac1 t1 , const Fac2 t2 ) const
{
using std::abs;
Value a1 = abs( get_unit_value( t1 ) ) , a2 = abs( get_unit_value( t2 ) );
return ( a1 < a2 ) ? a2 : a1 ;
}
typedef Value result_type;
};
template< class Fac1 = double >
struct rel_error_max
{
const Fac1 m_eps_abs , m_eps_rel;
rel_error_max( Fac1 eps_abs , Fac1 eps_rel )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel )
{ }
template< class Res , class T1 , class T2 , class T3 >
Res operator()( Res r , const T1 &x_old , const T2 &x , const T3 &x_err )
{
BOOST_USING_STD_MAX();
using std::abs;
Res tmp = abs( get_unit_value( x_err ) ) / ( m_eps_abs + m_eps_rel * max BOOST_PREVENT_MACRO_SUBSTITUTION ( abs( x_old ) , abs( x ) ) );
return max BOOST_PREVENT_MACRO_SUBSTITUTION ( r , tmp );
}
};
template< class Fac1 = double >
struct rel_error_max2
{
const Fac1 m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt;
rel_error_max2( Fac1 eps_abs , Fac1 eps_rel , Fac1 a_x , Fac1 a_dxdt )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt )
{ }
template< class Res , class T1 , class T2 , class T3 , class T4 >
Res operator()( Res r , const T1 &x_old , const T2 &x , const T3 &dxdt_old , const T4 &x_err )
{
BOOST_USING_STD_MAX();
using std::abs;
Res tmp = abs( get_unit_value( x_err ) ) /
( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( x_old ) ) + m_a_dxdt * abs( get_unit_value( dxdt_old ) ) ) );
return max BOOST_PREVENT_MACRO_SUBSTITUTION ( r , tmp );
}
};
template< class Fac1 = double >
struct rel_error_l2
{
const Fac1 m_eps_abs , m_eps_rel;
rel_error_l2( Fac1 eps_abs , Fac1 eps_rel )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel )
{ }
template< class Res , class T1 , class T2 , class T3 >
Res operator()( Res r , const T1 &x_old , const T2 &x , const T3 &x_err )
{
BOOST_USING_STD_MAX();
using std::abs;
Res tmp = abs( get_unit_value( x_err ) ) / ( m_eps_abs + m_eps_rel * max BOOST_PREVENT_MACRO_SUBSTITUTION ( abs( x_old ) , abs( x ) ) );
return r + tmp * tmp;
}
};
template< class Fac1 = double >
struct rel_error_l2_2
{
const Fac1 m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt;
rel_error_l2_2( Fac1 eps_abs , Fac1 eps_rel , Fac1 a_x , Fac1 a_dxdt )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt )
{ }
template< class Res , class T1 , class T2 , class T3 , class T4 >
Res operator()( Res r , const T1 &x_old , const T2 &x , const T3 &dxdt_old , const T4 &x_err )
{
using std::abs;
Res tmp = abs( get_unit_value( x_err ) ) /
( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( x_old ) ) + m_a_dxdt * abs( get_unit_value( dxdt_old ) ) ) );
return r + tmp * tmp;
}
};
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_DEFAULT_OPERATIONS_HPP_INCLUDED

View File

@@ -0,0 +1,165 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/detail/for_each.hpp
[begin_description]
Default for_each implementations.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_FOR_EACH_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_FOR_EACH_HPP_INCLUDED
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
template< class Iterator1 , class Operation >
inline void for_each1( Iterator1 first1 , Iterator1 last1 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ );
}
template< class Iterator1 , class Iterator2 , class Operation >
inline void for_each2( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Operation >
inline void for_each3( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3, Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Operation >
inline void for_each4( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3, Iterator4 first4, Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Operation >
inline void for_each5( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Operation >
inline void for_each6( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Operation >
inline void for_each7( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Operation >
inline void for_each8( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Operation >
inline void for_each9( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Iterator10 , class Operation >
inline void for_each10( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Iterator10 first10 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ , *first10++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Iterator10 , class Iterator11 , class Operation >
inline void for_each11( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Iterator10 first10 , Iterator11 first11 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ , *first10++ , *first11++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Iterator10 , class Iterator11 , class Iterator12 , class Operation >
inline void for_each12( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Iterator10 first10 , Iterator11 first11 , Iterator12 first12 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ , *first10++ , *first11++ , *first12++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Iterator10 , class Iterator11 , class Iterator12 , class Iterator13 , class Operation >
inline void for_each13( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Iterator10 first10 , Iterator11 first11 , Iterator12 first12 , Iterator13 first13 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ , *first10++ , *first11++ , *first12++ , *first13++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Iterator10 , class Iterator11 , class Iterator12 , class Iterator13 , class Iterator14 , class Operation >
inline void for_each14( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Iterator10 first10 , Iterator11 first11 , Iterator12 first12 , Iterator13 first13 ,
Iterator14 first14 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ , *first10++ , *first11++ , *first12++ , *first13++ , *first14++ );
}
template< class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Iterator5 , class Iterator6 , class Iterator7 , class Iterator8 , class Iterator9 , class Iterator10 , class Iterator11 , class Iterator12 , class Iterator13 , class Iterator14 , class Iterator15 , class Operation >
inline void for_each15( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3,
Iterator4 first4, Iterator5 first5, Iterator6 first6 , Iterator7 first7 , Iterator8 first8 ,
Iterator9 first9 , Iterator10 first10 , Iterator11 first11 , Iterator12 first12 , Iterator13 first13 ,
Iterator14 first14 , Iterator15 first15 , Operation op )
{
for( ; first1 != last1 ; )
op( *first1++ , *first2++ , *first3++ , *first4++ , *first5++ , *first6++ , *first7++ , *first8++ , *first9++ , *first10++ , *first11++ , *first12++ , *first13++ , *first14++ , *first15++ );
}
} // detail
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_FOR_EACH_HPP_INCLUDED

View File

@@ -0,0 +1,43 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/detail/macros.hpp
[begin_description]
Some macros for type checking.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_MACROS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_MACROS_HPP_INCLUDED
//type traits aren't working with nvcc
#ifndef __CUDACC__
#include <boost/type_traits.hpp>
#include <boost/static_assert.hpp>
#define BOOST_ODEINT_CHECK_CONTAINER_TYPE( Type1 , Type2 ) \
BOOST_STATIC_ASSERT(( boost::is_same< typename boost::remove_const< Type1 >::type , Type2 >::value ))
#else
//empty macro for nvcc
#define BOOST_ODEINT_CHECK_CONTAINER_TYPE( Type1 , Type2 )
#endif // __CUDACC__
/*
#define BOOST_ODEINT_CHECK_OPERATION_ARITY( Operation , Arity ) \
BOOST_STATIC_ASSERT(( boost::function_traits< Operation >::arity == Arity ))
*/
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_MACROS_HPP_INCLUDED

View File

@@ -0,0 +1,67 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/detail/reduce.hpp
[begin_description]
Default reduce implementation.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_REDUCE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_REDUCE_HPP_INCLUDED
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
template< class ValueType , class Iterator1 , class Reduction >
inline ValueType reduce( Iterator1 first1 , Iterator1 last1 , Reduction red, ValueType init)
{
for( ; first1 != last1 ; )
init = red( init , *first1++ );
return init;
}
template< class ValueType , class Iterator1 , class Iterator2 , class Reduction >
inline ValueType reduce2( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Reduction red, ValueType init)
{
for( ; first1 != last1 ; )
init = red( init , *first1++ , *first2++ );
return init;
}
template< class ValueType , class Iterator1 , class Iterator2 , class Iterator3 , class Reduction >
inline ValueType reduce3( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3 , Reduction red, ValueType init)
{
for( ; first1 != last1 ; )
init = red( init , *first1++ , *first2++ , *first3++ );
return init;
}
template< class ValueType , class Iterator1 , class Iterator2 , class Iterator3 , class Iterator4 , class Reduction >
inline ValueType reduce4( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Iterator3 first3 , Iterator4 first4 , Reduction red, ValueType init)
{
for( ; first1 != last1 ; )
init = red( init , *first1++ , *first2++ , *first3++ , *first4++ );
return init;
}
} // detail
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_REDUCE_HPP_INCLUDED

View File

@@ -0,0 +1,186 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/fusion_algebra.hpp
[begin_description]
Algebra for boost::fusion sequences.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/view/zip_view.hpp>
#include <boost/fusion/functional/generation/make_fused.hpp>
#include <boost/fusion/algorithm/iteration/accumulate.hpp>
namespace boost {
namespace numeric {
namespace odeint {
struct fusion_algebra
{
template< class S1 , class Op >
static void for_each1( S1 &s1 , Op op )
{
boost::fusion::for_each( s1 , op );
};
template< class S1 , class S2 , class Op >
static void for_each2( S1 &s1 , S2 &s2 , Op op )
{
typedef boost::fusion::vector< S1& , S2& > Sequences;
Sequences sequences( s1 , s2 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class Op >
static void for_each3( S1 &s1 , S2 &s2 , S3 &s3 , Op op )
{
typedef boost::fusion::vector< S1& , S2& , S3& > Sequences;
Sequences sequences( s1 , s2 , s3 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class Op >
static void for_each4( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , Op op )
{
typedef boost::fusion::vector< S1& , S2& , S3& , S4& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class Op >
static void for_each5( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , Op op )
{
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class Op >
static void for_each6( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , Op op )
{
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class Op >
static void for_each7( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , Op op )
{
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class Op >
static void for_each8( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 8 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class Op >
static void for_each9( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 9 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class Op >
static void for_each10( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 10 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class Op >
static void for_each11( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 11 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 11 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class Op >
static void for_each12( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 12 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 12 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class Op >
static void for_each13( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 13 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 13 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& , S13& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class Op >
static void for_each14( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 14 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 14 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& , S13& , S14& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 , s14 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class S15 , class Op >
static void for_each15( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , S15 &s15 , Op op )
{
BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 15 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 15 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" );
typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& , S13& , S14& , S15& > Sequences;
Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 , s14 , s15 );
boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) );
}
template< class Value , class S , class Reduction >
static Value reduce( const S &s , Reduction red , Value init)
{
return boost::fusion::accumulate( s , init , red );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED

View File

@@ -0,0 +1,159 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/range_algebra.hpp
[begin_description]
Default algebra, which works with the most state types, like vector< double >, boost::array< double >, boost::range.
Internally is uses boost::range to obtain the begin and end iterator of the according sequence.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_RANGE_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_RANGE_ALGEBRA_HPP_INCLUDED
#include <boost/range.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/numeric/odeint/algebra/detail/macros.hpp>
#include <boost/numeric/odeint/algebra/detail/for_each.hpp>
#include <boost/numeric/odeint/algebra/detail/reduce.hpp>
namespace boost {
namespace numeric {
namespace odeint {
struct range_algebra
{
template< class S1 , class Op >
static void for_each1( S1 &s1 , Op op )
{
detail::for_each1( boost::begin( s1 ) , boost::end( s1 ) ,
op );
}
template< class S1 , class S2 , class Op >
static void for_each2( S1 &s1 , S2 &s2 , Op op )
{
detail::for_each2( boost::begin( s1 ) , boost::end( s1 ) ,
boost::begin( s2 ) , op );
}
template< class S1 , class S2 , class S3 , class Op >
static void for_each3( S1 &s1 , S2 &s2 , S3 &s3 , Op op )
{
detail::for_each3( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class Op >
static void for_each4( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , Op op )
{
detail::for_each4( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class Op >
static void for_each5( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , Op op )
{
detail::for_each5( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class Op >
static void for_each6( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , Op op )
{
detail::for_each6( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class Op >
static void for_each7( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , Op op )
{
detail::for_each7( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class Op >
static void for_each8( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , Op op )
{
detail::for_each8( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class Op >
static void for_each9( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , Op op )
{
detail::for_each9( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class Op >
static void for_each10( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , Op op )
{
detail::for_each10( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , boost::begin( s10 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class Op >
static void for_each11( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , Op op )
{
detail::for_each11( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , boost::begin( s10 ) , boost::begin( s11 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class Op >
static void for_each12( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , Op op )
{
detail::for_each12( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , boost::begin( s10 ) , boost::begin( s11 ) , boost::begin( s12 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class Op >
static void for_each13( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , Op op )
{
detail::for_each13( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , boost::begin( s10 ) , boost::begin( s11 ) , boost::begin( s12 ) , boost::begin( s13 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class Op >
static void for_each14( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , Op op )
{
detail::for_each14( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , boost::begin( s10 ) , boost::begin( s11 ) , boost::begin( s12 ) , boost::begin( s13 ) , boost::begin( s14 ) , op );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class S15 , class Op >
static void for_each15( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , S15 &s15 , Op op )
{
detail::for_each15( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , boost::begin( s5 ) , boost::begin( s6 ) , boost::begin( s7 ) , boost::begin( s8 ) , boost::begin( s9 ) , boost::begin( s10 ) , boost::begin( s11 ) , boost::begin( s12 ) , boost::begin( s13 ) , boost::begin( s14 ) , boost::begin( s15 ) , op );
}
template< class Value , class S , class Red >
static Value reduce( const S &s , Red red , Value init)
{
return detail::reduce( boost::begin( s ) , boost::end( s ) , red , init );
}
template< class Value , class S1 , class S2 , class Red >
static Value reduce2( const S1 &s1 , const S2 &s2 , Red red , Value init )
{
return detail::reduce2( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , red , init );
}
template< class Value , class S1 , class S2 , class S3 , class Red >
static Value reduce3( const S1 &s1 , const S2 &s2 , const S3 &s3 , Red red , Value init )
{
return detail::reduce3( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , red , init );
}
template< class Value , class S1 , class S2 , class S3 , class S4 , class Red >
static Value reduce4( const S1 &s1 , const S2 &s2 , const S3 &s3 , const S4 &s4 , Red red , Value init )
{
return detail::reduce4( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) , boost::begin( s3 ) , boost::begin( s4 ) , red , init );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_RANGE_ALGEBRA_HPP_INCLUDED

View File

@@ -0,0 +1,156 @@
/*
[auto_generated]
boost/numeric/odeint/algebra/vector_space_algebra.hpp
[begin_description]
An algebra for types which have vector space semantics, hence types on which the operators +,-,* are well defined.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_VECTOR_SPACE_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_ALGEBRA_VECTOR_SPACE_ALGEBRA_HPP_INCLUDED
#include <boost/type_traits/remove_reference.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* This class template has to be overload in order to call vector_space_algebra::reduce
*/
template< class State > struct vector_space_reduce;
/*
* Example: instantiation for sole doubles
*/
template<>
struct vector_space_reduce< double >
{
template< class Op >
double operator()( double x , Op op , double init ) const
{
init = op( init , x );
return init;
}
};
struct vector_space_algebra
{
template< class S1 , class Op >
static void for_each1( S1 &s1 , Op op )
{
// ToDo : build checks, that the +-*/ operators are well defined
op( s1 );
}
template< class S1 , class S2 , class Op >
static void for_each2( S1 &s1 , S2 &s2 , Op op )
{
op( s1 , s2 );
}
template< class S1 , class S2 , class S3 , class Op >
static void for_each3( S1 &s1 , S2 &s2 , S3 &s3 , Op op )
{
op( s1 , s2 , s3 );
}
template< class S1 , class S2 , class S3 , class S4 , class Op >
static void for_each4( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , Op op )
{
op( s1 , s2 , s3 , s4 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class Op >
static void for_each5( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class Op >
static void for_each6( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class Op >
static void for_each7( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class Op >
static void for_each8( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class Op >
static void for_each9( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class Op >
static void for_each10( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class Op >
static void for_each11( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class Op >
static void for_each12( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class Op >
static void for_each13( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class Op >
static void for_each14( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 , s14 );
}
template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 ,class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class S15 , class Op >
static void for_each15( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , S15 &s15 , Op op )
{
op( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 , s14 , s15 );
}
template< class Value , class S , class Red >
static Value reduce( const S &s , Red red , Value init )
{
boost::numeric::odeint::vector_space_reduce< S > r;
return r( s , red , init );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_VECTOR_SPACE_ALGEBRA_HPP_INCLUDED

View File

@@ -0,0 +1,47 @@
/*
[auto_generated]
boost/numeric/odeint/config.hpp
[begin_description]
Sets configurations for odeint and used libraries. Should be included before any other odeint library
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_CONFIG_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_CONFIG_HPP_INCLUDED
//increase macro variable to allow rk78 scheme
#ifndef FUSION_MAX_VECTOR_SIZE
#define FUSION_MAX_VECTOR_SIZE 15
#endif
/*
* the following definitions are only required if fusion vectors are used as state types
* in the rk78 scheme
* they should be defined by the user if required, see e.g. libs/numeric/examples/harmonic_oscillator_units.cpp
*/
#ifndef BOOST_FUSION_INVOKE_MAX_ARITY
#define BOOST_FUSION_INVOKE_MAX_ARITY 15
#endif
#ifndef BOOST_RESULT_OF_NUM_ARGS
#define BOOST_RESULT_OF_NUM_ARGS 15
#endif
/*
*/
#include <boost/config.hpp>
#if __cplusplus >= 201103L
#define BOOST_NUMERIC_ODEINT_CXX11 1
#endif
#endif // BOOST_NUMERIC_ODEINT_CONFIG_HPP_INCLUDED

View File

@@ -0,0 +1,229 @@
/*
[auto_generated]
boost/numeric/odeint/external/gsl/gsl_wrapper.hpp
[begin_description]
Wrapper for gsl_vector.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_GSL_GSL_WRAPPER_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_GSL_GSL_WRAPPER_HPP_INCLUDED
#include <new>
#include <gsl/gsl_vector.h>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/range.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/numeric/odeint/util/state_wrapper.hpp>
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/copy.hpp>
class const_gsl_vector_iterator;
/*
* defines an iterator for gsl_vector
*/
class gsl_vector_iterator : public boost::iterator_facade< gsl_vector_iterator , double , boost::random_access_traversal_tag >
{
public :
gsl_vector_iterator( void ): m_p(0) , m_stride( 0 ) { }
explicit gsl_vector_iterator( gsl_vector *p ) : m_p( p->data ) , m_stride( p->stride ) { }
friend gsl_vector_iterator end_iterator( gsl_vector * );
private :
friend class boost::iterator_core_access;
friend class const_gsl_vector_iterator;
void increment( void ) { m_p += m_stride; }
void decrement( void ) { m_p -= m_stride; }
void advance( ptrdiff_t n ) { m_p += n*m_stride; }
bool equal( const gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
bool equal( const const_gsl_vector_iterator &other ) const;
double& dereference( void ) const { return *m_p; }
double *m_p;
size_t m_stride;
};
/*
* defines an const iterator for gsl_vector
*/
class const_gsl_vector_iterator : public boost::iterator_facade< const_gsl_vector_iterator , const double , boost::random_access_traversal_tag >
{
public :
const_gsl_vector_iterator( void ): m_p(0) , m_stride( 0 ) { }
explicit const_gsl_vector_iterator( const gsl_vector *p ) : m_p( p->data ) , m_stride( p->stride ) { }
const_gsl_vector_iterator( const gsl_vector_iterator &p ) : m_p( p.m_p ) , m_stride( p.m_stride ) { }
private :
friend class boost::iterator_core_access;
friend class gsl_vector_iterator;
friend const_gsl_vector_iterator end_iterator( const gsl_vector * );
void increment( void ) { m_p += m_stride; }
void decrement( void ) { m_p -= m_stride; }
void advance( ptrdiff_t n ) { m_p += n*m_stride; }
bool equal( const const_gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
bool equal( const gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
const double& dereference( void ) const { return *m_p; }
const double *m_p;
size_t m_stride;
};
bool gsl_vector_iterator::equal( const const_gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
gsl_vector_iterator end_iterator( gsl_vector *x )
{
gsl_vector_iterator iter( x );
iter.m_p += iter.m_stride * x->size;
return iter;
}
const_gsl_vector_iterator end_iterator( const gsl_vector *x )
{
const_gsl_vector_iterator iter( x );
iter.m_p += iter.m_stride * x->size;
return iter;
}
namespace boost
{
template<>
struct range_mutable_iterator< gsl_vector* >
{
typedef gsl_vector_iterator type;
};
template<>
struct range_const_iterator< gsl_vector* >
{
typedef const_gsl_vector_iterator type;
};
} // namespace boost
// template<>
inline gsl_vector_iterator range_begin( gsl_vector *x )
{
return gsl_vector_iterator( x );
}
// template<>
inline const_gsl_vector_iterator range_begin( const gsl_vector *x )
{
return const_gsl_vector_iterator( x );
}
// template<>
inline gsl_vector_iterator range_end( gsl_vector *x )
{
return end_iterator( x );
}
// template<>
inline const_gsl_vector_iterator range_end( const gsl_vector *x )
{
return end_iterator( x );
}
namespace boost {
namespace numeric {
namespace odeint {
template<>
struct is_resizeable< gsl_vector* >
{
//struct type : public boost::true_type { };
typedef boost::true_type type;
const static bool value = type::value;
};
template <>
struct same_size_impl< gsl_vector* , gsl_vector* >
{
static bool same_size( const gsl_vector* x , const gsl_vector* y )
{
return x->size == y->size;
}
};
template <>
struct resize_impl< gsl_vector* , gsl_vector* >
{
static void resize( gsl_vector* x , const gsl_vector* y )
{
gsl_vector_free( x );
x = gsl_vector_alloc( y->size );
}
};
template<>
struct state_wrapper< gsl_vector* >
{
typedef double value_type;
typedef gsl_vector* state_type;
typedef state_wrapper< gsl_vector* > state_wrapper_type;
state_type m_v;
state_wrapper( )
{
m_v = gsl_vector_alloc( 1 );
}
state_wrapper( const state_wrapper_type &x )
{
resize( m_v , x.m_v );
gsl_vector_memcpy( m_v , x.m_v );
}
~state_wrapper()
{
gsl_vector_free( m_v );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_GSL_GSL_WRAPPER_HPP_INCLUDED

View File

@@ -0,0 +1,181 @@
/*
[auto_generated]
boost/numeric/odeint/external/mkl/mkl_operations.hpp
[begin_description]
Wrapper classes for intel math kernel library types.
Get a free, non-commercial download of MKL at
http://software.intel.com/en-us/articles/non-commercial-software-download/
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MKL_MKL_OPERATIONS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MKL_MKL_OPERATIONS_HPP_INCLUDED
#include <iostream>
#include <mkl_cblas.h>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
/* exemplary example for writing bindings to the Intel MKL library
* see test/mkl for how to use mkl with odeint
* this is a quick and dirty implementation showing the general possibility.
* It works only with containers based on double and sequential memory allocation.
*/
namespace boost {
namespace numeric {
namespace odeint {
/* only defined for doubles */
struct mkl_operations
{
//template< class Fac1 , class Fac2 > struct scale_sum2;
template< class F1 = double , class F2 = F1 >
struct scale_sum2
{
typedef double Fac1;
typedef double Fac2;
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum2( const Fac1 alpha1 , const Fac2 alpha2 ) : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class T1 , class T2 , class T3 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3) const
{ // t1 = m_alpha1 * t2 + m_alpha2 * t3;
// we get Containers that have size() and [i]-access
const int n = t1.size();
//boost::numeric::odeint::copy( t1 , t3 );
if( &(t2[0]) != &(t1[0]) )
{
cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
}
cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
//daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
}
};
template< class F1 = double , class F2 = F1 , class F3 = F2 >
struct scale_sum3
{
typedef double Fac1;
typedef double Fac2;
typedef double Fac3;
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
scale_sum3( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) { }
template< class T1 , class T2 , class T3 , class T4 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 ) const
{ // t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4;
// we get Containers that have size() and [i]-access
const int n = t1.size();
//boost::numeric::odeint::copy( t1 , t3 );
if( &(t2[0]) != &(t1[0]) )
{
cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
}
cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
//daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
cblas_daxpy( n , m_alpha3 , &(t4[0]) , 1 , &(t1[0]) , 1 );
}
};
template< class F1 = double , class F2 = F1 , class F3 = F2 , class F4 = F3 >
struct scale_sum4
{
typedef double Fac1;
typedef double Fac2;
typedef double Fac3;
typedef double Fac4;
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
scale_sum4( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 , const Fac4 alpha4 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 ) const
{ // t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5;
// we get Containers that have size() and [i]-access
const int n = t1.size();
//boost::numeric::odeint::copy( t1 , t3 );
if( &(t2[0]) != &(t1[0]) )
{
cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
}
cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
//daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
cblas_daxpy( n , m_alpha3 , &(t4[0]) , 1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha4 , &(t5[0]) , 1 , &(t1[0]) , 1 );
}
};
template< class F1 = double , class F2 = F1 , class F3 = F2 , class F4 = F3 , class F5 = F4 >
struct scale_sum5
{
typedef double Fac1;
typedef double Fac2;
typedef double Fac3;
typedef double Fac4;
typedef double Fac5;
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
scale_sum5( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 , const Fac4 alpha4 , const Fac5 alpha5 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 ) const
{ // t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6;
// we get Containers that have size() and [i]-access
const int n = t1.size();
//boost::numeric::odeint::copy( t1 , t3 );
if( &(t2[0]) != &(t1[0]) )
{
cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
}
cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
//daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
cblas_daxpy( n , m_alpha3 , &(t4[0]) , 1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha4 , &(t5[0]) , 1 , &(t1[0]) , 1 );
cblas_daxpy( n , m_alpha5 , &(t6[0]) , 1 , &(t1[0]) , 1 );
}
};
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_MKL_MKL_OPERATIONS_HPP_INCLUDED

View File

@@ -0,0 +1,162 @@
/*
[begin_description]
Modification of the implicit Euler method, works with the MTL4 matrix library only.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Copyright 2012 Andreas Angelopoulos
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_IMPLICIT_EULER_MTL4_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_IMPLICIT_EULER_MTL4_HPP_INCLUDED
#include <utility>
#include <boost/numeric/odeint/util/bind.hpp>
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/external/mtl4/mtl4_resize.hpp>
#include <boost/numeric/mtl/mtl.hpp>
#include <boost/numeric/itl/itl.hpp>
namespace boost {
namespace numeric {
namespace odeint {
template< class ValueType , class Resizer = initially_resizer >
class implicit_euler_mtl4
{
public:
typedef ValueType value_type;
typedef value_type time_type;
typedef mtl::dense_vector<value_type> state_type;
typedef state_wrapper< state_type > wrapped_state_type;
typedef state_type deriv_type;
typedef state_wrapper< deriv_type > wrapped_deriv_type;
typedef mtl::compressed2D< value_type > matrix_type;
typedef state_wrapper< matrix_type > wrapped_matrix_type;
typedef Resizer resizer_type;
typedef stepper_tag stepper_category;
typedef implicit_euler_mtl4< ValueType , Resizer > stepper_type;
implicit_euler_mtl4( const value_type epsilon = 1E-6 )
: m_epsilon( epsilon ) , m_resizer() ,
m_dxdt() , m_x() ,
m_identity() , m_jacobi()
{ }
template< class System >
void do_step( System system , state_type &x , time_type t , time_type dt )
{
typedef typename odeint::unwrap_reference< System >::type system_type;
typedef typename odeint::unwrap_reference< typename system_type::first_type >::type deriv_func_type;
typedef typename odeint::unwrap_reference< typename system_type::second_type >::type jacobi_func_type;
system_type &sys = system;
deriv_func_type &deriv_func = sys.first;
jacobi_func_type &jacobi_func = sys.second;
m_resizer.adjust_size( x , detail::bind(
&stepper_type::template resize_impl< state_type > , detail::ref( *this ) , detail::_1 ) );
m_identity.m_v = 1;
t += dt;
m_x.m_v = x;
deriv_func( x , m_dxdt.m_v , t );
jacobi_func( x , m_jacobi.m_v , t );
m_dxdt.m_v *= -dt;
m_jacobi.m_v *= dt;
m_jacobi.m_v -= m_identity.m_v ;
// using ilu_0 preconditioning -incomplete LU factorisation
// itl::pc::diagonal<matrix_type,double> L(m_jacobi.m_v);
itl::pc::ilu_0<matrix_type> L( m_jacobi.m_v );
solve( m_jacobi.m_v , m_x.m_v , m_dxdt.m_v , L );
x+= m_x.m_v;
}
template< class StateType >
void adjust_size( const StateType &x )
{
resize_impl( x );
}
private:
/*
Applying approximate iterative linear solvers
default solver is Biconjugate gradient stabilized method
itl::bicgstab(A, x, b, L, iter);
*/
template < class LinearOperator, class HilbertSpaceX, class HilbertSpaceB, class Preconditioner>
void solve(const LinearOperator& A, HilbertSpaceX& x, const HilbertSpaceB& b,
const Preconditioner& L, int max_iteractions =500)
{
// Termination criterion: r < 1e-6 * b or N iterations
itl::basic_iteration< double > iter( b , max_iteractions , 1e-6 );
itl::bicgstab( A , x , b , L , iter );
}
template< class StateIn >
bool resize_impl( const StateIn &x )
{
bool resized = false;
resized |= adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() );
resized |= adjust_size_by_resizeability( m_x , x , typename is_resizeable<state_type>::type() );
resized |= adjust_size_by_resizeability( m_identity , x , typename is_resizeable<matrix_type>::type() );
resized |= adjust_size_by_resizeability( m_jacobi , x , typename is_resizeable<matrix_type>::type() );
return resized;
}
private:
value_type m_epsilon;
resizer_type m_resizer;
wrapped_deriv_type m_dxdt;
wrapped_state_type m_x;
wrapped_matrix_type m_identity;
wrapped_matrix_type m_jacobi;
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_IMPLICIT_EULER_MTL4_HPP_INCLUDED

View File

@@ -0,0 +1,133 @@
/*
[begin_description]
Modification of the implicit Euler method, works with the MTL4 matrix library only.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Copyright 2012 Andreas Angelopoulos
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MTL4_RESIZE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MTL4_RESIZE_HPP_INCLUDED
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/resize.hpp>
#include <boost/numeric/odeint/util/same_size.hpp>
#include <boost/numeric/mtl/vector/dense_vector.hpp>
#include <boost/numeric/mtl/matrix/dense2D.hpp>
#include <boost/numeric/mtl/matrix/compressed2D.hpp>
namespace boost {
namespace numeric {
namespace odeint {
template< class Value , class Parameters >
struct is_resizeable< mtl::dense_vector< Value , Parameters > >
{
typedef boost::true_type type;
const static bool value = type::value;
};
template< class Value , class Parameters >
struct is_resizeable< mtl::dense2D< Value , Parameters > >
{
typedef boost::true_type type;
const static bool value = type::value;
};
template< class Value , class Parameters >
struct is_resizeable< mtl::compressed2D< Value , Parameters > >
{
typedef boost::true_type type;
const static bool value = type::value;
};
template< class Value , class Parameters >
struct same_size_impl< mtl::dense_vector< Value , Parameters > , mtl::dense_vector< Value , Parameters > >
{
static bool same_size( const mtl::dense_vector< Value , Parameters > &v1 ,
const mtl::dense_vector< Value , Parameters > &v2 )
{
return mtl::size( v1 ) == mtl::size( v2 );
}
};
template< class Value , class Parameters >
struct resize_impl< mtl::dense_vector< Value , Parameters > , mtl::dense_vector< Value , Parameters > >
{
static void resize( mtl::dense_vector< Value , Parameters > &v1 ,
const mtl::dense_vector< Value , Parameters > &v2 )
{
v1.change_dim( mtl::size( v2 ) );
}
};
template< class Value , class MatrixParameters , class VectorParameters >
struct same_size_impl< mtl::dense2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > >
{
static bool same_size( const mtl::dense2D< Value , MatrixParameters > &m ,
const mtl::dense_vector< Value , VectorParameters > &v )
{
return ( ( mtl::size( v ) == m.num_cols() ) && ( mtl::size( v ) == m.num_rows() ) );
}
};
template< class Value , class MatrixParameters , class VectorParameters >
struct resize_impl< mtl::dense2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > >
{
static void resize( mtl::dense2D< Value , MatrixParameters > &m ,
const mtl::dense_vector< Value , VectorParameters > &v )
{
m.change_dim( mtl::size( v ) , mtl::size( v ) , false );
}
};
template< class Value , class MatrixParameters , class VectorParameters >
struct same_size_impl< mtl::compressed2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > >
{
static bool same_size( const mtl::compressed2D< Value , MatrixParameters > &m ,
const mtl::dense_vector< Value , VectorParameters > &v )
{
return ( ( mtl::size( v ) == m.num_cols() ) && ( mtl::size( v ) == m.num_rows() ) );
}
};
template< class Value , class MatrixParameters , class VectorParameters >
struct resize_impl< mtl::compressed2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > >
{
static void resize( mtl::compressed2D< Value , MatrixParameters > &m ,
const mtl::dense_vector< Value , VectorParameters > &v )
{
m.change_dim( mtl::size( v ) , mtl::size( v ) );
}
};
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_MTL4_RESIZE_HPP_INCLUDED

View File

@@ -0,0 +1,198 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_algebra.hpp
[begin_description]
An algebra for thrusts device_vectors.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
#include <thrust/device_vector.h>
#include <thrust/for_each.h>
#include <thrust/iterator/zip_iterator.h>
#include <boost/range.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/** ToDO extend until for_each14 for rk78 */
/*
* The const versions are needed for boost.range to work, i.e.
* it allows you to do
* for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op );
*/
struct thrust_algebra
{
template< class StateType , class Operation >
static void for_each1( StateType &s , Operation op )
{
thrust::for_each( boost::begin(s) , boost::begin(s) , op );
}
template< class StateType1 , class StateType2 , class Operation >
static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class Operation >
static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
class Operation >
static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 ,
class StateType4 , class StateType5 ,class Operation >
static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 ,
class StateType4 , class StateType5 , class StateType6 , class Operation >
static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , StateType6 &s6 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ,
boost::begin(s6) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ,
boost::end(s6) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
class StateType5 , class StateType6 , class StateType7 , class Operation >
static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ,
boost::begin(s6) ,
boost::begin(s7) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ,
boost::end(s6) ,
boost::end(s7) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation >
static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ,
boost::begin(s6) ,
boost::begin(s7) ,
boost::begin(s8) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ,
boost::end(s6) ,
boost::end(s7) ,
boost::end(s8) ) ) ,
op);
}
template< class Value , class S , class Red >
Value reduce( const S &s , Red red , Value init)
{
return thrust::reduce( boost::begin( s ) , boost::end( s ) , init , red );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED

View File

@@ -0,0 +1,252 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_operations.hpp
[begin_description]
Operations of thrust zipped iterators. Is the counterpart of the thrust_algebra.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_HPP_INCLUDED
namespace boost {
namespace numeric {
namespace odeint {
#include <thrust/tuple.h>
#include <thrust/iterator/zip_iterator.h>
/**ToDo extend to scale_sum13 for rk78 */
struct thrust_operations
{
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum2( const Fac1 alpha1 , const Fac2 alpha2 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) + m_alpha2 * thrust::get<2>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum_swap2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum_swap2( const Fac1 alpha1 , const Fac2 alpha2 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
typename thrust::tuple_element<0,Tuple>::type tmp = thrust::get<0>(t);
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) + m_alpha2 * thrust::get<2>(t);
thrust::get<1>(t) = tmp;
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 >
struct scale_sum3
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
scale_sum3( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 >
struct scale_sum4
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
scale_sum4( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 , const Fac4 alpha4 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ){ }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 ,
class Fac4 = Fac3 , class Fac5 = Fac4 >
struct scale_sum5
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
scale_sum5( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 ,
const Fac4 alpha4 , const Fac5 alpha5 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) ,
m_alpha4( alpha4 ) , m_alpha5( alpha5 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t) +
m_alpha5 * thrust::get<5>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 ,
class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 >
struct scale_sum6
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
scale_sum6( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 ,
const Fac4 alpha4 , const Fac5 alpha5 , const Fac6 alpha6 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) ,
m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t) +
m_alpha5 * thrust::get<5>(t) +
m_alpha6 * thrust::get<6>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 ,
class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 >
struct scale_sum7
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
scale_sum7( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 ,
const Fac4 alpha4 , const Fac5 alpha5 , const Fac6 alpha6 , const Fac7 alpha7 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) ,
m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t) +
m_alpha5 * thrust::get<5>(t) +
m_alpha6 * thrust::get<6>(t) +
m_alpha7 * thrust::get<7>(t) ;
}
};
template< class Fac1 = double >
struct rel_error
{
const Fac1 m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt;
rel_error( const Fac1 eps_abs , const Fac1 eps_rel , const Fac1 a_x , const Fac1 a_dxdt )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
using std::abs;
thrust::get< 0 >( t ) = abs( thrust::get< 0 >( t ) ) /
( m_eps_abs + m_eps_rel * ( m_a_x * abs( thrust::get< 1 >( t ) + m_a_dxdt * abs( thrust::get< 2 >( t ) ) ) ) );
}
typedef void result_type;
};
/*
* for usage in reduce
*/
template< class Value >
struct maximum
{
template< class Fac1 , class Fac2 >
__host__ __device__
Value operator()( const Fac1 t1 , const Fac2 t2 ) const
{
using std::max;
return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ;
}
typedef Value result_type;
};
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_HPP_INCLUDED

View File

@@ -0,0 +1,119 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_resize.hpp
[begin_description]
Enable resizing for thrusts device and host_vector.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <boost/numeric/odeint/util/copy.hpp>
namespace boost {
namespace numeric {
namespace odeint {
template< class T >
struct is_resizeable< thrust::device_vector< T > >
{
struct type : public boost::true_type { };
const static bool value = type::value;
};
template< class T >
struct same_size_impl< thrust::device_vector< T > , thrust::device_vector< T > >
{
static bool same_size( const thrust::device_vector< T > &x , const thrust::device_vector< T > &y )
{
return x.size() == y.size();
}
};
template< class T >
struct resize_impl< thrust::device_vector< T > , thrust::device_vector< T > >
{
static void resize( thrust::device_vector< T > &x , const thrust::device_vector< T > &y )
{
x.resize( y.size() );
}
};
template< class T >
struct is_resizeable< thrust::host_vector< T > >
{
struct type : public boost::true_type { };
const static bool value = type::value;
};
template< class T >
struct same_size_impl< thrust::host_vector< T > , thrust::host_vector< T > >
{
static bool same_size( const thrust::host_vector< T > &x , const thrust::host_vector< T > &y )
{
return x.size() == y.size();
}
};
template< class T >
struct resize_impl< thrust::host_vector< T > , thrust::host_vector< T > >
{
static void resize( thrust::host_vector< T > &x , const thrust::host_vector< T > &y )
{
x.resize( y.size() );
}
};
template< class Container1, class Value >
struct copy_impl< Container1 , thrust::device_vector< Value > >
{
static void copy( const Container1 &from , thrust::device_vector< Value > &to )
{
thrust::copy( boost::begin( from ) , boost::end( from ) , boost::begin( to ) );
}
};
template< class Value , class Container2 >
struct copy_impl< thrust::device_vector< Value > , Container2 >
{
static void copy( const thrust::device_vector< Value > &from , Container2 &to )
{
thrust::copy( boost::begin( from ) , boost::end( from ) , boost::begin( to ) );
}
};
template< class Value >
struct copy_impl< thrust::device_vector< Value > , thrust::device_vector< Value > >
{
static void copy( const thrust::device_vector< Value > &from , thrust::device_vector< Value > &to )
{
thrust::copy( boost::begin( from ) , boost::end( from ) , boost::begin( to ) );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED

View File

@@ -0,0 +1,92 @@
/*
[auto_generated]
boost/numeric/odeint/external/vexcl/vexcl_resize.hpp
[begin_description]
Enable resizing for vexcl vector and multivector.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_VEXCL_VEXCL_RESIZE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_VEXCL_VEXCL_RESIZE_HPP_INCLUDED
#include <vexcl/vector.hpp>
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/resize.hpp>
#include <boost/numeric/odeint/util/same_size.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* specializations for vex::vector< T >
*/
template< typename T >
struct is_resizeable< vex::vector< T > > : boost::true_type { };
template< typename T >
struct resize_impl< vex::vector< T > , vex::vector< T > >
{
static void resize( vex::vector< T > &x1 , const vex::vector< T > &x2 )
{
x1.resize( x2.queue_list() , x2.size() );
}
};
template< typename T >
struct same_size_impl< vex::vector< T > , vex::vector< T > >
{
static bool same_size( const vex::vector< T > &x1 , const vex::vector< T > &x2 )
{
return x1.size() == x2.size();
}
};
/*
* specializations for vex::multivector< T >
*/
template< typename T , uint N >
struct is_resizeable< vex::multivector< T , N > > : boost::true_type { };
template< typename T , uint N >
struct resize_impl< vex::multivector< T , N > , vex::multivector< T , N > >
{
static void resize( vex::multivector< T , N > &x1 , const vex::multivector< T , N > &x2 )
{
x1.resize( x2.queue_list() , x2.size() );
}
};
template< typename T , uint N >
struct same_size_impl< vex::multivector< T , N > , vex::multivector< T , N > >
{
static bool same_size( const vex::multivector< T , N > &x1 , const vex::multivector< T , N > &x2 )
{
return x1.size() == x2.size();
}
};
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_VEXCL_VEXCL_RESIZE_HPP_INCLUDED

View File

@@ -0,0 +1,245 @@
/*
[auto_generated]
boost/numeric/odeint/external/viennacl_operations.hpp
[begin_description]
ViennaCL operations.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_VIENNACL_VIENNACL_OPERATIONS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_VIENNACL_VIENNACL_OPERATIONS_HPP_INCLUDED
#include <viennacl/vector.hpp>
#include <viennacl/generator/custom_operation.hpp>
namespace boost {
namespace numeric {
namespace odeint {
struct viennacl_operations
{
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum2( Fac1 alpha1 , Fac2 alpha2 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 )
{ }
template< class T1 , class T2 , class T3 >
void operator()( viennacl::vector<T1> &v1 ,
const viennacl::vector<T2> &v2 ,
const viennacl::vector<T3> &v3
) const
{
using namespace viennacl;
static generator::symbolic_vector <0, T1> sym_v1;
static generator::symbolic_vector <1, T2> sym_v2;
static generator::symbolic_vector <2, T3> sym_v3;
static generator::cpu_symbolic_scalar<3, Fac1> sym_a1;
static generator::cpu_symbolic_scalar<4, Fac2> sym_a2;
static generator::custom_operation op(
sym_v1 = sym_a1 * sym_v2
+ sym_a2 * sym_v3
);
ocl::enqueue( op(v1,
const_cast< viennacl::vector<T2>& >(v2),
const_cast< viennacl::vector<T3>& >(v3),
const_cast< Fac1& >(m_alpha1),
const_cast< Fac2& >(m_alpha2)
) );
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 >
struct scale_sum3
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
scale_sum3( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 )
{ }
template< class T1 , class T2 , class T3 , class T4 >
void operator()( viennacl::vector<T1> &v1 ,
const viennacl::vector<T2> &v2 ,
const viennacl::vector<T3> &v3 ,
const viennacl::vector<T4> &v4
) const
{
using namespace viennacl;
static generator::symbolic_vector <0, T1> sym_v1;
static generator::symbolic_vector <1, T2> sym_v2;
static generator::symbolic_vector <2, T3> sym_v3;
static generator::symbolic_vector <3, T4> sym_v4;
static generator::cpu_symbolic_scalar<4, Fac1> sym_a1;
static generator::cpu_symbolic_scalar<5, Fac2> sym_a2;
static generator::cpu_symbolic_scalar<6, Fac3> sym_a3;
static generator::custom_operation op(
sym_v1 = sym_a1 * sym_v2
+ sym_a2 * sym_v3
+ sym_a3 * sym_v4
);
ocl::enqueue( op(v1,
const_cast< viennacl::vector<T2>& >(v2),
const_cast< viennacl::vector<T3>& >(v3),
const_cast< viennacl::vector<T4>& >(v4),
const_cast< Fac1& >(m_alpha1),
const_cast< Fac2& >(m_alpha2),
const_cast< Fac3& >(m_alpha3)
) );
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 >
struct scale_sum4
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
scale_sum4( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 >
void operator()( viennacl::vector<T1> &v1 ,
const viennacl::vector<T2> &v2 ,
const viennacl::vector<T3> &v3 ,
const viennacl::vector<T4> &v4 ,
const viennacl::vector<T5> &v5
) const
{
using namespace viennacl;
static generator::symbolic_vector <0, T1> sym_v1;
static generator::symbolic_vector <1, T2> sym_v2;
static generator::symbolic_vector <2, T3> sym_v3;
static generator::symbolic_vector <3, T4> sym_v4;
static generator::symbolic_vector <4, T5> sym_v5;
static generator::cpu_symbolic_scalar<5, Fac1> sym_a1;
static generator::cpu_symbolic_scalar<6, Fac2> sym_a2;
static generator::cpu_symbolic_scalar<7, Fac3> sym_a3;
static generator::cpu_symbolic_scalar<8, Fac4> sym_a4;
static generator::custom_operation op(
sym_v1 = sym_a1 * sym_v2
+ sym_a2 * sym_v3
+ sym_a3 * sym_v4
+ sym_a4 * sym_v5
);
ocl::enqueue( op(v1,
const_cast< viennacl::vector<T2>& >(v2),
const_cast< viennacl::vector<T3>& >(v3),
const_cast< viennacl::vector<T4>& >(v4),
const_cast< viennacl::vector<T5>& >(v5),
const_cast< Fac1& >(m_alpha1),
const_cast< Fac2& >(m_alpha2),
const_cast< Fac3& >(m_alpha3),
const_cast< Fac4& >(m_alpha4)
) );
}
typedef void result_type;
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 , class Fac5 = Fac4 >
struct scale_sum5
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
scale_sum5( Fac1 alpha1 , Fac2 alpha2 , Fac3 alpha3 , Fac4 alpha4 , Fac5 alpha5 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) { }
template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
void operator()( viennacl::vector<T1> &v1 ,
const viennacl::vector<T2> &v2 ,
const viennacl::vector<T3> &v3 ,
const viennacl::vector<T4> &v4 ,
const viennacl::vector<T5> &v5 ,
const viennacl::vector<T6> &v6
) const
{
using namespace viennacl;
static generator::symbolic_vector < 0, T1> sym_v1;
static generator::symbolic_vector < 1, T2> sym_v2;
static generator::symbolic_vector < 2, T3> sym_v3;
static generator::symbolic_vector < 3, T4> sym_v4;
static generator::symbolic_vector < 4, T5> sym_v5;
static generator::symbolic_vector < 5, T6> sym_v6;
static generator::cpu_symbolic_scalar< 6, Fac1> sym_a1;
static generator::cpu_symbolic_scalar< 7, Fac2> sym_a2;
static generator::cpu_symbolic_scalar< 8, Fac3> sym_a3;
static generator::cpu_symbolic_scalar< 9, Fac4> sym_a4;
static generator::cpu_symbolic_scalar<10, Fac5> sym_a5;
static generator::custom_operation op(
sym_v1 = sym_a1 * sym_v2
+ sym_a2 * sym_v3
+ sym_a3 * sym_v4
+ sym_a4 * sym_v5
+ sym_a5 * sym_v6
);
ocl::enqueue( op(v1,
const_cast< viennacl::vector<T2>& >(v2),
const_cast< viennacl::vector<T3>& >(v3),
const_cast< viennacl::vector<T4>& >(v4),
const_cast< viennacl::vector<T5>& >(v5),
const_cast< viennacl::vector<T6>& >(v6),
const_cast< Fac1& >(m_alpha1),
const_cast< Fac2& >(m_alpha2),
const_cast< Fac3& >(m_alpha3),
const_cast< Fac4& >(m_alpha4),
const_cast< Fac5& >(m_alpha5)
) );
}
typedef void result_type;
};
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_VIENNACL_VIENNACL_OPERATIONS_HPP_INCLUDED

View File

@@ -0,0 +1,65 @@
/*
[auto_generated]
boost/numeric/odeint/external/viennacl/viennacl_resize.hpp
[begin_description]
Enable resizing for viennacl vector.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_VIENNACL_VIENNACL_RESIZE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_VIENNACL_VIENNACL_RESIZE_HPP_INCLUDED
#include <viennacl/vector.hpp>
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/resize.hpp>
#include <boost/numeric/odeint/util/same_size.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* specializations for viennacl::vector< T >
*/
template< typename T >
struct is_resizeable< viennacl::vector< T > > : boost::true_type { };
template< typename T >
struct resize_impl< viennacl::vector< T > , viennacl::vector< T > >
{
static void resize( viennacl::vector< T > &x1 , const viennacl::vector< T > &x2 )
{
x1.resize( x2.size() , false );
}
};
template< typename T >
struct same_size_impl< viennacl::vector< T > , viennacl::vector< T > >
{
static bool same_size( const viennacl::vector< T > &x1 , const viennacl::vector< T > &x2 )
{
return x1.size() == x2.size();
}
};
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_VIENNACL_VIENNACL_RESIZE_HPP_INCLUDED

View File

@@ -0,0 +1,154 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp
[begin_description]
Default Integrate adaptive implementation.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
#include <stdexcept>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp>
#include <boost/numeric/odeint/util/bind.hpp>
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/util/copy.hpp>
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
#include <iostream>
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
// forward declaration
template< class Stepper , class System , class State , class Time , class Observer>
Time integrate_n_steps(
Stepper stepper , System system , State &start_state ,
Time start_time , Time dt , size_t num_of_steps ,
Observer observer , stepper_tag );
/*
* integrate_adaptive for simple stepper is basically an integrate_const + some last step
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer , stepper_tag
)
{
size_t steps = static_cast< size_t >( (end_time-start_time)/dt );
Time end = detail::integrate_n_steps( stepper , system , start_state , start_time ,
dt , steps , observer , stepper_tag() );
if( less_with_sign( end , end_time , dt ) )
{ //make a last step to end exactly at end_time
stepper.do_step( system , start_state , end , end_time - end );
steps++;
typename odeint::unwrap_reference< Observer >::type &obs = observer;
obs( start_state , end_time );
}
return steps;
}
/*
* classical integrate adaptive
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time &start_time , Time end_time , Time &dt ,
Observer observer , controlled_stepper_tag
)
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
const size_t max_attempts = 1000;
const char *error_string = "Integrate adaptive : Maximal number of iterations reached. A step size could not be found.";
size_t count = 0;
while( less_with_sign( start_time , end_time , dt ) )
{
obs( start_state , start_time );
if( less_with_sign( end_time , start_time + dt , dt ) )
{
dt = end_time - start_time;
}
size_t trials = 0;
controlled_step_result res = success;
do
{
res = stepper.try_step( system , start_state , start_time , dt );
++trials;
}
while( ( res == fail ) && ( trials < max_attempts ) );
if( trials == max_attempts ) throw std::overflow_error( error_string );
++count;
}
obs( start_state , start_time );
return count;
}
/*
* integrate adaptive for dense output steppers
*
* step size control is used if the stepper supports it
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer , dense_output_stepper_tag )
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
size_t count = 0;
stepper.initialize( start_state , start_time , dt );
while( less_with_sign( stepper.current_time() , end_time , stepper.current_time_step() ) )
{
while( less_eq_with_sign( stepper.current_time() + stepper.current_time_step() ,
end_time ,
stepper.current_time_step() ) )
{ //make sure we don't go beyond the end_time
obs( stepper.current_state() , stepper.current_time() );
stepper.do_step( system );
++count;
}
stepper.initialize( stepper.current_state() , stepper.current_time() , end_time - stepper.current_time() );
}
obs( stepper.current_state() , stepper.current_time() );
// overwrite start_state with the final point
boost::numeric::odeint::copy( stepper.current_state() , start_state );
return count;
}
} // namespace detail
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED

View File

@@ -0,0 +1,159 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/detail/integrate_const.hpp
[begin_description]
integrate const implementation
[end_description]
Copyright 2009-2012 Karsten Ahnert
Copyright 2009-2012 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/util/unit_helper.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
// forward declaration
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time &start_time , Time end_time , Time &dt ,
Observer observer , controlled_stepper_tag
);
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_const(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer , stepper_tag
)
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
int step = 0;
while( less_eq_with_sign( time+dt , end_time , dt ) )
{
obs( start_state , time );
stepper.do_step( system , start_state , time , dt );
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
++step;
time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt;
}
obs( start_state , time );
return step;
}
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_const(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer , controlled_stepper_tag
)
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
const Time time_step = dt;
int step = 0;
while( less_eq_with_sign( time+time_step , end_time , dt ) )
{
obs( start_state , time );
detail::integrate_adaptive( stepper , system , start_state , time , time+time_step , dt ,
null_observer() , controlled_stepper_tag() );
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
++step;
time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * time_step;
}
obs( start_state , time );
return step;
}
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_const(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer , dense_output_stepper_tag
)
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
stepper.initialize( start_state , time , dt );
obs( start_state , time );
time += dt;
int obs_step( 1 );
int real_step( 0 );
while( less_with_sign( time+dt , end_time , dt ) )
{
while( less_eq_with_sign( time , stepper.current_time() , dt ) )
{
stepper.calc_state( time , start_state );
obs( start_state , time );
++obs_step;
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
time = start_time + static_cast< typename unit_value_type<Time>::type >(obs_step) * dt;
}
// we have not reached the end, do another real step
if( less_with_sign( stepper.current_time()+stepper.current_time_step() ,
end_time ,
stepper.current_time_step() ) )
{
while( less_eq_with_sign( stepper.current_time() , time , dt ) )
{
stepper.do_step( system );
++real_step;
}
}
else if( less_with_sign( stepper.current_time() , end_time , stepper.current_time_step() ) )
{ // do the last step ending exactly on the end point
stepper.initialize( stepper.current_state() , stepper.current_time() , end_time - stepper.current_time() );
stepper.do_step( system );
++real_step;
}
}
// last observation, if we are still in observation interval
if( less_eq_with_sign( time , end_time , dt ) )
{
stepper.calc_state( time , start_state );
obs( start_state , time );
}
return real_step;
}
} } } }
#endif

View File

@@ -0,0 +1,156 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp
[begin_description]
integrate steps implementation
[end_description]
Copyright 2009-2012 Karsten Ahnert
Copyright 2009-2012 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
#include <boost/numeric/odeint/util/unit_helper.hpp>
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
// forward declaration
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time &start_time , Time end_time , Time &dt ,
Observer observer , controlled_stepper_tag
);
/* basic version */
template< class Stepper , class System , class State , class Time , class Observer>
Time integrate_n_steps(
Stepper stepper , System system , State &start_state ,
Time start_time , Time dt , size_t num_of_steps ,
Observer observer , stepper_tag )
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
for( size_t step = 0; step < num_of_steps ; ++step )
{
obs( start_state , time );
stepper.do_step( system , start_state , time , dt );
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
time = start_time + static_cast< typename unit_value_type<Time>::type >( step+1 ) * dt;
}
obs( start_state , time );
return time;
}
/* controlled version */
template< class Stepper , class System , class State , class Time , class Observer>
Time integrate_n_steps(
Stepper stepper , System system , State &start_state ,
Time start_time , Time dt , size_t num_of_steps ,
Observer observer , controlled_stepper_tag )
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
Time time_step = dt;
for( size_t step = 0; step < num_of_steps ; ++step )
{
obs( start_state , time );
detail::integrate_adaptive( stepper , system , start_state , time , time+time_step , dt ,
null_observer() , controlled_stepper_tag() );
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
time = start_time + static_cast< typename unit_value_type<Time>::type >(step+1) * time_step;
}
obs( start_state , time );
return time;
}
/* dense output version */
template< class Stepper , class System , class State , class Time , class Observer>
Time integrate_n_steps(
Stepper stepper , System system , State &start_state ,
Time start_time , Time dt , size_t num_of_steps ,
Observer observer , dense_output_stepper_tag )
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
const Time end_time = start_time + static_cast< typename unit_value_type<Time>::type >(num_of_steps) * dt;
stepper.initialize( start_state , time , dt );
size_t step = 0;
while( step < num_of_steps )
{
while( less_with_sign( time , stepper.current_time() , stepper.current_time_step() ) )
{
stepper.calc_state( time , start_state );
obs( start_state , time );
++step;
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt;
}
// we have not reached the end, do another real step
if( less_with_sign( stepper.current_time()+stepper.current_time_step() ,
end_time ,
stepper.current_time_step() ) )
{
stepper.do_step( system );
}
else if( less_with_sign( stepper.current_time() , end_time , stepper.current_time_step() ) )
{ // do the last step ending exactly on the end point
stepper.initialize( stepper.current_state() , stepper.current_time() , end_time - stepper.current_time() );
stepper.do_step( system );
}
}
while( stepper.current_time() < end_time )
{
if( less_with_sign( end_time ,
stepper.current_time()+stepper.current_time_step() ,
stepper.current_time_step() ) )
stepper.initialize( stepper.current_state() , stepper.current_time() , end_time - stepper.current_time() );
stepper.do_step( system );
}
// observation at end point, only if we ended exactly on the end-point (or above due to finite precision)
obs( stepper.current_state() , end_time );
return time;
}
}
}
}
}
#endif /* BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED */

View File

@@ -0,0 +1,166 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/detail/integrate_times.hpp
[begin_description]
Default integrate times implementation.
[end_description]
Copyright 2009-2012 Karsten Ahnert
Copyright 2009-2012 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_TIMES_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_TIMES_HPP_INCLUDED
#include <stdexcept>
#include <boost/config.hpp>
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
/*
* integrate_times for simple stepper
*/
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , State &start_state ,
TimeIterator start_time , TimeIterator end_time , Time dt ,
Observer observer , stepper_tag
)
{
BOOST_USING_STD_MIN();
typename odeint::unwrap_reference< Observer >::type &obs = observer;
size_t steps = 0;
Time current_dt = dt;
while( true )
{
Time current_time = *start_time++;
obs( start_state , current_time );
if( start_time == end_time )
break;
while( less_with_sign( current_time , *start_time , current_dt ) )
{
current_dt = min BOOST_PREVENT_MACRO_SUBSTITUTION ( dt , *start_time - current_time );
stepper.do_step( system , start_state , current_time , current_dt );
current_time += current_dt;
steps++;
}
}
return steps;
}
/*
* integrate_times for controlled stepper
*/
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , State &start_state ,
TimeIterator start_time , TimeIterator end_time , Time dt ,
Observer observer , controlled_stepper_tag
)
{
BOOST_USING_STD_MIN();
typename odeint::unwrap_reference< Observer >::type &obs = observer;
const size_t max_attempts = 1000;
const char *error_string = "Integrate adaptive : Maximal number of iterations reached. A step size could not be found.";
size_t steps = 0;
while( true )
{
size_t fail_steps = 0;
Time current_time = *start_time++;
obs( start_state , current_time );
if( start_time == end_time )
break;
while( less_with_sign( current_time , *start_time , dt ) )
{
dt = min BOOST_PREVENT_MACRO_SUBSTITUTION ( dt , *start_time - current_time );
if( stepper.try_step( system , start_state , current_time , dt ) == success )
{
++steps;
}
else
{
++fail_steps;
}
if( fail_steps == max_attempts ) throw std::overflow_error( error_string );
}
}
return steps;
}
/*
* integrate_times for dense output stepper
*/
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , State &start_state ,
TimeIterator start_time , TimeIterator end_time , Time dt ,
Observer observer , dense_output_stepper_tag
)
{
typename odeint::unwrap_reference< Observer >::type &obs = observer;
if( start_time == end_time )
return 0;
Time last_time_point = *(end_time-1);
stepper.initialize( start_state , *start_time , dt );
obs( start_state , *start_time++ );
size_t count = 0;
while( start_time != end_time )
{
while( ( start_time != end_time ) && less_eq_with_sign( *start_time , stepper.current_time() , stepper.current_time_step() ) )
{
stepper.calc_state( *start_time , start_state );
obs( start_state , *start_time );
start_time++;
}
// we have not reached the end, do another real step
if( less_eq_with_sign( stepper.current_time() + stepper.current_time_step() ,
last_time_point ,
stepper.current_time_step() ) )
{
stepper.do_step( system );
++count;
}
else if( start_time != end_time )
{ // do the last step ending exactly on the end point
stepper.initialize( stepper.current_state() , stepper.current_time() , last_time_point - stepper.current_time() );
stepper.do_step( system );
++count;
}
}
return count;
}
} // namespace detail
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED

View File

@@ -0,0 +1,105 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/integrate.hpp
[begin_description]
Convenience methods which choose the stepper for the current ODE.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_HPP_INCLUDED
#include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
#include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
#include <boost/numeric/odeint/integrate/null_observer.hpp>
#include <boost/numeric/odeint/integrate/integrate_adaptive.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* ToDo :
*
* determine type of dxdt for units
*
*/
template< class System , class State , class Time , class Observer >
size_t integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
{
return integrate_adaptive( controlled_runge_kutta< runge_kutta_dopri5< State > >() , system , start_state , start_time , end_time , dt , observer );
}
/*
* the two overloads are needed in order to solve the forwarding problem
*/
template< class System , class State , class Time >
size_t integrate( System system , State &start_state , Time start_time , Time end_time , Time dt )
{
return integrate( system , start_state , start_time , end_time , dt , null_observer() );
}
/**
* \fn integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
* \brief Integrates the ODE.
*
* Integrates the ODE given by system from start_time to end_time starting
* with start_state as initial condition and dt as initial time step.
* This function uses a dense output dopri5 stepper and performs an adaptive
* integration with step size control, thus dt changes during the integration.
* This method uses standard error bounds of 1E-6.
* After each step, the observer is called.
*
* \param system The system function to solve, hence the r.h.s. of the
* ordinary differential equation.
* \param start_state The initial state.
* \param start_time Start time of the integration.
* \param end_time End time of the integration.
* \param dt Initial step size, will be adjusted during the integration.
* \param observer Observer that will be called after each time step.
* \return The number of steps performed.
*/
/**
* \fn integrate( System system , State &start_state , Time start_time , Time end_time , Time dt )
* \brief Integrates the ODE without observer calls.
*
* Integrates the ODE given by system from start_time to end_time starting
* with start_state as initial condition and dt as initial time step.
* This function uses a dense output dopri5 stepper and performs an adaptive
* integration with step size control, thus dt changes during the integration.
* This method uses standard error bounds of 1E-6.
* No observer is called.
*
* \param system The system function to solve, hence the r.h.s. of the
* ordinary differential equation.
* \param start_state The initial state.
* \param start_time Start time of the integration.
* \param end_time End time of the integration.
* \param dt Initial step size, will be adjusted during the integration.
* \return The number of steps performed.
*/
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_HPP_INCLUDED

View File

@@ -0,0 +1,127 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/integrate_adaptive.hpp
[begin_description]
Adaptive integration of ODEs.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED
#include <boost/type_traits/is_same.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/null_observer.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* the two overloads are needed in order to solve the forwarding problem
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer )
{
return detail::integrate_adaptive(
stepper , system , start_state ,
start_time , end_time , dt ,
observer , typename Stepper::stepper_category() );
/*
* Suggestion for a new extendable version:
*
* integrator_adaptive< Stepper , System, State , Time , Observer , typename Stepper::stepper_category > integrator;
* return integrator.run( stepper , system , start_state , start_time , end_time , dt , observer );
*/
}
/**
* \brief Second version to solve the forwarding problem,
* can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
Stepper stepper , System system , const State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer )
{
return detail::integrate_adaptive(
stepper , system , start_state ,
start_time , end_time , dt ,
observer , typename Stepper::stepper_category() );
}
/**
* \brief integrate_adaptive without an observer.
*/
template< class Stepper , class System , class State , class Time >
size_t integrate_adaptive(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt )
{
return integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , null_observer() );
}
/**
* \brief Second version to solve the forwarding problem,
* can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class Time >
size_t integrate_adaptive(
Stepper stepper , System system , const State &start_state ,
Time start_time , Time end_time , Time dt )
{
return integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , null_observer() );
}
/************* DOXYGEN ************/
/**
* \fn integrate_adaptive( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
* \brief Integrates the ODE with adaptive step size.
*
* This function integrates the ODE given by system with the given stepper.
* The observer is called after each step. If the stepper has no error
* control, the step size remains constant and the observer is called at
* equidistant time points t0+n*dt. If the stepper is a ControlledStepper,
* the step size is adjusted and the observer is called in non-equidistant
* intervals.
*
* \param stepper The stepper to be used for numerical integration.
* \param system Function/Functor defining the rhs of the ODE.
* \param start_state The initial condition x0.
* \param start_time The initial time t0.
* \param end_time The final integration time tend.
* \param dt The time step between observer calls, _not_ necessarily the
* time step of the integration.
* \param observer Function/Functor called at equidistant time intervals.
* \return The number of steps performed.
*/
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED

View File

@@ -0,0 +1,156 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/integrate_const.hpp
[begin_description]
Constant integration of ODEs, meaning that the state of the ODE is observed on constant time intervals.
The routines makes full use of adaptive and dense-output methods.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED
#include <boost/type_traits/is_same.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/null_observer.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_const.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* Integrates with constant time step dt.
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_const(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer
)
{
// we want to get as fast as possible to the end
if( boost::is_same< null_observer , Observer >::value )
{
return detail::integrate_adaptive(
stepper , system , start_state ,
start_time , end_time , dt ,
observer , typename Stepper::stepper_category() );
}
else
{
return detail::integrate_const( stepper , system , start_state ,
start_time , end_time , dt ,
observer , typename Stepper::stepper_category() );
}
}
/**
* \brief Second version to solve the forwarding problem,
* can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_const(
Stepper stepper , System system , const State &start_state ,
Time start_time , Time end_time , Time dt ,
Observer observer
)
{
// we want to get as fast as possible to the end
if( boost::is_same< null_observer , Observer >::value )
{
return detail::integrate_adaptive(
stepper , system , start_state ,
start_time , end_time , dt ,
observer , typename Stepper::stepper_category() );
}
else
{
return detail::integrate_const( stepper , system , start_state ,
start_time , end_time , dt ,
observer , typename Stepper::stepper_category() );
}
}
/**
* \brief integrate_const without observer calls
*/
template< class Stepper , class System , class State , class Time >
size_t integrate_const(
Stepper stepper , System system , State &start_state ,
Time start_time , Time end_time , Time dt
)
{
return integrate_const( stepper , system , start_state , start_time , end_time , dt , null_observer() );
}
/**
* \brief Second version to solve the forwarding problem,
* can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class Time >
size_t integrate_const(
Stepper stepper , System system , const State &start_state ,
Time start_time , Time end_time , Time dt
)
{
return integrate_const( stepper , system , start_state , start_time , end_time , dt , null_observer() );
}
/********* DOXYGEN *********/
/**
* \fn integrate_const( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
* \brief Integrates the ODE with constant step size.
*
* Integrates the ODE defined by system using the given stepper.
* This method ensures that the observer is called at constant intervals dt.
* If the Stepper is a normal stepper without step size control, dt is also
* used for the numerical scheme. If a ControlledStepper is provided, the
* algorithm might reduce the step size to meet the error bounds, but it is
* ensured that the observer is always called at equidistant time points
* t0 + n*dt. If a DenseOutputStepper is used, the step size also may vary
* and the dense output is used to call the observer at equidistant time
* points.
*
* \param stepper The stepper to be used for numerical integration.
* \param system Function/Functor defining the rhs of the ODE.
* \param start_state The initial condition x0.
* \param start_time The initial time t0.
* \param end_time The final integration time tend.
* \param dt The time step between observer calls, _not_ necessarily the
* time step of the integration.
* \param observer Function/Functor called at equidistant time intervals.
* \return The number of steps performed.
*/
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED

View File

@@ -0,0 +1,124 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/integrate_n_steps.hpp
[begin_description]
Integration of n steps with constant time size. Adaptive and dense-output methods are fully supported.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED
#include <boost/type_traits/is_same.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/null_observer.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* Integrates n steps
*
* the two overloads are needed in order to solve the forwarding problem
*/
template< class Stepper , class System , class State , class Time , class Observer>
Time integrate_n_steps(
Stepper stepper , System system , State &start_state ,
Time start_time , Time dt , size_t num_of_steps ,
Observer observer )
{
return detail::integrate_n_steps(
stepper , system , start_state ,
start_time , dt , num_of_steps ,
observer , typename Stepper::stepper_category() );
}
/**
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class Time , class Observer >
Time integrate_n_steps(
Stepper stepper , System system , const State &start_state ,
Time start_time , Time dt , size_t num_of_steps ,
Observer observer )
{
return detail::integrate_n_steps(
stepper , system , start_state ,
start_time , dt , num_of_steps ,
observer , typename Stepper::stepper_category() );
}
/**
* \brief The same function as above, but without observer calls.
*/
template< class Stepper , class System , class State , class Time >
Time integrate_n_steps(
Stepper stepper , System system , State &start_state ,
Time start_time , Time dt , size_t num_of_steps )
{
return integrate_n_steps( stepper , system , start_state , start_time , dt , num_of_steps , null_observer() );
}
/**
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class Time >
Time integrate_n_steps(
Stepper stepper , System system , const State &start_state ,
Time start_time , Time dt , size_t num_of_steps )
{
return integrate_n_steps( stepper , system , start_state , start_time , dt , num_of_steps , null_observer() );
}
/************* DOXYGEN *************/
/**
* \fn Time integrate_n_steps( Stepper stepper , System system , State &start_state , Time start_time , Time dt , size_t num_of_steps , Observer observer )
* \brief Integrates the ODE with constant step size.
*
* This function is similar to integrate_const. The observer is called at
* equidistant time intervals t0 + n*dt.
* If the Stepper is a normal stepper without step size control, dt is also
* used for the numerical scheme. If a ControlledStepper is provided, the
* algorithm might reduce the step size to meet the error bounds, but it is
* ensured that the observer is always called at equidistant time points
* t0 + n*dt. If a DenseOutputStepper is used, the step size also may vary
* and the dense output is used to call the observer at equidistant time
* points. The final integration time is always t0 + num_of_steps*dt.
*
* \param stepper The stepper to be used for numerical integration.
* \param system Function/Functor defining the rhs of the ODE.
* \param start_state The initial condition x0.
* \param start_time The initial time t0.
* \param dt The time step between observer calls, _not_ necessarily the
* time step of the integration.
* \param num_of_steps Number of steps to be performed
* \param observer Function/Functor called at equidistant time intervals.
* \return The number of steps performed.
*/
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED

View File

@@ -0,0 +1,131 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/integrate_times.hpp
[begin_description]
Integration of ODEs with observation at user defined points
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED
#include <boost/type_traits/is_same.hpp>
#include <boost/range.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/null_observer.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_times.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* the two overloads are needed in order to solve the forwarding problem
*/
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , State &start_state ,
TimeIterator times_start , TimeIterator times_end , Time dt ,
Observer observer )
{
return detail::integrate_times(
stepper , system , start_state ,
times_start , times_end , dt ,
observer , typename Stepper::stepper_category() );
}
/**
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , const State &start_state ,
TimeIterator times_start , TimeIterator times_end , Time dt ,
Observer observer )
{
return detail::integrate_times(
stepper , system , start_state ,
times_start , times_end , dt ,
observer , typename Stepper::stepper_category() );
}
/**
* \brief The same function as above, but without observer calls.
*/
template< class Stepper , class System , class State , class TimeRange , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , State &start_state ,
const TimeRange &times , Time dt ,
Observer observer )
{
return integrate_times(
stepper , system , start_state ,
boost::begin( times ) , boost::end( times ) , dt , observer );
}
/**
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
*/
template< class Stepper , class System , class State , class TimeRange , class Time , class Observer >
size_t integrate_times(
Stepper stepper , System system , const State &start_state ,
const TimeRange &times , Time dt ,
Observer observer )
{
return integrate_times(
stepper , system , start_state ,
boost::begin( times ) , boost::end( times ) , dt , observer );
}
/********* DOXYGEN ***********/
/**
* \fn size_t integrate_times( Stepper stepper , System system , State &start_state , TimeIterator times_start , TimeIterator times_end , Time dt , Observer observer )
* \brief Integrates the ODE with observer calls at given time points.
*
* Integrates the ODE given by system using the given stepper. This function
* does observer calls at the subsequent time points given by the range
* times_start, times_end. If the stepper has not step size control, the
* step size might be reduced occasionally to ensure observer calls exactly
* at the time points from the given sequence. If the stepper is a
* ControlledStepper, the step size is adjusted to meet the error bounds,
* but also might be reduced occasionally to ensure correct observer calls.
* If a DenseOutputStepper is provided, the dense output functionality is
* used to call the observer at the given times. The end time of the
* integration is always *(end_time-1).
*
* \param stepper The stepper to be used for numerical integration.
* \param system Function/Functor defining the rhs of the ODE.
* \param start_state The initial condition x0.
* \param times_start Iterator to the start time
* \param times_end Iterator to the end time
* \param dt The time step between observer calls, _not_ necessarily the
* time step of the integration.
* \param observer Function/Functor called at equidistant time intervals.
* \return The number of steps performed.
*/
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED

View File

@@ -0,0 +1,38 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/null_observer.hpp
[begin_description]
null_observer
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
namespace boost {
namespace numeric {
namespace odeint {
struct null_observer
{
template< class State , class Time >
void operator()( const State& /* x */ , Time /* t */ ) const
{
}
};
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED

View File

@@ -0,0 +1,56 @@
/*
[auto_generated]
boost/numeric/odeint/integrate/observer_collection.hpp
[begin_description]
Collection of observers, which are all called during the evolution of the ODE.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_OBSERVER_COLLECTION_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATE_OBSERVER_COLLECTION_HPP_INCLUDED
#include <vector>
#include <boost/function.hpp>
namespace boost {
namespace numeric {
namespace odeint {
template< class State , class Time >
class observer_collection
{
public:
typedef boost::function< void( const State& , const Time& ) > observer_type;
typedef std::vector< observer_type > collection_type;
void operator()( const State& x , Time t )
{
for( size_t i=0 ; i<m_observers.size() ; ++i )
m_observers[i]( x , t );
}
collection_type& observers( void ) { return m_observers; }
const collection_type& observers( void ) const { return m_observers; }
private:
collection_type m_observers;
};
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_OBSERVER_COLLECTION_HPP_INCLUDED

View File

@@ -0,0 +1,416 @@
/*
[auto_generated]
boost/numeric/odeint/stepper/adams_bashforth.hpp
[begin_description]
Implementaton of the Adam-Bashforth method a multistep method used for the predictor step in the
Adams-Bashforth-Moulton method.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_HPP_INCLUDED
#include <boost/static_assert.hpp>
#include <boost/numeric/odeint/util/bind.hpp>
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
#include <boost/numeric/odeint/util/state_wrapper.hpp>
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/resizer.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
#include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp>
#include <boost/numeric/odeint/stepper/detail/adams_bashforth_coefficients.hpp>
#include <boost/numeric/odeint/stepper/detail/adams_bashforth_call_algebra.hpp>
#include <boost/numeric/odeint/stepper/detail/rotating_buffer.hpp>
namespace boost {
namespace numeric {
namespace odeint {
template<
size_t Steps ,
class State ,
class Value = double ,
class Deriv = State ,
class Time = Value ,
class Algebra = range_algebra ,
class Operations = default_operations ,
class Resizer = initially_resizer ,
class InitializingStepper = runge_kutta4< State , Value , Deriv , Time , Algebra , Operations, Resizer >
>
class adams_bashforth : public algebra_stepper_base< Algebra , Operations >
{
#ifndef DOXYGEN_SKIP
BOOST_STATIC_ASSERT(( Steps > 0 ));
BOOST_STATIC_ASSERT(( Steps < 9 ));
#endif
public :
typedef State state_type;
typedef state_wrapper< state_type > wrapped_state_type;
typedef Value value_type;
typedef Deriv deriv_type;
typedef state_wrapper< deriv_type > wrapped_deriv_type;
typedef Time time_type;
typedef Resizer resizer_type;
typedef stepper_tag stepper_category;
typedef InitializingStepper initializing_stepper_type;
typedef typename algebra_stepper_base< Algebra , Operations >::algebra_type algebra_type;
typedef typename algebra_stepper_base< Algebra , Operations >::operations_type operations_type;
#ifndef DOXYGEN_SKIP
typedef adams_bashforth< Steps , State , Value , Deriv , Time , Algebra , Operations , Resizer , InitializingStepper > stepper_type;
#endif
static const size_t steps = Steps;
typedef unsigned short order_type;
static const order_type order_value = steps;
typedef detail::rotating_buffer< wrapped_deriv_type , steps > step_storage_type;
order_type order( void ) const { return order_value; }
adams_bashforth( const algebra_type &algebra = algebra_type() )
: m_step_storage() , m_resizer() , m_coefficients() ,
m_steps_initialized( 0 ) , m_initializing_stepper() ,
m_algebra( algebra )
{ }
adams_bashforth( const adams_bashforth &stepper )
: m_step_storage( stepper.m_step_storage ) , m_resizer( stepper.m_resizer ) , m_coefficients() ,
m_steps_initialized( stepper.m_steps_initialized ) , m_initializing_stepper( stepper.m_initializing_stepper ) ,
m_algebra( stepper.m_algebra )
{ }
adams_bashforth& operator=( const adams_bashforth &stepper )
{
m_resizer = stepper.m_resizer;
m_step_storage = stepper.m_step_storage;
m_algebra = stepper.m_algebra;
return *this;
}
/*
* Version 1 : do_step( system , x , t , dt );
*
* solves the forwarding problem
*/
template< class System , class StateInOut >
void do_step( System system , StateInOut &x , time_type t , time_type dt )
{
do_step( system , x , t , x , dt );
}
/**
* \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
*/
template< class System , class StateInOut >
void do_step( System system , const StateInOut &x , time_type t , time_type dt )
{
do_step( system , x , t , x , dt );
}
/*
* Version 2 : do_step( system , in , t , out , dt );
*
* solves the forwarding problem
*/
template< class System , class StateIn , class StateOut >
void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
{
do_step_impl( system , in , t , out , dt );
}
/**
* \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateOut.
*/
template< class System , class StateIn , class StateOut >
void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
{
do_step_impl( system , in , t , out , dt );
}
template< class StateType >
void adjust_size( const StateType &x )
{
resize_impl( x );
}
const step_storage_type& step_storage( void ) const
{
return m_step_storage;
}
step_storage_type& step_storage( void )
{
return m_step_storage;
}
template< class ExplicitStepper , class System , class StateIn >
void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
{
typename odeint::unwrap_reference< ExplicitStepper >::type &stepper = explicit_stepper;
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) );
for( size_t i=0 ; i<steps-1 ; ++i )
{
if( i != 0 ) m_step_storage.rotate();
sys( x , m_step_storage[0].m_v , t );
stepper.do_step( system , x , m_step_storage[0].m_v , t , dt );
t += dt;
}
m_steps_initialized = steps;
}
template< class System , class StateIn >
void initialize( System system , StateIn &x , time_type &t , time_type dt )
{
initialize( detail::ref( m_initializing_stepper ) , system , x , t , dt );
}
void reset( void )
{
m_steps_initialized = 0;
}
bool is_initialized( void ) const
{
return m_steps_initialized >= steps;
}
const initializing_stepper_type& initializing_stepper( void ) const { return m_initializing_stepper; }
initializing_stepper_type& initializing_stepper( void ) { return m_initializing_stepper; }
private:
template< class System , class StateIn , class StateOut >
void do_step_impl( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
{
typename odeint::unwrap_reference< System >::type &sys = system;
if( m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) ) )
{
m_steps_initialized = 0;
}
if( m_steps_initialized < steps - 1 )
{
if( m_steps_initialized != 0 ) m_step_storage.rotate();
sys( in , m_step_storage[0].m_v , t );
m_initializing_stepper.do_step( system , in , m_step_storage[0].m_v , t , out , dt );
m_steps_initialized++;
}
else
{
m_step_storage.rotate();
sys( in , m_step_storage[0].m_v , t );
detail::adams_bashforth_call_algebra< steps , algebra_type , operations_type >()( m_algebra , in , out , m_step_storage , m_coefficients , dt );
}
}
template< class StateIn >
bool resize_impl( const StateIn &x )
{
bool resized( false );
for( size_t i=0 ; i<steps ; ++i )
{
resized |= adjust_size_by_resizeability( m_step_storage[i] , x , typename is_resizeable<deriv_type>::type() );
}
return resized;
}
step_storage_type m_step_storage;
resizer_type m_resizer;
const detail::adams_bashforth_coefficients< value_type , steps > m_coefficients;
size_t m_steps_initialized;
initializing_stepper_type m_initializing_stepper;
protected:
algebra_type m_algebra;
};
/***** DOXYGEN *****/
/**
* \class adams_bashforth
* \brief The Adams-Bashforth multistep algorithm.
*
* The Adams-Bashforth method is a multi-step algorithm with configurable step
* number. The step number is specified as template parameter Steps and it
* then uses the result from the previous Steps steps. See also
* <a href="http://en.wikipedia.org/wiki/Linear_multistep_method">en.wikipedia.org/wiki/Linear_multistep_method</a>.
* Currently, a maximum of Steps=8 is supported.
* The method is explicit and fulfills the Stepper concept. Step size control
* or continuous output are not provided.
*
* This class derives from algebra_base and inherits its interface via
* CRTP (current recurring template pattern). For more details see
* algebra_stepper_base.
*
* \tparam Steps The number of steps (maximal 8).
* \tparam State The state type.
* \tparam Value The value type.
* \tparam Deriv The type representing the time derivative of the state.
* \tparam Time The time representing the independent variable - the time.
* \tparam Algebra The algebra type.
* \tparam Operations The operations type.
* \tparam Resizer The resizer policy type.
* \tparam InitializingStepper The stepper for the first two steps.
*/
/**
* \fn adams_bashforth::adams_bashforth( const algebra_type &algebra )
* \brief Constructs the adams_bashforth class. This constructor can be used as a default
* constructor if the algebra has a default constructor.
* \param algebra A copy of algebra is made and stored.
*/
/**
* \fn order_type adams_bashforth::order( void ) const
* \brief Returns the order of the algorithm, which is equal to the number of steps.
* \return order of the method.
*/
/**
* \fn void adams_bashforth::do_step( System system , StateInOut &x , time_type t , time_type dt )
* \brief This method performs one step. It transforms the result in-place.
*
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
*/
/**
* \fn void adams_bashforth::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
* \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param in The state of the ODE which should be solved. in is not modified in this method
* \param t The value of the time, at which the step should be performed.
* \param out The result of the step is written in out.
* \param dt The step size.
*/
/**
* \fn void adams_bashforth::adjust_size( const StateType &x )
* \brief Adjust the size of all temporaries in the stepper manually.
* \param x A state from which the size of the temporaries to be resized is deduced.
*/
/**
* \fn const step_storage_type& adams_bashforth::step_storage( void ) const
* \brief Returns the storage of intermediate results.
* \return The storage of intermediate results.
*/
/**
* \fn step_storage_type& adams_bashforth::step_storage( void )
* \brief Returns the storage of intermediate results.
* \return The storage of intermediate results.
*/
/**
* \fn void adams_bashforth::initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
* \brief Initialized the stepper. Does Steps-1 steps with the explicit_stepper to fill the buffer.
* \param explicit_stepper the stepper used to fill the buffer of previous step results
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
*/
/**
* \fn void adams_bashforth::initialize( System system , StateIn &x , time_type &t , time_type dt )
* \brief Initialized the stepper. Does Steps-1 steps with an internal instance of InitializingStepper to fill the buffer.
* \note The state x and time t are updated to the values after Steps-1 initial steps.
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The initial state of the ODE which should be solved, updated in this method.
* \param t The initial value of the time, updated in this method.
* \param dt The step size.
*/
/**
* \fn void adams_bashforth::reset( void )
* \brief Resets the internal buffer of the stepper.
*/
/**
* \fn bool adams_bashforth::is_initialized( void ) const
* \brief Returns true if the stepper has been initialized.
* \return bool true if stepper is initialized, false otherwise
*/
/**
* \fn const initializing_stepper_type& adams_bashforth::initializing_stepper( void ) const
* \brief Returns the internal initializing stepper instance.
* \return initializing_stepper
*/
/**
* \fn const initializing_stepper_type& adams_bashforth::initializing_stepper( void ) const
* \brief Returns the internal initializing stepper instance.
* \return initializing_stepper
*/
/**
* \fn initializing_stepper_type& adams_bashforth::initializing_stepper( void )
* \brief Returns the internal initializing stepper instance.
* \return initializing_stepper
*/
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_HPP_INCLUDED

View File

@@ -0,0 +1,258 @@
/*
[auto_generated]
boost/numeric/odeint/stepper/adams_bashforth_moulton.hpp
[begin_description]
Implementation of the Adams-Bashforth-Moulton method, a predictor-corrector multistep method.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
#include <boost/numeric/odeint/util/bind.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
#include <boost/numeric/odeint/util/state_wrapper.hpp>
#include <boost/numeric/odeint/util/resizer.hpp>
#include <boost/numeric/odeint/stepper/adams_bashforth.hpp>
#include <boost/numeric/odeint/stepper/adams_moulton.hpp>
namespace boost {
namespace numeric {
namespace odeint {
template<
size_t Steps ,
class State ,
class Value = double ,
class Deriv = State ,
class Time = Value ,
class Algebra = range_algebra ,
class Operations = default_operations ,
class Resizer = initially_resizer
>
class adams_bashforth_moulton
{
#ifndef DOXYGEN_SKIP
BOOST_STATIC_ASSERT(( Steps > 0 ));
BOOST_STATIC_ASSERT(( Steps < 9 ));
#endif
public :
typedef State state_type;
typedef state_wrapper< state_type > wrapped_state_type;
typedef Value value_type;
typedef Deriv deriv_type;
typedef state_wrapper< deriv_type > wrapped_deriv_type;
typedef Time time_type;
typedef Algebra algebra_type;
typedef Operations operations_type;
typedef Resizer resizer_type;
typedef stepper_tag stepper_category;
static const size_t steps = Steps;
#ifndef DOXYGEN_SKIP
typedef adams_bashforth< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_bashforth_type;
typedef adams_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_moulton_type;
#endif //DOXYGEN_SKIP
typedef unsigned short order_type;
static const order_type order_value = steps + 1;
/** \brief Constructs the adams_bashforth class. */
adams_bashforth_moulton( void )
: m_adams_bashforth() , m_adams_moulton( m_adams_bashforth.algebra() )
{ }
adams_bashforth_moulton( const algebra_type &algebra )
: m_adams_bashforth( algebra ) , m_adams_moulton( m_adams_bashforth.algebra() )
{ }
order_type order( void ) const { return order_value; }
template< class System , class StateInOut >
void do_step( System system , StateInOut &x , time_type t , time_type dt )
{
m_adams_bashforth.do_step( system , x , t , dt );
m_adams_moulton.do_step( system , x , t , dt , m_adams_bashforth.step_storage() );
}
/**
* \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
*/
template< class System , class StateInOut >
void do_step( System system , const StateInOut &x , time_type t , time_type dt )
{
m_adams_bashforth.do_step( system , x , t , dt );
m_adams_moulton.do_step( system , x , t , dt , m_adams_bashforth.step_storage() );
}
template< class System , class StateIn , class StateOut >
void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
{
m_adams_bashforth.do_step( system , in , t , out , dt );
m_adams_moulton.do_step( system , out , t , dt , m_adams_bashforth.step_storage() );
}
/**
* \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateOut.
*/
template< class System , class StateIn , class StateOut >
void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
{
m_adams_bashforth.do_step( system , in , t , out , dt );
m_adams_moulton.do_step( system , out , t , dt , m_adams_bashforth.step_storage() );
}
template< class StateType >
void adjust_size( const StateType &x )
{
m_adams_bashforth.adjust_size( x );
m_adams_moulton.adjust_size( x );
}
template< class ExplicitStepper , class System , class StateIn >
void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
{
m_adams_bashforth.initialize( explicit_stepper , system , x , t , dt );
}
template< class System , class StateIn >
void initialize( System system , StateIn &x , time_type &t , time_type dt )
{
m_adams_bashforth.initialize( system , x , t , dt );
}
private:
adams_bashforth_type m_adams_bashforth;
adams_moulton_type m_adams_moulton;
};
/********* DOXYGEN ********/
/**
* \class adams_bashforth_moulton
* \brief The Adams-Bashforth-Moulton multistep algorithm.
*
* The Adams-Bashforth method is a multi-step predictor-corrector algorithm
* with configurable step number. The step number is specified as template
* parameter Steps and it then uses the result from the previous Steps steps.
* See also
* <a href="http://en.wikipedia.org/wiki/Linear_multistep_method">en.wikipedia.org/wiki/Linear_multistep_method</a>.
* Currently, a maximum of Steps=8 is supported.
* The method is explicit and fulfills the Stepper concept. Step size control
* or continuous output are not provided.
*
* This class derives from algebra_base and inherits its interface via
* CRTP (current recurring template pattern). For more details see
* algebra_stepper_base.
*
* \tparam Steps The number of steps (maximal 8).
* \tparam State The state type.
* \tparam Value The value type.
* \tparam Deriv The type representing the time derivative of the state.
* \tparam Time The time representing the independent variable - the time.
* \tparam Algebra The algebra type.
* \tparam Operations The operations type.
* \tparam Resizer The resizer policy type.
* \tparam InitializingStepper The stepper for the first two steps.
*/
/**
* \fn adams_bashforth_moulton::adams_bashforth_moulton( const algebra_type &algebra )
* \brief Constructs the adams_bashforth class. This constructor can be used as a default
* constructor if the algebra has a default constructor.
* \param algebra A copy of algebra is made and stored.
*/
/**
* \fn adams_bashforth_moulton::order( void ) const
* \brief Returns the order of the algorithm, which is equal to the number of steps+1.
* \return order of the method.
*/
/**
* \fn adams_bashforth_moulton::do_step( System system , StateInOut &x , time_type t , time_type dt )
* \brief This method performs one step. It transforms the result in-place.
*
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
*/
/**
* \fn adams_bashforth_moulton::do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
* \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param in The state of the ODE which should be solved. in is not modified in this method
* \param t The value of the time, at which the step should be performed.
* \param out The result of the step is written in out.
* \param dt The step size.
*/
/**
* \fn adams_bashforth_moulton::adjust_size( const StateType &x )
* \brief Adjust the size of all temporaries in the stepper manually.
* \param x A state from which the size of the temporaries to be resized is deduced.
*/
/**
* \fn adams_bashforth_moulton::initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
* \brief Initialized the stepper. Does Steps-1 steps with the explicit_stepper to fill the buffer.
* \note The state x and time t are updated to the values after Steps-1 initial steps.
* \param explicit_stepper the stepper used to fill the buffer of previous step results
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The initial state of the ODE which should be solved, updated after in this method.
* \param t The initial time, updated in this method.
* \param dt The step size.
*/
/**
* \fn adams_bashforth_moulton::initialize( System system , StateIn &x , time_type &t , time_type dt )
* \brief Initialized the stepper. Does Steps-1 steps using the standard initializing stepper
* of the underlying adams_bashforth stepper.
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
*/
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED

View File

@@ -0,0 +1,195 @@
/*
[auto_generated]
boost/numeric/odeint/stepper/adams_moulton.hpp
[begin_description]
Implementation of the Adams-Moulton method. This is method is not a real stepper, it is more a helper class
which computes the corrector step in the Adams-Bashforth-Moulton method.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_MOULTON_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_MOULTON_HPP_INCLUDED
#include <boost/numeric/odeint/util/bind.hpp>
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
#include <boost/numeric/odeint/util/state_wrapper.hpp>
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/resizer.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
#include <boost/numeric/odeint/stepper/detail/adams_moulton_call_algebra.hpp>
#include <boost/numeric/odeint/stepper/detail/adams_moulton_coefficients.hpp>
#include <boost/numeric/odeint/stepper/detail/rotating_buffer.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* Static implicit Adams-Moulton multistep-solver without step size control and without dense output.
*/
template<
size_t Steps ,
class State ,
class Value = double ,
class Deriv = State ,
class Time = Value ,
class Algebra = range_algebra ,
class Operations = default_operations ,
class Resizer = initially_resizer
>
class adams_moulton
{
private:
public :
typedef State state_type;
typedef state_wrapper< state_type > wrapped_state_type;
typedef Value value_type;
typedef Deriv deriv_type;
typedef state_wrapper< deriv_type > wrapped_deriv_type;
typedef Time time_type;
typedef Algebra algebra_type;
typedef Operations operations_type;
typedef Resizer resizer_type;
typedef stepper_tag stepper_category;
typedef adams_moulton< Steps , State , Value , Deriv , Time , Algebra , Operations , Resizer > stepper_type;
static const size_t steps = Steps;
typedef unsigned short order_type;
static const order_type order_value = steps + 1;
typedef detail::rotating_buffer< wrapped_deriv_type , steps > step_storage_type;
adams_moulton( )
: m_coefficients() , m_dxdt() , m_resizer() ,
m_algebra_instance() , m_algebra( m_algebra_instance )
{ }
adams_moulton( algebra_type &algebra )
: m_coefficients() , m_dxdt() , m_resizer() ,
m_algebra_instance() , m_algebra( algebra )
{ }
adams_moulton& operator=( const adams_moulton &stepper )
{
m_dxdt = stepper.m_dxdt;
m_resizer = stepper.m_resizer;
m_algebra = stepper.m_algebra;
return *this;
}
order_type order( void ) const { return order_value; }
/*
* Version 1 : do_step( system , x , t , dt , buf );
*
* solves the forwarding problem
*/
template< class System , class StateInOut , class ABBuf >
void do_step( System system , StateInOut &in , time_type t , time_type dt , const ABBuf &buf )
{
do_step( system , in , t , in , dt , buf );
}
template< class System , class StateInOut , class ABBuf >
void do_step( System system , const StateInOut &in , time_type t , time_type dt , const ABBuf &buf )
{
do_step( system , in , t , in , dt , buf );
}
/*
* Version 2 : do_step( system , in , t , out , dt , buf );
*
* solves the forwarding problem
*/
template< class System , class StateIn , class StateOut , class ABBuf >
void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , const ABBuf &buf )
{
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) );
sys( in , m_dxdt.m_v , t );
detail::adams_moulton_call_algebra< steps , algebra_type , operations_type >()( m_algebra , in , out , m_dxdt.m_v , buf , m_coefficients , dt );
}
template< class System , class StateIn , class StateOut , class ABBuf >
void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt , const ABBuf &buf )
{
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) );
sys( in , m_dxdt.m_v , t );
detail::adams_moulton_call_algebra< steps , algebra_type , operations_type >()( m_algebra , in , out , m_dxdt.m_v , buf , m_coefficients , dt );
}
template< class StateType >
void adjust_size( const StateType &x )
{
resize_impl( x );
}
algebra_type& algebra()
{ return m_algebra; }
const algebra_type& algebra() const
{ return m_algebra; }
private:
template< class StateIn >
bool resize_impl( const StateIn &x )
{
return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() );
}
const detail::adams_moulton_coefficients< value_type , steps > m_coefficients;
wrapped_deriv_type m_dxdt;
resizer_type m_resizer;
protected:
algebra_type m_algebra_instance;
algebra_type &m_algebra;
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_MOULTON_HPP_INCLUDED

View File

@@ -0,0 +1,91 @@
/*
[auto_generated]
boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp
[begin_description]
Base class for all steppers with an algebra and operations.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_ALGEBRA_STEPPER_BASE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_ALGEBRA_STEPPER_BASE_HPP_INCLUDED
namespace boost {
namespace numeric {
namespace odeint {
template< class Algebra , class Operations >
class algebra_stepper_base
{
public:
typedef Algebra algebra_type;
typedef Operations operations_type;
algebra_stepper_base( const algebra_type &algebra = algebra_type() )
: m_algebra( algebra ) { }
algebra_type& algebra()
{
return m_algebra;
}
const algebra_type& algebra() const
{
return m_algebra;
}
protected:
algebra_type m_algebra;
};
/******* DOXYGEN *******/
/**
* \class algebra_stepper_base
* \brief Base class for all steppers with algebra and operations.
*
* This class serves a base class for all steppers with algebra and operations. It holds the
* algebra and provides access to the algebra. The operations are not instantiated, since they are
* static classes inside the operations class.
*
* \tparam Algebra The type of the algebra. Must fulfill the Algebra Concept, at least partially to work
* with the stepper.
* \tparam Operations The type of the operations. Must fulfill the Operations Concept, at least partially
* to work with the stepper.
*/
/**
* \fn algebra_stepper_base::algebra_stepper_base( const algebra_type &algebra = algebra_type() )
* \brief Constructs a algebra_stepper_base and creates the algebra. This constructor can be used as a default
* constructor if the algebra has a default constructor.
* \param algebra The algebra_stepper_base stores and uses a copy of algebra.
*/
/**
* \fn algebra_type& algebra_stepper_base::algebra()
* \return A reference to the algebra which is held by this class.
*/
/**
* \fn const algebra_type& algebra_stepper_base::algebra() const
* \return A const reference to the algebra which is held by this class.
*/
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_ALGEBRA_STEPPER_BASE_HPP_INCLUDED

View File

@@ -0,0 +1,560 @@
/*
[auto_generated]
boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp
[begin_description]
Base class for all explicit Runge Kutta stepper which are also error steppers.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_BASE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_BASE_HPP_INCLUDED
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/numeric/odeint/util/bind.hpp>
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/util/state_wrapper.hpp>
#include <boost/numeric/odeint/util/is_resizeable.hpp>
#include <boost/numeric/odeint/util/resizer.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/*
* base class for explicit stepper and error steppers
* models the stepper AND the error stepper concept
*
* this class provides the following do_step variants:
* do_step( sys , x , t , dt )
* do_step( sys , x , dxdt , t , dt )
* do_step( sys , in , t , out , dt )
* do_step( sys , in , dxdt , t , out , dt )
* do_step( sys , x , t , dt , xerr )
* do_step( sys , x , dxdt , t , dt , xerr )
* do_step( sys , in , t , out , dt , xerr )
* do_step( sys , in , dxdt , t , out , dt , xerr )
*/
template<
class Stepper ,
unsigned short Order ,
unsigned short StepperOrder ,
unsigned short ErrorOrder ,
class State ,
class Value ,
class Deriv ,
class Time ,
class Algebra ,
class Operations ,
class Resizer
>
class explicit_error_stepper_base : public algebra_stepper_base< Algebra , Operations >
{
public:
typedef algebra_stepper_base< Algebra , Operations > algebra_stepper_base_type;
typedef typename algebra_stepper_base_type::algebra_type algebra_type;
typedef State state_type;
typedef Value value_type;
typedef Deriv deriv_type;
typedef Time time_type;
typedef Resizer resizer_type;
typedef Stepper stepper_type;
typedef explicit_error_stepper_tag stepper_category;
#ifndef DOXYGEN_SKIP
typedef state_wrapper< state_type > wrapped_state_type;
typedef state_wrapper< deriv_type > wrapped_deriv_type;
typedef explicit_error_stepper_base< Stepper , Order , StepperOrder , ErrorOrder ,
State , Value , Deriv , Time , Algebra , Operations , Resizer > internal_stepper_base_type;
#endif
typedef unsigned short order_type;
static const order_type order_value = Order;
static const order_type stepper_order_value = StepperOrder;
static const order_type error_order_value = ErrorOrder;
explicit_error_stepper_base( const algebra_type &algebra = algebra_type() )
: algebra_stepper_base_type( algebra )
{ }
order_type order( void ) const
{
return order_value;
}
order_type stepper_order( void ) const
{
return stepper_order_value;
}
order_type error_order( void ) const
{
return error_order_value;
}
/*
* Version 1 : do_step( sys , x , t , dt )
*
* the two overloads are needed in order to solve the forwarding problem
*/
template< class System , class StateInOut >
void do_step( System system , StateInOut &x , time_type t , time_type dt )
{
do_step_v1( system , x , t , dt );
}
/**
* \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
*/
template< class System , class StateInOut >
void do_step( System system , const StateInOut &x , time_type t , time_type dt )
{
do_step_v1( system , x , t , dt );
}
/*
* Version 2 : do_step( sys , x , dxdt , t , dt )
*
* this version does not solve the forwarding problem, boost.range can not be used
*
* the disable is needed to avoid ambiguous overloads if state_type = time_type
*/
template< class System , class StateInOut , class DerivIn >
typename boost::disable_if< boost::is_same< DerivIn , time_type > , void >::type
do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt )
{
this->stepper().do_step_impl( system , x , dxdt , t , x , dt );
}
/*
* Version 3 : do_step( sys , in , t , out , dt )
*
* this version does not solve the forwarding problem, boost.range can not be used
*
* the disable is needed to avoid ambiguous overloads if state_type = time_type
*/
template< class System , class StateIn , class StateOut >
typename boost::disable_if< boost::is_same< StateIn , time_type > , void >::type
do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
{
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) );
sys( in , m_dxdt.m_v ,t );
this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , dt );
}
/*
* Version 4 :do_step( sys , in , dxdt , t , out , dt )
*
* this version does not solve the forwarding problem, boost.range can not be used
*
* the disable is needed to avoid ambiguous overloads if state_type = time_type
*/
template< class System , class StateIn , class DerivIn , class StateOut >
typename boost::disable_if< boost::is_same< DerivIn , time_type > , void >::type
do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
{
this->stepper().do_step_impl( system , in , dxdt , t , out , dt );
}
/*
* Version 5 :do_step( sys , x , t , dt , xerr )
*
* the two overloads are needed in order to solve the forwarding problem
*/
template< class System , class StateInOut , class Err >
void do_step( System system , StateInOut &x , time_type t , time_type dt , Err &xerr )
{
do_step_v5( system , x , t , dt , xerr );
}
/**
* \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
*/
template< class System , class StateInOut , class Err >
void do_step( System system , const StateInOut &x , time_type t , time_type dt , Err &xerr )
{
do_step_v5( system , x , t , dt , xerr );
}
/*
* Version 6 :do_step( sys , x , dxdt , t , dt , xerr )
*
* this version does not solve the forwarding problem, boost.range can not be used
*
* the disable is needed to avoid ambiguous overloads if state_type = time_type
*/
template< class System , class StateInOut , class DerivIn , class Err >
typename boost::disable_if< boost::is_same< DerivIn , time_type > , void >::type
do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt , Err &xerr )
{
this->stepper().do_step_impl( system , x , dxdt , t , x , dt , xerr );
}
/*
* Version 7 : do_step( sys , in , t , out , dt , xerr )
*
* this version does not solve the forwarding problem, boost.range can not be used
*/
template< class System , class StateIn , class StateOut , class Err >
void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , Err &xerr )
{
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) );
sys( in , m_dxdt.m_v ,t );
this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , dt , xerr );
}
/*
* Version 8 : do_step( sys , in , dxdt , t , out , dt , xerr )
*
* this version does not solve the forwarding problem, boost.range can not be used
*/
template< class System , class StateIn , class DerivIn , class StateOut , class Err >
void do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt , Err &xerr )
{
this->stepper().do_step_impl( system , in , dxdt , t , out , dt , xerr );
}
template< class StateIn >
void adjust_size( const StateIn &x )
{
resize_impl( x );
}
private:
template< class System , class StateInOut >
void do_step_v1( System system , StateInOut &x , time_type t , time_type dt )
{
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl<StateInOut> , detail::ref( *this ) , detail::_1 ) );
sys( x , m_dxdt.m_v ,t );
this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , dt );
}
template< class System , class StateInOut , class Err >
void do_step_v5( System system , StateInOut &x , time_type t , time_type dt , Err &xerr )
{
typename odeint::unwrap_reference< System >::type &sys = system;
m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl<StateInOut> , detail::ref( *this ) , detail::_1 ) );
sys( x , m_dxdt.m_v ,t );
this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , dt , xerr );
}
template< class StateIn >
bool resize_impl( const StateIn &x )
{
return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() );
}
stepper_type& stepper( void )
{
return *static_cast< stepper_type* >( this );
}
const stepper_type& stepper( void ) const
{
return *static_cast< const stepper_type* >( this );
}
resizer_type m_resizer;
protected:
wrapped_deriv_type m_dxdt;
};
/******** DOXYGEN *******/
/**
* \class explicit_error_stepper_base
* \brief Base class for explicit steppers with error estimation. This class can used with
* controlled steppers for step size control.
*
* This class serves as the base class for all explicit steppers with algebra and operations. In contrast to
* explicit_stepper_base it also estimates the error and can be used in a controlled stepper to provide
* step size control.
*
* \note This stepper provides `do_step` methods with and without error estimation. It has therefore three orders,
* one for the order of a step if the error is not estimated. The other two orders are the orders of the step and
* the error step if the error estimation is performed.
*
* explicit_error_stepper_base is used as the interface in a CRTP (currently recurring template
* pattern). In order to work correctly the parent class needs to have a method
* `do_step_impl( system , in , dxdt_in , t , out , dt , xerr )`.
* explicit_error_stepper_base derives from algebra_stepper_base.
*
* explicit_error_stepper_base provides several overloaded `do_step` methods, see the list below. Only two of them
* are needed to fulfill the Error Stepper concept. The other ones are for convenience and for performance. Some
* of them simply update the state out-of-place, while other expect that the first derivative at `t` is passed to the
* stepper.
*
* - `do_step( sys , x , t , dt )` - The classical `do_step` method needed to fulfill the Error Stepper concept. The
* state is updated in-place. A type modelling a Boost.Range can be used for x.
* - `do_step( sys , x , dxdt , t , dt )` - This method updates the state in-place, but the derivative at the point `t`
* must be explicitly passed in `dxdt`.
* - `do_step( sys , in , t , out , dt )` - This method updates the state out-of-place, hence the result of the step
* is stored in `out`.
* - `do_step( sys , in , dxdt , t , out , dt )` - This method update the state out-of-place and expects that the
* derivative at the point `t` is explicitly passed in `dxdt`. It is a combination of the two `do_step` methods
* above.
* - `do_step( sys , x , t , dt , xerr )` - This `do_step` method is needed to fulfill the Error Stepper concept. The
* state is updated in-place and an error estimate is calculated. A type modelling a Boost.Range can be used for x.
* - `do_step( sys , x , dxdt , t , dt , xerr )` - This method updates the state in-place, but the derivative at the
* point `t` must be passed in `dxdt`. An error estimate is calculated.
* - `do_step( sys , in , t , out , dt , xerr )` - This method updates the state out-of-place and estimates the error
* during the step.
* - `do_step( sys , in , dxdt , t , out , dt , xerr )` - This methods updates the state out-of-place and estimates
* the error during the step. Furthermore, the derivative at `t` must be passed in `dxdt`.
*
* \note The system is always passed as value, which might result in poor performance if it contains data. In this
* case it can be used with `boost::ref` or `std::ref`, for example `stepper.do_step( boost::ref( sys ) , x , t , dt );`
*
* \note The time `t` is not advanced by the stepper. This has to done manually, or by the appropriate `integrate`
* routines or `iterator`s.
*
* \tparam Stepper The stepper on which this class should work. It is used via CRTP, hence explicit_stepper_base
* provides the interface for the Stepper.
* \tparam Order The order of a stepper if the stepper is used without error estimation.
* \tparam StepperOrder The order of a step if the stepper is used with error estimation. Usually Order and StepperOrder have
* the same value.
* \tparam ErrorOrder The order of the error step if the stepper is used with error estimation.
* \tparam State The state type for the stepper.
* \tparam Value The value type for the stepper. This should be a floating point type, like float,
* double, or a multiprecision type. It must not necessary be the value_type of the State. For example
* the State can be a `vector< complex< double > >` in this case the Value must be double.
* The default value is double.
* \tparam Deriv The type representing time derivatives of the state type. It is usually the same type as the
* state type, only if used with Boost.Units both types differ.
* \tparam Time The type representing the time. Usually the same type as the value type. When Boost.Units is
* used, this type has usually a unit.
* \tparam Algebra The algebra type which must fulfill the Algebra Concept.
* \tparam Operations The type for the operations which must fulfill the Operations Concept.
* \tparam Resizer The resizer policy class.
*/
/**
* \fn explicit_error_stepper_base::explicit_error_stepper_base( const algebra_type &algebra = algebra_type() )
*
* \brief Constructs a explicit_error_stepper_base class. This constructor can be used as a default
* constructor if the algebra has a default constructor.
* \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
*/
/**
* \fn explicit_error_stepper_base::order( void ) const
* \return Returns the order of the stepper if it used without error estimation.
*/
/**
* \fn explicit_error_stepper_base::stepper_order( void ) const
* \return Returns the order of a step if the stepper is used without error estimation.
*/
/**
* \fn explicit_error_stepper_base::error_order( void ) const
* \return Returns the order of an error step if the stepper is used without error estimation.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , time_type t , time_type dt )
* \brief This method performs one step. It transforms the result in-place.
*
* \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt )
* \brief The method performs one step with the stepper passed by Stepper. Additionally to the other method
* the derivative of x is also passed to this method. It is supposed to be used in the following way:
*
* \code
* sys( x , dxdt , t );
* stepper.do_step( sys , x , dxdt , t , dt );
* \endcode
*
* The result is updated in place in x. This method is disabled if Time and Deriv are of the same type. In this
* case the method could not be distinguished from other `do_step` versions.
*
* \note This method does not solve the forwarding problem.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param dxdt The derivative of x at t.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
* \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
* This method is disabled if StateIn and Time are the same type. In this case the method can not be distinguished from
* other `do_step` variants.
* \note This method does not solve the forwarding problem.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param in The state of the ODE which should be solved. in is not modified in this method
* \param t The value of the time, at which the step should be performed.
* \param out The result of the step is written in out.
* \param dt The step size.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
* \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
* Furthermore, the derivative of x at t is passed to the stepper. It is supposed to be used in the following way:
*
* \code
* sys( in , dxdt , t );
* stepper.do_step( sys , in , dxdt , t , out , dt );
* \endcode
*
* This method is disabled if DerivIn and Time are of same type.
*
* \note This method does not solve the forwarding problem.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param in The state of the ODE which should be solved. in is not modified in this method
* \param dxdt The derivative of x at t.
* \param t The value of the time, at which the step should be performed.
* \param out The result of the step is written in out.
* \param dt The step size.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , time_type t , time_type dt , Err &xerr )
* \brief The method performs one step with the stepper passed by Stepper and estimates the error. The state of the ODE
* is updated in-place.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. x is updated by this method.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
* \param xerr The estimation of the error is stored in xerr.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt , Err &xerr )
* \brief The method performs one step with the stepper passed by Stepper. Additionally to the other method
* the derivative of x is also passed to this method. It is supposed to be used in the following way:
*
* \code
* sys( x , dxdt , t );
* stepper.do_step( sys , x , dxdt , t , dt , xerr );
* \endcode
*
* The result is updated in place in x. This method is disabled if Time and DerivIn are of the same type. In this
* case the method could not be distinguished from other `do_step` versions.
*
* \note This method does not solve the forwarding problem.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
* \param dxdt The derivative of x at t.
* \param t The value of the time, at which the step should be performed.
* \param dt The step size.
* \param xerr The error estimate is stored in xerr.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , Err &xerr )
* \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
* Furthermore, the error is estimated.
*
* \note This method does not solve the forwarding problem.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param in The state of the ODE which should be solved. in is not modified in this method
* \param t The value of the time, at which the step should be performed.
* \param out The result of the step is written in out.
* \param dt The step size.
* \param xerr The error estimate.
*/
/**
* \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt , Err &xerr )
* \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
* Furthermore, the derivative of x at t is passed to the stepper and the error is estimated. It is supposed to be used in the following way:
*
* \code
* sys( in , dxdt , t );
* stepper.do_step( sys , in , dxdt , t , out , dt );
* \endcode
*
* This method is disabled if DerivIn and Time are of same type.
*
* \note This method does not solve the forwarding problem.
*
* \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
* Simple System concept.
* \param in The state of the ODE which should be solved. in is not modified in this method
* \param dxdt The derivative of x at t.
* \param t The value of the time, at which the step should be performed.
* \param out The result of the step is written in out.
* \param dt The step size.
* \param xerr The error estimate.
*/
/**
* \fn explicit_error_stepper_base::adjust_size( const StateIn &x )
* \brief Adjust the size of all temporaries in the stepper manually.
* \param x A state from which the size of the temporaries to be resized is deduced.
*/
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_BASE_HPP_INCLUDED

Some files were not shown because too many files have changed in this diff Show More