workaround.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2006-7 John Maddock
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_TOOLS_WORHAROUND_HPP
  6. #define BOOST_MATH_TOOLS_WORHAROUND_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
  11. # include <math.h>
  12. #endif
  13. #include <boost/math/tools/config.hpp>
  14. namespace boost{ namespace math{ namespace tools{
  15. //
  16. // We call this short forwarding function so that we can work around a bug
  17. // on Darwin that causes std::fmod to return a NaN. The test case is:
  18. // std::fmod(1185.0L, 1.5L);
  19. //
  20. template <class T>
  21. inline T fmod_workaround(T a, T b) BOOST_MATH_NOEXCEPT(T)
  22. {
  23. BOOST_MATH_STD_USING
  24. return fmod(a, b);
  25. }
  26. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106))
  27. template <>
  28. inline long double fmod_workaround(long double a, long double b) noexcept
  29. {
  30. return ::fmodl(a, b);
  31. }
  32. #endif
  33. }}} // namespaces
  34. #endif // BOOST_MATH_TOOLS_WORHAROUND_HPP