整理
This commit is contained in:
24
include/boost/numeric/conversion/bounds.hpp
Normal file
24
include/boost/numeric/conversion/bounds.hpp
Normal 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
|
||||
61
include/boost/numeric/conversion/cast.hpp
Normal file
61
include/boost/numeric/conversion/cast.hpp
Normal 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_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
|
||||
32
include/boost/numeric/conversion/conversion_traits.hpp
Normal file
32
include/boost/numeric/conversion/conversion_traits.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// (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
|
||||
{
|
||||
} ;
|
||||
|
||||
} } // namespace boost::numeric
|
||||
|
||||
#endif
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
68
include/boost/numeric/conversion/converter.hpp
Normal file
68
include/boost/numeric/conversion/converter.hpp
Normal 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
|
||||
|
||||
|
||||
194
include/boost/numeric/conversion/converter_policies.hpp
Normal file
194
include/boost/numeric/conversion/converter_policies.hpp
Normal 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 <functional>
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#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:
|
||||
|
||||
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
|
||||
{ return "bad numeric conversion: overflow"; }
|
||||
};
|
||||
|
||||
class negative_overflow : public bad_numeric_cast
|
||||
{
|
||||
public:
|
||||
|
||||
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
|
||||
{ return "bad numeric conversion: negative overflow"; }
|
||||
};
|
||||
class positive_overflow : public bad_numeric_cast
|
||||
{
|
||||
public:
|
||||
|
||||
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
|
||||
{ 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
|
||||
58
include/boost/numeric/conversion/detail/bounds.hpp
Normal file
58
include/boost/numeric/conversion/detail/bounds.hpp
Normal 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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -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
|
||||
|
||||
|
||||
593
include/boost/numeric/conversion/detail/converter.hpp
Normal file
593
include/boost/numeric/conversion/detail/converter.hpp
Normal file
@@ -0,0 +1,593 @@
|
||||
// (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 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 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 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(BOOST_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
|
||||
|
||||
|
||||
@@ -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/type_traits/integral_constant.hpp"
|
||||
|
||||
namespace boost { namespace numeric { namespace convdetail
|
||||
{
|
||||
// Integral Constants for 'IntFloatMixture'
|
||||
typedef boost::integral_constant<int_float_mixture_enum, integral_to_integral> int2int_c ;
|
||||
typedef boost::integral_constant<int_float_mixture_enum, integral_to_float> int2float_c ;
|
||||
typedef boost::integral_constant<int_float_mixture_enum, float_to_integral> float2int_c ;
|
||||
typedef boost::integral_constant<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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
234
include/boost/numeric/conversion/detail/is_subranged.hpp
Normal file
234
include/boost/numeric/conversion/detail/is_subranged.hpp
Normal 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
|
||||
|
||||
|
||||
120
include/boost/numeric/conversion/detail/meta.hpp
Normal file
120
include/boost/numeric/conversion/detail/meta.hpp
Normal 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(BOOST_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
|
||||
|
||||
|
||||
138
include/boost/numeric/conversion/detail/numeric_cast_traits.hpp
Normal file
138
include/boost/numeric/conversion/detail/numeric_cast_traits.hpp
Normal 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
|
||||
308
include/boost/numeric/conversion/detail/old_numeric_cast.hpp
Normal file
308
include/boost/numeric/conversion/detail/old_numeric_cast.hpp
Normal file
@@ -0,0 +1,308 @@
|
||||
// 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
|
||||
// 02 Jun 14 Remove VC6 workarounds.
|
||||
// 16 Jul 11 Bugfixes for VC6.
|
||||
// 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>
|
||||
|
||||
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; }
|
||||
};
|
||||
|
||||
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(BOOST_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(BOOST_BORLANDC)
|
||||
# pragma option pop
|
||||
# endif
|
||||
} // namespace detail
|
||||
|
||||
#endif
|
||||
|
||||
template<typename Target, typename Source>
|
||||
inline Target numeric_cast(Source arg)
|
||||
{
|
||||
// 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(BOOST_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(BOOST_BORLANDC)
|
||||
#pragma option pop
|
||||
# endif
|
||||
#endif
|
||||
{
|
||||
throw bad_numeric_cast();
|
||||
}
|
||||
return static_cast<Target>(arg);
|
||||
} // numeric_cast
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_OLD_NUMERIC_CAST_HPP
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
};
|
||||
}}
|
||||
72
include/boost/numeric/conversion/detail/sign_mixture.hpp
Normal file
72
include/boost/numeric/conversion/detail/sign_mixture.hpp
Normal 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/type_traits/integral_constant.hpp"
|
||||
|
||||
namespace boost { namespace numeric { namespace convdetail
|
||||
{
|
||||
// Integral Constants for 'SignMixture'
|
||||
typedef boost::integral_constant<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
|
||||
typedef boost::integral_constant<sign_mixture_enum, signed_to_signed> sig2sig_c ;
|
||||
typedef boost::integral_constant<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
|
||||
typedef boost::integral_constant<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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -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/type_traits/integral_constant.hpp"
|
||||
|
||||
namespace boost { namespace numeric { namespace convdetail
|
||||
{
|
||||
// Integral Constants for 'UdtMixture'
|
||||
typedef boost::integral_constant<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
|
||||
typedef boost::integral_constant<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
|
||||
typedef boost::integral_constant<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
|
||||
typedef boost::integral_constant<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
|
||||
|
||||
|
||||
30
include/boost/numeric/conversion/int_float_mixture.hpp
Normal file
30
include/boost/numeric/conversion/int_float_mixture.hpp
Normal 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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
29
include/boost/numeric/conversion/int_float_mixture_enum.hpp
Normal file
29
include/boost/numeric/conversion/int_float_mixture_enum.hpp
Normal 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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
27
include/boost/numeric/conversion/is_subranged.hpp
Normal file
27
include/boost/numeric/conversion/is_subranged.hpp
Normal 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
|
||||
|
||||
|
||||
31
include/boost/numeric/conversion/numeric_cast_traits.hpp
Normal file
31
include/boost/numeric/conversion/numeric_cast_traits.hpp
Normal 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
|
||||
30
include/boost/numeric/conversion/sign_mixture.hpp
Normal file
30
include/boost/numeric/conversion/sign_mixture.hpp
Normal 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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
29
include/boost/numeric/conversion/sign_mixture_enum.hpp
Normal file
29
include/boost/numeric/conversion/sign_mixture_enum.hpp
Normal 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
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
28
include/boost/numeric/conversion/udt_builtin_mixture.hpp
Normal file
28
include/boost/numeric/conversion/udt_builtin_mixture.hpp
Normal 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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
32
include/boost/numeric/interval.hpp
Normal file
32
include/boost/numeric/interval.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/* Boost interval.hpp header file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
305
include/boost/numeric/interval/arith.hpp
Normal file
305
include/boost/numeric/interval/arith.hpp
Normal file
@@ -0,0 +1,305 @@
|
||||
/* Boost interval/arith.hpp template implementation file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002-2003 Hervé Brö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
|
||||
304
include/boost/numeric/interval/arith2.hpp
Normal file
304
include/boost/numeric/interval/arith2.hpp
Normal file
@@ -0,0 +1,304 @@
|
||||
/* 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é Brö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;
|
||||
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
|
||||
69
include/boost/numeric/interval/arith3.hpp
Normal file
69
include/boost/numeric/interval/arith3.hpp
Normal 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
|
||||
130
include/boost/numeric/interval/checking.hpp
Normal file
130
include/boost/numeric/interval/checking.hpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/* Boost interval/checking.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002 Hervé Brö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
|
||||
19
include/boost/numeric/interval/compare.hpp
Normal file
19
include/boost/numeric/interval/compare.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/* Boost interval/compare.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002 Hervé Brö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
|
||||
113
include/boost/numeric/interval/compare/certain.hpp
Normal file
113
include/boost/numeric/interval/compare/certain.hpp
Normal 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
|
||||
248
include/boost/numeric/interval/compare/explicit.hpp
Normal file
248
include/boost/numeric/interval/compare/explicit.hpp
Normal file
@@ -0,0 +1,248 @@
|
||||
/* Boost interval/compare/explicit.hpp template implementation file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
122
include/boost/numeric/interval/compare/lexicographic.hpp
Normal file
122
include/boost/numeric/interval/compare/lexicographic.hpp
Normal 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
|
||||
113
include/boost/numeric/interval/compare/possible.hpp
Normal file
113
include/boost/numeric/interval/compare/possible.hpp
Normal 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
|
||||
101
include/boost/numeric/interval/compare/set.hpp
Normal file
101
include/boost/numeric/interval/compare/set.hpp
Normal 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>& , const T& )
|
||||
{
|
||||
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>& , const T& )
|
||||
{
|
||||
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>& , const T& )
|
||||
{
|
||||
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>& , const T& )
|
||||
{
|
||||
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>& , const T& )
|
||||
{
|
||||
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>& , const T& )
|
||||
{
|
||||
throw comparison_error();
|
||||
}
|
||||
|
||||
} // namespace set
|
||||
} // namespace compare
|
||||
} // namespace interval_lib
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP
|
||||
138
include/boost/numeric/interval/compare/tribool.hpp
Normal file
138
include/boost/numeric/interval/compare/tribool.hpp
Normal 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
|
||||
85
include/boost/numeric/interval/constants.hpp
Normal file
85
include/boost/numeric/interval/constants.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/* Boost interval/constants.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002 Hervé Brö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
|
||||
113
include/boost/numeric/interval/detail/alpha_rounding_control.hpp
Normal file
113
include/boost/numeric/interval/detail/alpha_rounding_control.hpp
Normal 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 */
|
||||
@@ -0,0 +1,57 @@
|
||||
/* Boost interval/detail/bcc_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
|
||||
#if !defined(__BORLANDC__) || defined(__clang__)
|
||||
# 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 */
|
||||
48
include/boost/numeric/interval/detail/bugs.hpp
Normal file
48
include/boost/numeric/interval/detail/bugs.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Boost interval/detail/bugs.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
|
||||
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_BUGS
|
||||
@@ -0,0 +1,50 @@
|
||||
/* Boost interval/detail/c99_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
@@ -0,0 +1,43 @@
|
||||
/* Boost interval/detail/c99sub_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
194
include/boost/numeric/interval/detail/division.hpp
Normal file
194
include/boost/numeric/interval/detail/division.hpp
Normal 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
|
||||
@@ -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 */
|
||||
|
||||
41
include/boost/numeric/interval/detail/interval_prototype.hpp
Normal file
41
include/boost/numeric/interval/detail/interval_prototype.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Boost interval/detail/interval_prototype.hpp file
|
||||
*
|
||||
* Copyright 2002 Hervé Brö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
|
||||
113
include/boost/numeric/interval/detail/msvc_rounding_control.hpp
Normal file
113
include/boost/numeric/interval/detail/msvc_rounding_control.hpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/* Boost interval/detail/msvc_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Maarten Keijzer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
#if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64)
|
||||
// x64 ignores _MCW_PC and _MCW_IC, and the Debug CRT library actually
|
||||
// asserts when these are passed to _control87.
|
||||
// MSDN says on '_control87' that changing precision (_MCW_PC) or
|
||||
// infinity (_MCW_IC) handling is not supported on the ARM and x64
|
||||
// architectures and that _control87 raises an assertion
|
||||
// and the invalid parameter handler is invoked.
|
||||
| _MCW_PC | _MCW_IC
|
||||
#endif
|
||||
);
|
||||
}
|
||||
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 */
|
||||
@@ -0,0 +1,99 @@
|
||||
/* Boost interval/detail/ppc_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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 */
|
||||
112
include/boost/numeric/interval/detail/sparc_rounding_control.hpp
Normal file
112
include/boost/numeric/interval/detail/sparc_rounding_control.hpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/* Boost interval/detail/sparc_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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 */
|
||||
76
include/boost/numeric/interval/detail/test_input.hpp
Normal file
76
include/boost/numeric/interval/detail/test_input.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/* Boost interval/detail/test_input.hpp file
|
||||
*
|
||||
* Copyright 2002 Hervé Brö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
|
||||
108
include/boost/numeric/interval/detail/x86_rounding_control.hpp
Normal file
108
include/boost/numeric/interval/detail/x86_rounding_control.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* Boost interval/detail/x86_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
|
||||
#if defined(__GNUC__) || defined(__BORLANDC__) && defined(__clang__)
|
||||
# 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 */
|
||||
@@ -0,0 +1,51 @@
|
||||
/* Boost interval/detail/x86gcc_rounding_control.hpp file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
|
||||
#if !defined(__GNUC__) && !(defined(__BORLANDC__) && defined(__clang__))
|
||||
# error This header only works with GNU CC.
|
||||
#endif
|
||||
|
||||
#if !defined(__i386__) && !defined(__x86_64__)
|
||||
# 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 */
|
||||
70
include/boost/numeric/interval/ext/integer.hpp
Normal file
70
include/boost/numeric/interval/ext/integer.hpp
Normal 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
|
||||
@@ -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é Brö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
|
||||
73
include/boost/numeric/interval/hw_rounding.hpp
Normal file
73
include/boost/numeric/interval/hw_rounding.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/* Boost interval/hw_rounding.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002 Hervé Brö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/config.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(BOOST_NO_FENV_H)
|
||||
# include <boost/numeric/interval/detail/c99_rounding_control.hpp>
|
||||
#elif defined(__i386__) || defined(_M_IX86) || defined(__BORLANDC__) && !defined(__clang__) || defined(_M_X64)
|
||||
# include <boost/numeric/interval/detail/x86_rounding_control.hpp>
|
||||
#elif defined(__i386) && defined(__SUNPRO_CC)
|
||||
# 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(BOOST_NO_FENV_H)
|
||||
# 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
|
||||
450
include/boost/numeric/interval/interval.hpp
Normal file
450
include/boost/numeric/interval/interval.hpp
Normal file
@@ -0,0 +1,450 @@
|
||||
/* Boost interval/interval.hpp header file
|
||||
*
|
||||
* Copyright 2002-2003 Hervé Brö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
|
||||
41
include/boost/numeric/interval/io.hpp
Normal file
41
include/boost/numeric/interval/io.hpp
Normal 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
|
||||
49
include/boost/numeric/interval/limits.hpp
Normal file
49
include/boost/numeric/interval/limits.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Boost interval/limits.hpp template implementation file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002-2003 Hervé Brö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
|
||||
|
||||
|
||||
#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 () BOOST_NOEXCEPT_OR_NOTHROW { return I((bl::min)(), (bl::min)()); }
|
||||
static I max BOOST_PREVENT_MACRO_SUBSTITUTION () BOOST_NOEXCEPT_OR_NOTHROW { return I((bl::max)(), (bl::max)()); }
|
||||
static I epsilon() BOOST_NOEXCEPT_OR_NOTHROW { 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 () BOOST_NOEXCEPT_OR_NOTHROW { return I::whole(); }
|
||||
static I quiet_NaN() BOOST_NOEXCEPT_OR_NOTHROW { return I::empty(); }
|
||||
static I signaling_NaN() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return I(bl::signaling_NaN(), bl::signaling_Nan()); }
|
||||
static I denorm_min() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return I(bl::denorm_min(), bl::denorm_min()); }
|
||||
private:
|
||||
static I round_error(); // hide this on purpose, not yet implemented
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_INTERVAL_LIMITS_HPP
|
||||
75
include/boost/numeric/interval/policies.hpp
Normal file
75
include/boost/numeric/interval/policies.hpp
Normal 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
|
||||
120
include/boost/numeric/interval/rounded_arith.hpp
Normal file
120
include/boost/numeric/interval/rounded_arith.hpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/* Boost interval/rounded_arith.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002-2003 Hervé Brö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 this->to_int(x); }
|
||||
T int_up (const T& x) { this->upward(); return this->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 -this->to_int(-x); }
|
||||
T int_up (const T& x) { return this->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
|
||||
140
include/boost/numeric/interval/rounded_transc.hpp
Normal file
140
include/boost/numeric/interval/rounded_transc.hpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/* Boost interval/rounded_transc.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002-2003 Hervé Brö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
|
||||
101
include/boost/numeric/interval/rounding.hpp
Normal file
101
include/boost/numeric/interval/rounding.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/* Boost interval/rounding.hpp template implementation file
|
||||
*
|
||||
* Copyright 2002-2003 Hervé Brö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
|
||||
232
include/boost/numeric/interval/transc.hpp
Normal file
232
include/boost/numeric/interval/transc.hpp
Normal file
@@ -0,0 +1,232 @@
|
||||
/* Boost interval/transc.hpp template implementation file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002 Hervé Brö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
|
||||
335
include/boost/numeric/interval/utility.hpp
Normal file
335
include/boost/numeric/interval/utility.hpp
Normal file
@@ -0,0 +1,335 @@
|
||||
/* Boost interval/utility.hpp template implementation file
|
||||
*
|
||||
* Copyright 2000 Jens Maurer
|
||||
* Copyright 2002-2003 Hervé Brö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/numeric/interval/utility_fwd.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)
|
||||
{
|
||||
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
|
||||
172
include/boost/numeric/interval/utility_fwd.hpp
Normal file
172
include/boost/numeric/interval/utility_fwd.hpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/* Boost interval/utility.hpp template interface file
|
||||
*
|
||||
* Copyright 2013 Cromwell D. Enage
|
||||
*
|
||||
* 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_FWD_HPP
|
||||
#define BOOST_NUMERIC_INTERVAL_UTILITY_FWD_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/numeric/interval/detail/interval_prototype.hpp>
|
||||
#include <utility>
|
||||
|
||||
/*
|
||||
* Interface of simple functions
|
||||
*/
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
|
||||
/*
|
||||
* Utility Functions
|
||||
*/
|
||||
|
||||
template<class T, class Policies>
|
||||
const T& lower(const interval<T,Policies>& x);
|
||||
|
||||
template<class T, class Policies>
|
||||
const T& upper(const interval<T,Policies>& x);
|
||||
|
||||
template<class T, class Policies>
|
||||
T checked_lower(const interval<T,Policies>& x);
|
||||
|
||||
template<class T, class Policies>
|
||||
T width(const interval<T,Policies>& x);
|
||||
|
||||
template<class T, class Policies>
|
||||
T median(const interval<T,Policies>& x);
|
||||
|
||||
template<class T, class Policies>
|
||||
interval<T,Policies> widen(const interval<T,Policies>& x, const T& v);
|
||||
|
||||
/*
|
||||
* Set-like operations
|
||||
*/
|
||||
|
||||
template <class T, class Policies>
|
||||
bool empty(const interval<T,Policies>& x);
|
||||
|
||||
template <class T, class Policies>
|
||||
bool zero_in(const interval<T,Policies>& x);
|
||||
|
||||
template <class T, class Policies>
|
||||
bool in_zero(const interval<T,Policies>& x); // DEPRECATED
|
||||
|
||||
template <class T, class Policies>
|
||||
bool in(const T& x, const interval<T,Policies>& y);
|
||||
|
||||
template <class T, class Policies>
|
||||
bool
|
||||
subset(
|
||||
const interval<T,Policies>& x
|
||||
, const interval<T,Policies>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies1, class Policies2>
|
||||
bool
|
||||
proper_subset(
|
||||
const interval<T,Policies1>& x
|
||||
, const interval<T,Policies2>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies1, class Policies2>
|
||||
bool
|
||||
overlap(
|
||||
const interval<T,Policies1>& x
|
||||
, const interval<T,Policies2>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
bool singleton(const interval<T, Policies>& x);
|
||||
|
||||
template <class T, class Policies1, class Policies2>
|
||||
bool
|
||||
equal(
|
||||
const interval<T,Policies1>& x
|
||||
, const interval<T,Policies2>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T, Policies>
|
||||
intersect(
|
||||
const interval<T,Policies>& x
|
||||
, const interval<T,Policies>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T, Policies>
|
||||
hull(const interval<T,Policies>& x, const interval<T,Policies>& y);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T, Policies>
|
||||
hull(const interval<T,Policies>& x, const T& y);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T, Policies>
|
||||
hull(const T& x, const interval<T,Policies>& y);
|
||||
|
||||
template <class T>
|
||||
interval<T> hull(const T& x, const T& y);
|
||||
|
||||
template <class T, class Policies>
|
||||
std::pair<interval<T,Policies>,interval<T,Policies> >
|
||||
bisect(const interval<T,Policies>& x);
|
||||
|
||||
/*
|
||||
* Elementary functions
|
||||
*/
|
||||
|
||||
template <class T, class Policies>
|
||||
T norm(const interval<T,Policies>& x);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies> abs(const interval<T,Policies>& x);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies>
|
||||
max BOOST_PREVENT_MACRO_SUBSTITUTION (
|
||||
const interval<T,Policies>& x
|
||||
, const interval<T,Policies>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies>
|
||||
max BOOST_PREVENT_MACRO_SUBSTITUTION (
|
||||
const interval<T,Policies>& x
|
||||
, const T& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies>
|
||||
max BOOST_PREVENT_MACRO_SUBSTITUTION (
|
||||
const T& x
|
||||
, const interval<T,Policies>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies>
|
||||
min BOOST_PREVENT_MACRO_SUBSTITUTION (
|
||||
const interval<T,Policies>& x
|
||||
, const interval<T,Policies>& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies>
|
||||
min BOOST_PREVENT_MACRO_SUBSTITUTION (
|
||||
const interval<T,Policies>& x
|
||||
, const T& y
|
||||
);
|
||||
|
||||
template <class T, class Policies>
|
||||
interval<T,Policies>
|
||||
min BOOST_PREVENT_MACRO_SUBSTITUTION (
|
||||
const T& x
|
||||
, const interval<T,Policies>& y
|
||||
);
|
||||
}} // namespace boost::numeric
|
||||
|
||||
#endif // include guard
|
||||
|
||||
87
include/boost/numeric/odeint.hpp
Normal file
87
include/boost/numeric/odeint.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint.hpp
|
||||
|
||||
[begin_description]
|
||||
Forward include for odeint. Includes nearly everything.
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2013 Karsten Ahnert
|
||||
Copyright 2010-2013 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/velocity_verlet.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/adams_bashforth_moulton.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/adaptive_adams_bashforth_moulton.hpp>
|
||||
#include <boost/numeric/odeint/stepper/controlled_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>
|
||||
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/algebra/multi_array_algebra.hpp>
|
||||
#include <boost/numeric/odeint/util/multi_array_adaption.hpp>
|
||||
/*
|
||||
* Including this algebra slows down the compilation time
|
||||
*/
|
||||
// #include <boost/numeric/odeint/algebra/fusion_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/integrate/max_step_checker.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/generation.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/iterator/adaptive_iterator.hpp>
|
||||
#include <boost/numeric/odeint/iterator/adaptive_time_iterator.hpp>
|
||||
#include <boost/numeric/odeint/iterator/const_step_iterator.hpp>
|
||||
#include <boost/numeric/odeint/iterator/const_step_time_iterator.hpp>
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_HPP_INCLUDED
|
||||
86
include/boost/numeric/odeint/algebra/algebra_dispatcher.hpp
Normal file
86
include/boost/numeric/odeint/algebra/algebra_dispatcher.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/algebra_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
Algebra dispatcher to automatically chose suitable algebra.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 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_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
|
||||
#include <type_traits>
|
||||
#include <complex>
|
||||
#include <array>
|
||||
|
||||
#include <boost/numeric/odeint/config.hpp>
|
||||
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
|
||||
#include <boost/numeric/odeint/algebra/array_algebra.hpp>
|
||||
#include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< class StateType , class Enabler = void >
|
||||
struct algebra_dispatcher_sfinae
|
||||
{
|
||||
// range_algebra is the standard algebra
|
||||
typedef range_algebra algebra_type;
|
||||
};
|
||||
|
||||
template< class StateType >
|
||||
struct algebra_dispatcher : algebra_dispatcher_sfinae< StateType > { };
|
||||
|
||||
// specialize for array
|
||||
template< class T , size_t N >
|
||||
struct algebra_dispatcher< std::array< T , N > >
|
||||
{
|
||||
typedef array_algebra algebra_type;
|
||||
};
|
||||
|
||||
//specialize for some integral types
|
||||
template< typename T >
|
||||
struct algebra_dispatcher_sfinae< T , typename std::enable_if< std::is_floating_point< T >::value >::type >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct algebra_dispatcher< std::complex<T> >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
///* think about that again....
|
||||
// specialize for ublas vector and matrix types
|
||||
template< class T , class A >
|
||||
struct algebra_dispatcher< boost::numeric::ublas::vector< T , A > >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
template< class T , class L , class A >
|
||||
struct algebra_dispatcher< boost::numeric::ublas::matrix< T , L , A > >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
//*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
293
include/boost/numeric/odeint/algebra/array_algebra.hpp
Normal file
293
include/boost/numeric/odeint/algebra/array_algebra.hpp
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/array_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
Algebra for Arrays. Highly specialized for odeint. Const arguments are
|
||||
introduce to work with odeint.
|
||||
The Array algebra can be used for Array structures with two template
|
||||
parameters:
|
||||
Array<T, N>
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Mario Mulansky
|
||||
Copyright 2011-2012 Karsten Ahnert
|
||||
|
||||
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 <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include <boost/numeric/odeint/algebra/norm_result_type.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
struct array_algebra
|
||||
{
|
||||
//template< typename T , size_t dim , class Op >
|
||||
template < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each1( Array< T, dim > &s1, Op op )
|
||||
{
|
||||
for( size_t i=0 ; i<dim ; ++i )
|
||||
op( s1[i] );
|
||||
}
|
||||
|
||||
template < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each2( Array< T, dim > &s1, const Array< T, dim > &s2,
|
||||
Op op )
|
||||
{
|
||||
for( size_t i=0 ; i<dim ; ++i )
|
||||
op( s1[i] , s2[i] );
|
||||
}
|
||||
|
||||
template < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each3( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each3( Array< T , dim > &s1 ,
|
||||
Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 , Op op )
|
||||
{
|
||||
for( size_t i=0 ; i<dim ; ++i )
|
||||
op( s1[i] , s2[i] , s3[i] );
|
||||
}
|
||||
|
||||
template < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each4( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 , Op op )
|
||||
{
|
||||
for( size_t i=0 ; i<dim ; ++i )
|
||||
op( s1[i] , s2[i] , s3[i] , s4[i] );
|
||||
}
|
||||
|
||||
template < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each5( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each6( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each7( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each8( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each9( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each10( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const Array< T , dim > &s9 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each11( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const Array< T , dim > &s9 ,
|
||||
const Array< T , dim > &s10 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each12( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const Array< T , dim > &s9 ,
|
||||
const Array< T , dim > &s10 ,
|
||||
const Array< T , dim > &s11 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each13( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const Array< T , dim > &s9 ,
|
||||
const Array< T , dim > &s10 ,
|
||||
const Array< T , dim > &s11 ,
|
||||
const Array< T , dim > &s12 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each14( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const Array< T , dim > &s9 ,
|
||||
const Array< T , dim > &s10 ,
|
||||
const Array< T , dim > &s11 ,
|
||||
const Array< T , dim > &s12 ,
|
||||
const Array< T , dim > &s13 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim, class Op >
|
||||
static void for_each15( Array< T , dim > &s1 ,
|
||||
const Array< T , dim > &s2 ,
|
||||
const Array< T , dim > &s3 ,
|
||||
const Array< T , dim > &s4 ,
|
||||
const Array< T , dim > &s5 ,
|
||||
const Array< T , dim > &s6 ,
|
||||
const Array< T , dim > &s7 ,
|
||||
const Array< T , dim > &s8 ,
|
||||
const Array< T , dim > &s9 ,
|
||||
const Array< T , dim > &s10 ,
|
||||
const Array< T , dim > &s11 ,
|
||||
const Array< T , dim > &s12 ,
|
||||
const Array< T , dim > &s13 ,
|
||||
const Array< T , dim > &s14 ,
|
||||
const 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 < template < typename, size_t > class Array, typename T,
|
||||
size_t dim>
|
||||
static typename norm_result_type< Array< T , dim > >::type norm_inf( const Array< T , dim > &s )
|
||||
{
|
||||
BOOST_USING_STD_MAX();
|
||||
using std::abs;
|
||||
typedef typename norm_result_type< Array< T , dim > >::type result_type;
|
||||
result_type init = static_cast< result_type >( 0 );
|
||||
for( size_t i=0 ; i<dim ; ++i )
|
||||
init = max BOOST_PREVENT_MACRO_SUBSTITUTION ( init , static_cast< result_type >(abs(s[i])) );
|
||||
return init;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
|
||||
599
include/boost/numeric/odeint/algebra/default_operations.hpp
Normal file
599
include/boost/numeric/odeint/algebra/default_operations.hpp
Normal file
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
[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 2010-2012 Karsten Ahnert
|
||||
Copyright 2010-2013 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 <array>
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/detail/extract_value_type.hpp
|
||||
|
||||
[begin_description]
|
||||
Extract true value type from complex types (eg. std::complex)
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 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_EXTRACT_VALUE_TYPE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_EXTRACT_VALUE_TYPE_HPP_INCLUDED
|
||||
|
||||
#include <type_traits>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
template< typename S , typename Enabler = void >
|
||||
struct extract_value_type
|
||||
{
|
||||
typedef S type;
|
||||
};
|
||||
|
||||
// as long as value_types are defined we go down the value_type chain
|
||||
// e.g. returning S::value_type::value_type::value_type
|
||||
|
||||
template< typename S >
|
||||
struct extract_value_type< S , typename std::enable_if< has_value_type<S>::value >::type >
|
||||
: mpl::if_< std::is_same< S, typename S::value_type > ,
|
||||
mpl::identity< S > , // cut the recursion if S and S::value_type are the same
|
||||
extract_value_type< typename S::value_type > >::type
|
||||
{};
|
||||
|
||||
} } } }
|
||||
|
||||
#endif
|
||||
165
include/boost/numeric/odeint/algebra/detail/for_each.hpp
Normal file
165
include/boost/numeric/odeint/algebra/detail/for_each.hpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/detail/for_each.hpp
|
||||
|
||||
[begin_description]
|
||||
Default for_each implementations.
|
||||
[end_description]
|
||||
|
||||
Copyright 2010-2012 Karsten Ahnert
|
||||
Copyright 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
|
||||
35
include/boost/numeric/odeint/algebra/detail/macros.hpp
Normal file
35
include/boost/numeric/odeint/algebra/detail/macros.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/detail/macros.hpp
|
||||
|
||||
[begin_description]
|
||||
Some macros for type checking.
|
||||
[end_description]
|
||||
|
||||
Copyright 2010-2012 Karsten Ahnert
|
||||
Copyright 2010 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
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
//type traits aren't working with nvcc
|
||||
#ifndef __CUDACC__
|
||||
|
||||
#define BOOST_ODEINT_CHECK_CONTAINER_TYPE( Type1 , Type2 ) \
|
||||
static_assert(( std::is_same< typename std::remove_const< Type1 >::type , Type2 >::value ));
|
||||
|
||||
#else
|
||||
//empty macro for nvcc
|
||||
#define BOOST_ODEINT_CHECK_CONTAINER_TYPE( Type1 , Type2 )
|
||||
|
||||
#endif // __CUDACC__
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_MACROS_HPP_INCLUDED
|
||||
46
include/boost/numeric/odeint/algebra/detail/norm_inf.hpp
Normal file
46
include/boost/numeric/odeint/algebra/detail/norm_inf.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/detail/norm_inf.hpp
|
||||
|
||||
[begin_description]
|
||||
Default reduce implementation.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 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_NORM_INF_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_NORM_INF_HPP_INCLUDED
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
template< typename Value , class Iterator1 >
|
||||
inline Value norm_inf( Iterator1 first1 , Iterator1 last1 , Value init )
|
||||
{
|
||||
using std::max;
|
||||
using std::abs;
|
||||
for( ; first1 != last1 ; )
|
||||
init = max( init , abs( *first1++ ) );
|
||||
return init;
|
||||
}
|
||||
|
||||
|
||||
} // detail
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_DETAIL_NORM_INF_HPP_INCLUDED
|
||||
216
include/boost/numeric/odeint/algebra/fusion_algebra.hpp
Normal file
216
include/boost/numeric/odeint/algebra/fusion_algebra.hpp
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/fusion_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
Algebra for boost::fusion sequences.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-2013 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 <algorithm>
|
||||
|
||||
#include <boost/numeric/odeint/config.hpp>
|
||||
|
||||
#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 {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template< class Value >
|
||||
struct fusion_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;
|
||||
};
|
||||
}
|
||||
|
||||
/* specialize this if the fundamental numeric type in your fusion sequence is
|
||||
* anything else but double (most likely not)
|
||||
*/
|
||||
template< typename Sequence >
|
||||
struct fusion_traits {
|
||||
typedef double value_type;
|
||||
};
|
||||
|
||||
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 )
|
||||
{
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( BOOST_FUSION_INVOKE_MAX_ARITY >= 11 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( BOOST_FUSION_INVOKE_MAX_ARITY >= 12 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( BOOST_FUSION_INVOKE_MAX_ARITY >= 13 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( BOOST_FUSION_INVOKE_MAX_ARITY >= 14 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
|
||||
static_assert( 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 )
|
||||
{
|
||||
static_assert( BOOST_FUSION_INVOKE_MAX_ARITY >= 15 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" );
|
||||
static_assert( 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 S >
|
||||
static typename fusion_traits< S >::value_type norm_inf( const S &s )
|
||||
{
|
||||
typedef typename fusion_traits< S >::value_type value_type;
|
||||
return boost::fusion::accumulate( s , static_cast<value_type>(0) ,
|
||||
detail::fusion_maximum<value_type>() );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/fusion_algebra_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 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_DISPATCHER_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_DISPATCHER_HPP_DEFINED
|
||||
|
||||
#include <boost/numeric/odeint/algebra/fusion_algebra.hpp>
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/fusion/include/is_sequence.hpp>
|
||||
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
// specialization for fusion sequences
|
||||
template< class FusionSequence >
|
||||
struct algebra_dispatcher_sfinae< FusionSequence ,
|
||||
typename boost::enable_if<
|
||||
typename boost::fusion::traits::is_sequence< FusionSequence >::type >::type >
|
||||
{
|
||||
typedef fusion_algebra algebra_type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_DISPATCHER_HPP_DEFINED
|
||||
146
include/boost/numeric/odeint/algebra/multi_array_algebra.hpp
Normal file
146
include/boost/numeric/odeint/algebra/multi_array_algebra.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/multi_array_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[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_ALGEBRA_MULTI_ARRAY_ALGEBRA_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_MULTI_ARRAY_ALGEBRA_HPP_DEFINED
|
||||
|
||||
|
||||
#include <boost/multi_array.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/algebra/detail/for_each.hpp>
|
||||
#include <boost/numeric/odeint/algebra/detail/norm_inf.hpp>
|
||||
#include <boost/numeric/odeint/algebra/norm_result_type.hpp>
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
// not ready
|
||||
struct multi_array_algebra
|
||||
{
|
||||
template< class S1 , class Op >
|
||||
static void for_each1( S1 &s1 , Op op )
|
||||
{
|
||||
detail::for_each1( s1.data() , s1.data() + s1.num_elements() , op );
|
||||
}
|
||||
|
||||
template< class S1 , class S2 , class Op >
|
||||
static void for_each2( S1 &s1 , S2 &s2 , Op op )
|
||||
{
|
||||
detail::for_each2( s1.data() , s1.data() + s1.num_elements() , s2.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , s10.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , s10.data() , s11.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , s10.data() , s11.data() , s12.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , s10.data() , s11.data() , s12.data() , s13.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , s10.data() , s11.data() , s12.data() , s13.data() , s14.data() , 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( s1.data() , s1.data() + s1.num_elements() , s2.data() , s3.data() , s4.data() , s5.data() , s6.data() , s7.data() , s8.data() , s9.data() , s10.data() , s11.data() , s12.data() , s13.data() , s14.data() , s15.data() , op );
|
||||
}
|
||||
|
||||
template< typename S >
|
||||
static typename norm_result_type<S>::type norm_inf( const S &s )
|
||||
{
|
||||
return detail::norm_inf( s.data() , s.data() + s.num_elements() , static_cast< typename norm_result_type<S>::type >( 0 ) );
|
||||
}
|
||||
};
|
||||
|
||||
template< class T , size_t N >
|
||||
struct algebra_dispatcher< boost::multi_array< T , N > >
|
||||
{
|
||||
typedef multi_array_algebra algebra_type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_MULTI_ARRAY_ALGEBRA_HPP_DEFINED
|
||||
33
include/boost/numeric/odeint/algebra/norm_result_type.hpp
Normal file
33
include/boost/numeric/odeint/algebra/norm_result_type.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/norm_result_type.hpp
|
||||
|
||||
[begin_description]
|
||||
Calculates the type of the norm_inf operation for container types
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 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_NORM_RESULT_TYPE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_NORM_RESULT_TYPE_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/algebra/detail/extract_value_type.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< typename S , typename Enabler = void >
|
||||
struct norm_result_type {
|
||||
typedef typename detail::extract_value_type< S >::type type;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/operations_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
Operations dispatcher to automatically chose suitable operations.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 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_OPERATIONS_DISPATCHER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_ALGEBRA_OPERATIONS_DISPATCHER_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/algebra/default_operations.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< class StateType , class Enabler = void >
|
||||
struct operations_dispatcher_sfinae
|
||||
{
|
||||
typedef default_operations operations_type;
|
||||
};
|
||||
|
||||
template< class StateType >
|
||||
struct operations_dispatcher : operations_dispatcher_sfinae< StateType > {};
|
||||
|
||||
// no further specializations required
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
142
include/boost/numeric/odeint/algebra/range_algebra.hpp
Normal file
142
include/boost/numeric/odeint/algebra/range_algebra.hpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/algebra/range_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
Default algebra, which works with the most state types, like vector< double >, std::array< double >, boost::range.
|
||||
Internally is uses boost::range to obtain the begin and end iterator of the according sequence.
|
||||
[end_description]
|
||||
|
||||
Copyright 2010-2013 Karsten Ahnert
|
||||
Copyright 2010-2013 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/norm_inf.hpp>
|
||||
#include <boost/numeric/odeint/algebra/norm_result_type.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< typename S >
|
||||
static typename norm_result_type<S>::type norm_inf( const S &s )
|
||||
{
|
||||
return detail::norm_inf( boost::begin( s ) , boost::end( s ) ,
|
||||
static_cast< typename norm_result_type<S>::type >( 0 ) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_RANGE_ALGEBRA_HPP_INCLUDED
|
||||
175
include/boost/numeric/odeint/algebra/vector_space_algebra.hpp
Normal file
175
include/boost/numeric/odeint/algebra/vector_space_algebra.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
[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 2010-2012 Karsten Ahnert
|
||||
Copyright 2010-2013 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 <complex>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
/*
|
||||
* This class template has to be overload in order to call vector_space_algebra::norm_inf
|
||||
*/
|
||||
template< class State, class Enabler = void > struct vector_space_norm_inf;
|
||||
|
||||
/*
|
||||
* Example: instantiation for sole doubles and complex
|
||||
*/
|
||||
template<>
|
||||
struct vector_space_norm_inf< double >
|
||||
{
|
||||
typedef double result_type;
|
||||
double operator()( double x ) const
|
||||
{
|
||||
using std::abs;
|
||||
return abs(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct vector_space_norm_inf< float >
|
||||
{
|
||||
typedef float result_type;
|
||||
result_type operator()( float x ) const
|
||||
{
|
||||
using std::abs;
|
||||
return abs(x);
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct vector_space_norm_inf< std::complex<T> >
|
||||
{
|
||||
typedef T result_type;
|
||||
result_type operator()( std::complex<T> x ) const
|
||||
{
|
||||
using std::abs;
|
||||
return abs( x );
|
||||
}
|
||||
};
|
||||
|
||||
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 S >
|
||||
static typename boost::numeric::odeint::vector_space_norm_inf< S >::result_type norm_inf( const S &s )
|
||||
{
|
||||
boost::numeric::odeint::vector_space_norm_inf< S > n;
|
||||
return n( s );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_ALGEBRA_VECTOR_SPACE_ALGEBRA_HPP_INCLUDED
|
||||
53
include/boost/numeric/odeint/config.hpp
Normal file
53
include/boost/numeric/odeint/config.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
[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 2011-2012 Mario Mulansky
|
||||
Copyright 2011-2012 Karsten Ahnert
|
||||
|
||||
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 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
|
||||
#define BOOST_NUMERIC_ODEINT_CXX11 1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_CONFIG_HPP_INCLUDED
|
||||
55
include/boost/numeric/odeint/external/blaze/blaze_algebra_dispatcher.hpp
vendored
Normal file
55
include/boost/numeric/odeint/external/blaze/blaze_algebra_dispatcher.hpp
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/blaze/blaze_algebra_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[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_EXTERNAL_BLAZE_BLAZE_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_BLAZE_BLAZE_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
#include <blaze/math/dense/StaticVector.h>
|
||||
#include <blaze/math/dense/DynamicVector.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< typename T , size_t N , bool TF >
|
||||
struct algebra_dispatcher< blaze::StaticVector< T , N , TF > >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
template< typename T , bool TF >
|
||||
struct algebra_dispatcher< blaze::DynamicVector< T , TF > >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_BLAZE_BLAZE_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
64
include/boost/numeric/odeint/external/blaze/blaze_resize.hpp
vendored
Normal file
64
include/boost/numeric/odeint/external/blaze/blaze_resize.hpp
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/blaze/blaze_resize.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[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_EXTERNAL_BLAZE_BLAZE_RESIZE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_BLAZE_BLAZE_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 <blaze/math/dense/DynamicVector.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< typename T , bool TF >
|
||||
struct is_resizeable< blaze::DynamicVector< T , TF > >
|
||||
{
|
||||
typedef std::true_type type;
|
||||
const static bool value = type::value;
|
||||
};
|
||||
|
||||
template< typename T1 , bool TF1, typename T2 , bool TF2 >
|
||||
struct same_size_impl< blaze::DynamicVector< T1 , TF1 > , blaze::DynamicVector< T2 , TF2 > >
|
||||
{
|
||||
static bool same_size( const blaze::DynamicVector< T1 , TF1 > &x1 , const blaze::DynamicVector< T2 , TF2 > &x2 )
|
||||
{
|
||||
return x1.size() == x2.size();
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T1 , bool TF1, typename T2 , bool TF2 >
|
||||
struct resize_impl< blaze::DynamicVector< T1 , TF1 > , blaze::DynamicVector< T2 , TF2 > >
|
||||
{
|
||||
static void resize( blaze::DynamicVector< T1 , TF1 > &x1 , const blaze::DynamicVector< T2 , TF2 > &x2 )
|
||||
{
|
||||
x1.resize( x2.size() );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_BLAZE_BLAZE_RESIZE_HPP_INCLUDED
|
||||
27
include/boost/numeric/odeint/external/compute/compute.hpp
vendored
Normal file
27
include/boost/numeric/odeint/external/compute/compute.hpp
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/compute/compute.hpp
|
||||
|
||||
[begin_description]
|
||||
includes all headers required for using odeint with Boost.Compute
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2013 Karsten Ahnert
|
||||
Copyright 2009-2013 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_COMPUTE_COMPUTE_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_HPP_DEFINED
|
||||
|
||||
#include <boost/numeric/odeint/external/compute/compute_algebra.hpp>
|
||||
#include <boost/numeric/odeint/external/compute/compute_operations.hpp>
|
||||
#include <boost/numeric/odeint/external/compute/compute_algebra_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/external/compute/compute_operations_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/external/compute/compute_resize.hpp>
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_HPP_DEFINED
|
||||
65
include/boost/numeric/odeint/external/compute/compute_algebra.hpp
vendored
Normal file
65
include/boost/numeric/odeint/external/compute/compute_algebra.hpp
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/compute/compute_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
An algebra for Boost.Compute 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_COMPUTE_COMPUTE_ALGEBRA_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_ALGEBRA_HPP_DEFINED
|
||||
|
||||
#include <boost/preprocessor/repetition.hpp>
|
||||
#include <boost/compute.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
struct compute_algebra
|
||||
{
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_STATE_PARAM(z, n, unused) \
|
||||
StateType ## n &s ## n,
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_ALGEBRA(z, n, unused) \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, class StateType), class Operation > \
|
||||
static void for_each ## n( \
|
||||
BOOST_PP_REPEAT(n, BOOST_ODEINT_COMPUTE_STATE_PARAM, ~) \
|
||||
Operation op \
|
||||
) \
|
||||
{ \
|
||||
op( BOOST_PP_ENUM_PARAMS(n, s) ); \
|
||||
}
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(3, 9, BOOST_ODEINT_COMPUTE_ALGEBRA, ~)
|
||||
|
||||
#undef BOOST_ODEINT_COMPUTE_ALGEBRA
|
||||
#undef BOOST_ODEINT_COMPUTE_STATE_PARAM
|
||||
|
||||
template < class S >
|
||||
static typename S::value_type norm_inf( const S &s ) {
|
||||
typedef typename S::value_type value_type;
|
||||
|
||||
BOOST_COMPUTE_FUNCTION(value_type, max_abs, (value_type, value_type),
|
||||
{
|
||||
return max(_1, fabs(_2));
|
||||
});
|
||||
|
||||
return boost::compute::accumulate(s.begin(), s.end(), value_type(), max_abs);
|
||||
}
|
||||
};
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
41
include/boost/numeric/odeint/external/compute/compute_algebra_dispatcher.hpp
vendored
Normal file
41
include/boost/numeric/odeint/external/compute/compute_algebra_dispatcher.hpp
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/compute/compute_algebra_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
algebra_dispatcher specialization for Boost.Compute
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2013 Karsten Ahnert
|
||||
Copyright 2009-2013 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_COMPUTE_COMPUTE_ALGEBRA_DISPATCHER_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_ALGEBRA_DISPATCHER_HPP_DEFINED
|
||||
|
||||
#include <boost/compute/container/vector.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/external/compute/compute_algebra.hpp>
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
// specialization for Boost.Compute vector
|
||||
template< class T , class A >
|
||||
struct algebra_dispatcher< boost::compute::vector< T , A > >
|
||||
{
|
||||
typedef compute_algebra algebra_type;
|
||||
};
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_ALGEBRA_DISPATCHER_HPP_DEFINED
|
||||
198
include/boost/numeric/odeint/external/compute/compute_operations.hpp
vendored
Normal file
198
include/boost/numeric/odeint/external/compute/compute_operations.hpp
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/compute/compute_operations.hpp
|
||||
|
||||
[begin_description]
|
||||
Operations of Boost.Compute zipped iterators. Is the counterpart of the compute_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_COMPUTE_COMPUTE_OPERATIONS_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_OPERATIONS_HPP_DEFINED
|
||||
|
||||
#include <boost/preprocessor/repetition.hpp>
|
||||
#include <boost/compute.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
struct compute_operations {
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_TEMPL_FAC(z, n, unused) \
|
||||
, class Fac ## n = BOOST_PP_CAT(Fac, BOOST_PP_DEC(n))
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_MEMB_FAC(z, n, unused) \
|
||||
const Fac ## n m_alpha ## n;
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_PRM_FAC(z, n, unused) \
|
||||
BOOST_PP_COMMA_IF(n) const Fac ## n alpha ## n
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_INIT_FAC(z, n, unused) \
|
||||
BOOST_PP_COMMA_IF(n) m_alpha ## n (alpha ## n)
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_PRM_STATE(z, n, unused) \
|
||||
BOOST_PP_COMMA_IF(n) StateType ## n &s ## n
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_BEGIN_STATE(z, n, unused) \
|
||||
BOOST_PP_COMMA_IF( BOOST_PP_DEC(n) ) s ## n.begin()
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_END_STATE(z, n, unused) \
|
||||
BOOST_PP_COMMA_IF( BOOST_PP_DEC(n) ) s ## n.end()
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_LAMBDA(z, n, unused) \
|
||||
BOOST_PP_EXPR_IF(n, +) m_alpha ## n * bc::lambda::get< n >(bc::_1)
|
||||
|
||||
#define BOOST_ODEINT_COMPUTE_OPERATIONS(z, n, unused) \
|
||||
template< \
|
||||
class Fac0 = double \
|
||||
BOOST_PP_REPEAT_FROM_TO(1, n, BOOST_ODEINT_COMPUTE_TEMPL_FAC, ~) \
|
||||
> \
|
||||
struct scale_sum ## n { \
|
||||
BOOST_PP_REPEAT(n, BOOST_ODEINT_COMPUTE_MEMB_FAC, ~) \
|
||||
scale_sum ## n( \
|
||||
BOOST_PP_REPEAT(n, BOOST_ODEINT_COMPUTE_PRM_FAC, ~) \
|
||||
) \
|
||||
: BOOST_PP_REPEAT(n, BOOST_ODEINT_COMPUTE_INIT_FAC, ~) \
|
||||
{ } \
|
||||
template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), class StateType) > \
|
||||
void operator()( \
|
||||
BOOST_PP_REPEAT( \
|
||||
BOOST_PP_INC(n), \
|
||||
BOOST_ODEINT_COMPUTE_PRM_STATE, ~) \
|
||||
) const \
|
||||
{ \
|
||||
namespace bc = boost::compute; \
|
||||
bc::transform( \
|
||||
bc::make_zip_iterator( \
|
||||
boost::make_tuple( \
|
||||
BOOST_PP_REPEAT_FROM_TO( \
|
||||
1, BOOST_PP_INC(n), \
|
||||
BOOST_ODEINT_COMPUTE_BEGIN_STATE, ~) \
|
||||
) \
|
||||
), \
|
||||
bc::make_zip_iterator( \
|
||||
boost::make_tuple( \
|
||||
BOOST_PP_REPEAT_FROM_TO( \
|
||||
1, BOOST_PP_INC(n), \
|
||||
BOOST_ODEINT_COMPUTE_END_STATE, ~) \
|
||||
) \
|
||||
), \
|
||||
s0.begin(), \
|
||||
BOOST_PP_REPEAT(n, BOOST_ODEINT_COMPUTE_LAMBDA, ~) \
|
||||
); \
|
||||
} \
|
||||
};
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(2, 8, BOOST_ODEINT_COMPUTE_OPERATIONS, ~)
|
||||
|
||||
#undef BOOST_ODEINT_COMPUTE_TEMPL_FAC
|
||||
#undef BOOST_ODEINT_COMPUTE_MEMB_FAC
|
||||
#undef BOOST_ODEINT_COMPUTE_PRM_FAC
|
||||
#undef BOOST_ODEINT_COMPUTE_INIT_FAC
|
||||
#undef BOOST_ODEINT_COMPUTE_PRM_STATE
|
||||
#undef BOOST_ODEINT_COMPUTE_BEGIN_STATE
|
||||
#undef BOOST_ODEINT_COMPUTE_END_STATE
|
||||
#undef BOOST_ODEINT_COMPUTE_LAMBDA
|
||||
#undef BOOST_ODEINT_COMPUTE_OPERATIONS
|
||||
|
||||
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 State0, class State1, class State2>
|
||||
void operator()(State0 &s0, State1 &s1, State2 &s2) const {
|
||||
namespace bc = boost::compute;
|
||||
|
||||
bc::command_queue &queue = bc::system::default_queue();
|
||||
const bc::context &context = queue.get_context();
|
||||
|
||||
const char source[] = BOOST_COMPUTE_STRINGIZE_SOURCE(
|
||||
kernel void scale_sum_swap2(
|
||||
F1 a1, F2 a2,
|
||||
global T0 *x0, global T1 *x1, global T2 *x2,
|
||||
)
|
||||
{
|
||||
uint i = get_global_id(0);
|
||||
T0 tmp = x0[i];
|
||||
x0[i] = a1 * x1[i] + a2 * x2[i];
|
||||
x1[i] = tmp;
|
||||
}
|
||||
);
|
||||
|
||||
std::stringstream options;
|
||||
options
|
||||
<< " -DT0=" << bc::type_name<typename State0::value_type>()
|
||||
<< " -DT1=" << bc::type_name<typename State1::value_type>()
|
||||
<< " -DT2=" << bc::type_name<typename State2::value_type>()
|
||||
<< " -DF1=" << bc::type_name<Fac1>()
|
||||
<< " -DF2=" << bc::type_name<Fac2>();
|
||||
|
||||
bc::program program =
|
||||
bc::program::build_with_source(source, context, options.str());
|
||||
|
||||
bc::kernel kernel(program, "scale_sum_swap2");
|
||||
kernel.set_arg(0, m_alpha1);
|
||||
kernel.set_arg(1, m_alpha2);
|
||||
kernel.set_arg(2, s0.get_buffer());
|
||||
kernel.set_arg(3, s1.get_buffer());
|
||||
kernel.set_arg(4, s2.get_buffer());
|
||||
|
||||
queue.enqueue_1d_range_kernel(kernel, 0, s0.size());
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
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 State0, class State1, class State2>
|
||||
void operator()(State0 &s0, State1 &s1, State2 &s2) const {
|
||||
namespace bc = boost::compute;
|
||||
using bc::_1;
|
||||
using bc::lambda::get;
|
||||
|
||||
bc::for_each(
|
||||
bc::make_zip_iterator(
|
||||
boost::make_tuple(
|
||||
s0.begin(),
|
||||
s1.begin(),
|
||||
s2.begin()
|
||||
)
|
||||
),
|
||||
bc::make_zip_iterator(
|
||||
boost::make_tuple(
|
||||
s0.end(),
|
||||
s1.end(),
|
||||
s2.end()
|
||||
)
|
||||
),
|
||||
get<0>(_1) = abs( get<0>(_1) ) /
|
||||
(m_eps_abs + m_eps_rel * (m_a_x * abs(get<1>(_1) + m_a_dxdt * abs(get<2>(_1)))))
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_OPERATIONS_HPP_DEFINED
|
||||
44
include/boost/numeric/odeint/external/compute/compute_operations_dispatcher.hpp
vendored
Normal file
44
include/boost/numeric/odeint/external/compute/compute_operations_dispatcher.hpp
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/compute/compute_operations_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
operations_dispatcher specialization for Boost.Compute
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2013 Karsten Ahnert
|
||||
Copyright 2009-2013 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_COMPUTE_COMPUTE_OPERATIONS_DISPATCHER_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_OPERATIONS_DISPATCHER_HPP_DEFINED
|
||||
|
||||
#include <boost/compute/container/vector.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/external/compute/compute_operations.hpp>
|
||||
#include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
// specialization for Boost.Compute vector
|
||||
template< class T , class A >
|
||||
struct operations_dispatcher< boost::compute::vector< T , A > >
|
||||
{
|
||||
typedef compute_operations operations_type;
|
||||
};
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_OPERATIONS_DISPATCHER_HPP_DEFINED
|
||||
92
include/boost/numeric/odeint/external/compute/compute_resize.hpp
vendored
Normal file
92
include/boost/numeric/odeint/external/compute/compute_resize.hpp
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/compute/compute_resize.hpp
|
||||
|
||||
[begin_description]
|
||||
Enable resizing for Boost.Compute 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_COMPUTE_COMPUTE_RESIZE_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_RESIZE_HPP_DEFINED
|
||||
|
||||
#include <boost/compute/container/vector.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/util/copy.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< class T, class A >
|
||||
struct is_resizeable< boost::compute::vector< T , A > >
|
||||
{
|
||||
struct type : public std::true_type { };
|
||||
const static bool value = type::value;
|
||||
};
|
||||
|
||||
template< class T, class A >
|
||||
struct same_size_impl< boost::compute::vector< T, A > , boost::compute::vector< T, A > >
|
||||
{
|
||||
static bool same_size( const boost::compute::vector< T, A > &x , const boost::compute::vector< T, A > &y )
|
||||
{
|
||||
return x.size() == y.size();
|
||||
}
|
||||
};
|
||||
|
||||
template< class T, class A >
|
||||
struct resize_impl< boost::compute::vector< T, A > , boost::compute::vector< T, A > >
|
||||
{
|
||||
static void resize( boost::compute::vector< T, A > &x , const boost::compute::vector< T, A > &y )
|
||||
{
|
||||
x.resize( y.size() );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< class Container1, class T, class A >
|
||||
struct copy_impl< Container1 , boost::compute::vector< T, A > >
|
||||
{
|
||||
static void copy( const Container1 &from , boost::compute::vector< T, A > &to )
|
||||
{
|
||||
boost::compute::copy( boost::begin( from ) , boost::end( from ) , boost::begin( to ) );
|
||||
}
|
||||
};
|
||||
|
||||
template< class T, class A, class Container2 >
|
||||
struct copy_impl< boost::compute::vector< T, A > , Container2 >
|
||||
{
|
||||
static void copy( const boost::compute::vector< T, A > &from , Container2 &to )
|
||||
{
|
||||
boost::compute::copy( boost::begin( from ) , boost::end( from ) , boost::begin( to ) );
|
||||
}
|
||||
};
|
||||
|
||||
template< class T, class A >
|
||||
struct copy_impl< boost::compute::vector< T, A > , boost::compute::vector< T, A > >
|
||||
{
|
||||
static void copy( const boost::compute::vector< T, A > &from , boost::compute::vector< T, A > &to )
|
||||
{
|
||||
boost::compute::copy( boost::begin( from ) , boost::end( from ) , boost::begin( to ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // odeint
|
||||
} // numeric
|
||||
} // boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_RESIZE_HPP_DEFINED
|
||||
27
include/boost/numeric/odeint/external/eigen/eigen.hpp
vendored
Normal file
27
include/boost/numeric/odeint/external/eigen/eigen.hpp
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/eigen/eigen.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[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_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED
|
||||
|
||||
|
||||
#include <boost/numeric/odeint/external/eigen/eigen_algebra.hpp>
|
||||
#include <boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/external/eigen/eigen_resize.hpp>
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED
|
||||
98
include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp
vendored
Normal file
98
include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/eigen/eigen_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Christian Shelton
|
||||
Copyright 2013 Karsten Ahnert
|
||||
|
||||
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_EIGEN_EIGEN_ALGEBRA_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_ALGEBRA_HPP_INCLUDED
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
|
||||
|
||||
// Necessary routines for Eigen matrices to work with vector_space_algebra
|
||||
// from odeint
|
||||
// (that is, it lets odeint treat the eigen matrices correctly, knowing
|
||||
// how to add, multiply, compute the norm, etc)
|
||||
namespace Eigen {
|
||||
|
||||
template<typename D>
|
||||
inline const
|
||||
typename Eigen::CwiseBinaryOp<
|
||||
internal::scalar_sum_op<typename internal::traits<D>::Scalar>,
|
||||
typename DenseBase<D>::ConstantReturnType,
|
||||
const D>
|
||||
operator+(const typename Eigen::MatrixBase<D> &m,
|
||||
const typename Eigen::internal::traits<D>::Scalar &s) {
|
||||
return CwiseBinaryOp<
|
||||
internal::scalar_sum_op<typename internal::traits<D>::Scalar>,
|
||||
typename DenseBase<D>::ConstantReturnType,
|
||||
const D>(DenseBase<D>::Constant(m.rows(), m.cols(), s), m.derived());
|
||||
}
|
||||
|
||||
template<typename D>
|
||||
inline const
|
||||
typename Eigen::CwiseBinaryOp<
|
||||
internal::scalar_sum_op<typename internal::traits<D>::Scalar>,
|
||||
typename DenseBase<D>::ConstantReturnType,
|
||||
const D>
|
||||
operator+(const typename Eigen::internal::traits<D>::Scalar &s,
|
||||
const typename Eigen::MatrixBase<D> &m) {
|
||||
return CwiseBinaryOp<
|
||||
internal::scalar_sum_op<typename internal::traits<D>::Scalar>,
|
||||
typename DenseBase<D>::ConstantReturnType,
|
||||
const D>(DenseBase<D>::Constant(m.rows(), m.cols(), s), m.derived());
|
||||
}
|
||||
|
||||
template<typename D1,typename D2>
|
||||
inline const
|
||||
typename Eigen::CwiseBinaryOp<
|
||||
typename Eigen::internal::scalar_quotient_op<
|
||||
typename Eigen::internal::traits<D1>::Scalar>,
|
||||
const D1, const D2>
|
||||
operator/(const Eigen::MatrixBase<D1> &x1, const Eigen::MatrixBase<D2> &x2) {
|
||||
return x1.cwiseQuotient(x2);
|
||||
}
|
||||
|
||||
|
||||
template< typename D >
|
||||
inline const
|
||||
typename Eigen::CwiseUnaryOp<
|
||||
typename Eigen::internal::scalar_abs_op<
|
||||
typename Eigen::internal::traits< D >::Scalar > ,
|
||||
const D >
|
||||
abs( const Eigen::MatrixBase< D > &m ) {
|
||||
return m.cwiseAbs();
|
||||
}
|
||||
|
||||
} // end Eigen namespace
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template<typename B,int S1,int S2,int O, int M1, int M2>
|
||||
struct vector_space_norm_inf< Eigen::Matrix<B,S1,S2,O,M1,M2> >
|
||||
{
|
||||
typedef B result_type;
|
||||
result_type operator()( const Eigen::Matrix<B,S1,S2,O,M1,M2> &m ) const
|
||||
{
|
||||
return m.template lpNorm<Eigen::Infinity>();
|
||||
}
|
||||
};
|
||||
|
||||
} } } // end boost::numeric::odeint namespace
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_ALGEBRA_HPP_INCLUDED
|
||||
49
include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp
vendored
Normal file
49
include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[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_EXTERNAL_EIGEN_EIGEN_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
template< class Derived >
|
||||
struct algebra_dispatcher_sfinae< Derived ,
|
||||
typename boost::enable_if< typename boost::is_base_of< Eigen::MatrixBase< Derived > , Derived >::type >::type >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
|
||||
template < class Derived >
|
||||
struct algebra_dispatcher_sfinae< Derived ,
|
||||
typename boost::enable_if< typename boost::is_base_of< Eigen::ArrayBase< Derived > , Derived >::type >::type >
|
||||
{
|
||||
typedef vector_space_algebra algebra_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_ALGEBRA_DISPATCHER_HPP_INCLUDED
|
||||
103
include/boost/numeric/odeint/external/eigen/eigen_resize.hpp
vendored
Normal file
103
include/boost/numeric/odeint/external/eigen/eigen_resize.hpp
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/eigen/eigen_resize.hpp
|
||||
|
||||
[begin_description]
|
||||
tba.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Ankur Sinha
|
||||
Copyright 2013 Karsten Ahnert
|
||||
|
||||
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_EIGEN_EIGEN_RESIZE_HPP_DEFINED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_RESIZE_HPP_DEFINED
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/numeric/odeint/util/is_resizeable.hpp>
|
||||
#include <boost/numeric/odeint/util/resize.hpp>
|
||||
#include <boost/numeric/odeint/util/same_size.hpp>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< class Derived >
|
||||
struct is_resizeable_sfinae< Derived ,
|
||||
typename std::enable_if< std::is_base_of< Eigen::MatrixBase< Derived > , Derived >::value >::type >
|
||||
{
|
||||
typedef std::integral_constant<bool, true> type;
|
||||
const static bool value = type::value;
|
||||
};
|
||||
|
||||
|
||||
template < class Derived >
|
||||
struct is_resizeable_sfinae< Derived ,
|
||||
typename std::enable_if< std::is_base_of< Eigen::ArrayBase< Derived > , Derived >::value >::type >
|
||||
{
|
||||
typedef std::integral_constant<bool, true> type;
|
||||
const static bool value = type::value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template< class Derived >
|
||||
struct same_size_impl_sfinae< Derived , Derived ,
|
||||
typename std::enable_if< std::is_base_of< Eigen::MatrixBase< Derived > , Derived >::value >::type >
|
||||
{
|
||||
static bool same_size( const Eigen::MatrixBase< Derived > &m1 , const Eigen::MatrixBase< Derived > &m2 )
|
||||
|
||||
{
|
||||
return ( ( m1.innerSize () == m2.innerSize () ) && ( m1.outerSize() == m2.outerSize() ) );
|
||||
}
|
||||
};
|
||||
|
||||
template< class Derived >
|
||||
struct same_size_impl_sfinae< Derived , Derived ,
|
||||
typename std::enable_if< std::is_base_of< Eigen::ArrayBase< Derived > , Derived >::value >::type >
|
||||
{
|
||||
static bool same_size( const Eigen::ArrayBase< Derived > &v1 , const Eigen::ArrayBase< Derived > &v2 )
|
||||
{
|
||||
return ( ( v1.innerSize () == v2.innerSize () ) && ( v1.outerSize() == v2.outerSize() ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template< class Derived >
|
||||
struct resize_impl_sfinae< Derived , Derived ,
|
||||
typename std::enable_if< std::is_base_of< Eigen::MatrixBase< Derived > , Derived >::value >::type >
|
||||
{
|
||||
static void resize( Eigen::MatrixBase< Derived > &m1 , const Eigen::MatrixBase< Derived > &m2 )
|
||||
{
|
||||
m1.derived().resizeLike(m2);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Derived >
|
||||
struct resize_impl_sfinae< Derived , Derived ,
|
||||
typename std::enable_if< std::is_base_of< Eigen::ArrayBase< Derived > , Derived >::value >::type >
|
||||
{
|
||||
static void resize( Eigen::ArrayBase< Derived > &v1 , const Eigen::ArrayBase< Derived > &v2 )
|
||||
{
|
||||
v1.derived().resizeLike(v2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_RESIZE_HPP_DEFINED
|
||||
228
include/boost/numeric/odeint/external/gsl/gsl_wrapper.hpp
vendored
Normal file
228
include/boost/numeric/odeint/external/gsl/gsl_wrapper.hpp
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/gsl/gsl_wrapper.hpp
|
||||
|
||||
[begin_description]
|
||||
Wrapper for gsl_vector.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2012 Mario Mulansky
|
||||
Copyright 2011 Karsten Ahnert
|
||||
|
||||
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/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 std::integral_constant<bool, true> { };
|
||||
typedef std::integral_constant<bool, true> 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
|
||||
181
include/boost/numeric/odeint/external/mkl/mkl_operations.hpp
vendored
Normal file
181
include/boost/numeric/odeint/external/mkl/mkl_operations.hpp
vendored
Normal 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 2010-2011 Mario Mulansky
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
|
||||
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
|
||||
25
include/boost/numeric/odeint/external/mpi/mpi.hpp
vendored
Normal file
25
include/boost/numeric/odeint/external/mpi/mpi.hpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/mpi/mpi.hpp
|
||||
|
||||
[begin_description]
|
||||
Wrappers for MPI.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 Mario Mulansky
|
||||
Copyright 2013 Pascal Germroth
|
||||
|
||||
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_MPI_MPI_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/external/mpi/mpi_vector_state.hpp>
|
||||
#include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
|
||||
|
||||
#endif
|
||||
62
include/boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp
vendored
Normal file
62
include/boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp
|
||||
|
||||
[begin_description]
|
||||
Nested parallelized algebra for MPI.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 Mario Mulansky
|
||||
Copyright 2013 Pascal Germroth
|
||||
|
||||
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_MPI_MPI_NESTED_ALGEBRA_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_NESTED_ALGEBRA_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/algebra/norm_result_type.hpp>
|
||||
#include <boost/numeric/odeint/util/n_ary_helper.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
/** \brief MPI-parallelized algebra, wrapping another algebra.
|
||||
*/
|
||||
template< class InnerAlgebra >
|
||||
struct mpi_nested_algebra
|
||||
{
|
||||
|
||||
// execute the InnerAlgebra on each node's local data.
|
||||
#define BOOST_ODEINT_GEN_BODY(n) \
|
||||
InnerAlgebra::for_each##n( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(n, s, () BOOST_PP_INTERCEPT) , \
|
||||
op \
|
||||
);
|
||||
BOOST_ODEINT_GEN_FOR_EACH(BOOST_ODEINT_GEN_BODY)
|
||||
#undef BOOST_ODEINT_GEN_BODY
|
||||
|
||||
|
||||
template< class NestedState >
|
||||
static typename norm_result_type< typename NestedState::value_type >::type norm_inf( const NestedState &s )
|
||||
{
|
||||
typedef typename norm_result_type< typename NestedState::value_type >::type result_type;
|
||||
// local maximum
|
||||
result_type value = InnerAlgebra::norm_inf( s() );
|
||||
// global maximum
|
||||
return boost::mpi::all_reduce(s.world, value, boost::mpi::maximum<result_type>());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
113
include/boost/numeric/odeint/external/mpi/mpi_state.hpp
vendored
Normal file
113
include/boost/numeric/odeint/external/mpi/mpi_state.hpp
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/mpi/mpi_state.hpp
|
||||
|
||||
[begin_description]
|
||||
A generic split state, storing partial data on each node.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 Mario Mulansky
|
||||
Copyright 2013 Pascal Germroth
|
||||
|
||||
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_MPI_MPI_STATE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <boost/mpi.hpp>
|
||||
#include <boost/numeric/odeint/util/copy.hpp>
|
||||
#include <boost/numeric/odeint/util/split.hpp>
|
||||
#include <boost/numeric/odeint/util/resize.hpp>
|
||||
#include <boost/numeric/odeint/util/same_size.hpp>
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
/** \brief A container which has its contents distributed among the nodes.
|
||||
*/
|
||||
template< class InnerState >
|
||||
struct mpi_state
|
||||
{
|
||||
typedef InnerState value_type;
|
||||
|
||||
// the node's local data.
|
||||
InnerState m_data;
|
||||
|
||||
boost::mpi::communicator world;
|
||||
|
||||
mpi_state() {}
|
||||
mpi_state(boost::mpi::communicator comm) : world(comm) {}
|
||||
|
||||
inline InnerState &operator()() { return m_data; }
|
||||
inline const InnerState &operator()() const { return m_data; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template< class InnerState >
|
||||
struct is_resizeable< mpi_state< InnerState > >
|
||||
: is_resizeable< InnerState > { };
|
||||
|
||||
|
||||
template< class InnerState1 , class InnerState2 >
|
||||
struct same_size_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
|
||||
{
|
||||
static bool same_size( const mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
|
||||
{
|
||||
const bool local = boost::numeric::odeint::same_size(x(), y());
|
||||
return boost::mpi::all_reduce(x.world, local, mpi::bitwise_and<bool>());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< class InnerState1 , class InnerState2 >
|
||||
struct resize_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
|
||||
{
|
||||
static void resize( mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
|
||||
{
|
||||
// resize local parts on each node.
|
||||
boost::numeric::odeint::resize(x(), y());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** \brief Copy data between mpi_states of same size. */
|
||||
template< class InnerState1 , class InnerState2 >
|
||||
struct copy_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
|
||||
{
|
||||
static void copy( const mpi_state< InnerState1 > &from , mpi_state< InnerState2 > &to )
|
||||
{
|
||||
// copy local parts on each node.
|
||||
boost::numeric::odeint::copy(from(), to());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** \brief Use `mpi_algebra` for `mpi_state`. */
|
||||
template< class InnerState >
|
||||
struct algebra_dispatcher< mpi_state< InnerState > >
|
||||
{
|
||||
typedef mpi_nested_algebra<
|
||||
typename algebra_dispatcher< InnerState >::algebra_type
|
||||
> algebra_type;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
95
include/boost/numeric/odeint/external/mpi/mpi_vector_state.hpp
vendored
Normal file
95
include/boost/numeric/odeint/external/mpi/mpi_vector_state.hpp
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/external/mpi/mpi_vector_state.hpp
|
||||
|
||||
[begin_description]
|
||||
Copying a container from/to an mpi_state splits/joins it.
|
||||
[end_description]
|
||||
|
||||
Copyright 2013 Karsten Ahnert
|
||||
Copyright 2013 Mario Mulansky
|
||||
Copyright 2013 Pascal Germroth
|
||||
|
||||
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_MPI_MPI_VECTOR_STATE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_VECTOR_STATE_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <boost/mpi.hpp>
|
||||
#include <boost/numeric/odeint/util/copy.hpp>
|
||||
#include <boost/numeric/odeint/util/split_adaptor.hpp>
|
||||
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/external/mpi/mpi_state.hpp>
|
||||
#include <boost/numeric/odeint/tools/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
/** \brief Split data from some container on node 0 to the slaves.
|
||||
* Source must be a model of Random Access Range. */
|
||||
template< class Source , class InnerState >
|
||||
struct split_impl< Source, mpi_state< InnerState >,
|
||||
typename boost::enable_if< boost::has_range_const_iterator<Source> >::type >
|
||||
{
|
||||
typedef typename boost::range_iterator<const Source>::type iterator;
|
||||
|
||||
static void split( const Source &from, mpi_state< InnerState > &to )
|
||||
{
|
||||
std::vector< InnerState > pieces;
|
||||
if(to.world.rank() == 0) {
|
||||
const size_t num = static_cast<size_t>(to.world.size());
|
||||
pieces.resize(num);
|
||||
for(size_t i = 0 ; i < num ; i++) {
|
||||
iterator_range<iterator> part = detail::make_split_range(from, i, num);
|
||||
boost::numeric::odeint::resize(pieces[i], part);
|
||||
boost::numeric::odeint::copy(part, pieces[i]);
|
||||
}
|
||||
}
|
||||
// send to nodes
|
||||
boost::mpi::scatter(to.world, pieces, to(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
/** \brief Merge data from an mpi_state to some container on node 0.
|
||||
* Target must be a model Single Pass Range. */
|
||||
template< class Target, class InnerState >
|
||||
struct unsplit_impl< mpi_state< InnerState >, Target,
|
||||
typename boost::enable_if< boost::has_range_iterator<Target> >::type >
|
||||
{
|
||||
typedef typename boost::range_iterator<Target>::type iterator;
|
||||
|
||||
static void unsplit( const mpi_state< InnerState > &from , Target &to )
|
||||
{
|
||||
std::vector< InnerState > pieces;
|
||||
// send data to root
|
||||
boost::mpi::gather(from.world, from(), pieces, 0);
|
||||
if(from.world.rank() == 0) {
|
||||
// check target size
|
||||
size_t total_size = 0;
|
||||
for(size_t i = 0 ; i < pieces.size() ; i++)
|
||||
total_size += boost::size(pieces[i]);
|
||||
BOOST_NUMERIC_ODEINT_ASSERT( total_size <= boost::size(to) );
|
||||
// copy parts
|
||||
iterator out = boost::begin(to);
|
||||
for(size_t i = 0 ; i < pieces.size() ; i++)
|
||||
out = boost::copy(pieces[i], out);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
161
include/boost/numeric/odeint/external/mtl4/implicit_euler_mtl4.hpp
vendored
Normal file
161
include/boost/numeric/odeint/external/mtl4/implicit_euler_mtl4.hpp
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
[begin_description]
|
||||
Modification of the implicit Euler method, works with the MTL4 matrix library only.
|
||||
[end_description]
|
||||
|
||||
Copyright 2012-2013 Andreas Angelopoulos
|
||||
Copyright 2012-2013 Karsten Ahnert
|
||||
Copyright 2012-2013 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_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, [this](auto&& arg) { return this->resize_impl<StateIn>(std::forward<decltype(arg)>(arg)); });
|
||||
|
||||
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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user