3 boost/numeric/odeint/util/detail/less_with_sign.hpp
6 Helper function to compare times taking into account the sign of dt
9 Copyright 2012-2015 Mario Mulansky
10 Copyright 2012 Karsten Ahnert
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
17 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_LESS_WITH_SIGN_HPP_INCLUDED
18 #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_LESS_WITH_SIGN_HPP_INCLUDED
22 #include <boost/numeric/odeint/util/unit_helper.hpp>
30 * return t1 < t2 if dt > 0 and t1 > t2 if dt < 0 with epsilon accuracy
32 template< typename T >
33 bool less_with_sign( T t1 , T t2 , T dt )
35 if( get_unit_value(dt) > 0 )
37 return t2-t1 > std::numeric_limits<T>::epsilon();
40 return t1-t2 > std::numeric_limits<T>::epsilon();
44 * return t1 <= t2 if dt > 0 and t1 => t2 if dt < 0 with epsilon accuracy
46 template< typename T >
47 bool less_eq_with_sign( T t1 , T t2 , T dt )
49 if( get_unit_value(dt) > 0 )
50 return t1-t2 <= std::numeric_limits<T>::epsilon();
52 return t2-t1 <= std::numeric_limits<T>::epsilon();
55 template< typename T >
56 T min_abs( T t1 , T t2 )
58 BOOST_USING_STD_MIN();
59 BOOST_USING_STD_MAX();
60 if( get_unit_value(t1)>0 )
61 return min BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
63 return max BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
66 template< typename T >
67 T max_abs( T t1 , T t2 )
69 BOOST_USING_STD_MIN();
70 BOOST_USING_STD_MAX();
71 if( get_unit_value(t1)>0 )
72 return max BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
74 return min BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );