less_with_sign.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/util/detail/less_with_sign.hpp
  4. [begin_description]
  5. Helper function to compare times taking into account the sign of dt
  6. [end_description]
  7. Copyright 2012-2015 Mario Mulansky
  8. Copyright 2012 Karsten Ahnert
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_LESS_WITH_SIGN_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_LESS_WITH_SIGN_HPP_INCLUDED
  15. #include <limits>
  16. #include <boost/numeric/odeint/util/unit_helper.hpp>
  17. namespace boost {
  18. namespace numeric {
  19. namespace odeint {
  20. namespace detail {
  21. /**
  22. * return t1 < t2 if dt > 0 and t1 > t2 if dt < 0 with epsilon accuracy
  23. */
  24. template< typename T >
  25. bool less_with_sign( T t1 , T t2 , T dt )
  26. {
  27. if( get_unit_value(dt) > 0 )
  28. //return t1 < t2;
  29. return t2-t1 > std::numeric_limits<T>::epsilon();
  30. else
  31. //return t1 > t2;
  32. return t1-t2 > std::numeric_limits<T>::epsilon();
  33. }
  34. /**
  35. * return t1 <= t2 if dt > 0 and t1 => t2 if dt < 0 with epsilon accuracy
  36. */
  37. template< typename T >
  38. bool less_eq_with_sign( T t1 , T t2 , T dt )
  39. {
  40. if( get_unit_value(dt) > 0 )
  41. return t1-t2 <= std::numeric_limits<T>::epsilon();
  42. else
  43. return t2-t1 <= std::numeric_limits<T>::epsilon();
  44. }
  45. template< typename T >
  46. T min_abs( T t1 , T t2 )
  47. {
  48. BOOST_USING_STD_MIN();
  49. BOOST_USING_STD_MAX();
  50. if( get_unit_value(t1)>0 )
  51. return min BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
  52. else
  53. return max BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
  54. }
  55. template< typename T >
  56. T max_abs( T t1 , T t2 )
  57. {
  58. BOOST_USING_STD_MIN();
  59. BOOST_USING_STD_MAX();
  60. if( get_unit_value(t1)>0 )
  61. return max BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
  62. else
  63. return min BOOST_PREVENT_MACRO_SUBSTITUTION ( t1 , t2 );
  64. }
  65. } } } }
  66. #endif