almost_equal.ipp 524 B

1234567891011121314151617181920
  1. #ifndef BOOST_MATH_ALMOST_EQUAL_HPP
  2. #define BOOST_MATH_ALMOST_EQUAL_HPP
  3. // Copyright (c) 2006 Johan Rade
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include <cmath>
  8. template<class ValType>
  9. bool almost_equal(ValType a, ValType b)
  10. {
  11. const ValType e = static_cast<ValType>(0.00001);
  12. return (a - e * std::abs(a) <= b + e * std::abs(b))
  13. && (a + e * std::abs(a) >= b - e * std::abs(b));
  14. }
  15. #endif