iconv.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2009 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_ICONV_HPP
  6. #define BOOST_MATH_ICONV_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/math/tools/config.hpp>
  11. #include <boost/math/tools/type_traits.hpp>
  12. #include <boost/math/special_functions/round.hpp>
  13. namespace boost { namespace math { namespace detail{
  14. template <class T, class Policy>
  15. BOOST_MATH_GPU_ENABLED inline int iconv_imp(T v, Policy const&, boost::math::true_type const&)
  16. {
  17. return static_cast<int>(v);
  18. }
  19. template <class T, class Policy>
  20. BOOST_MATH_GPU_ENABLED inline int iconv_imp(T v, Policy const& pol, boost::math::false_type const&)
  21. {
  22. BOOST_MATH_STD_USING
  23. return iround(v, pol);
  24. }
  25. template <class T, class Policy>
  26. BOOST_MATH_GPU_ENABLED inline int iconv(T v, Policy const& pol)
  27. {
  28. typedef typename boost::math::is_convertible<T, int>::type tag_type;
  29. return iconv_imp(v, pol, tag_type());
  30. }
  31. }}} // namespaces
  32. #endif // BOOST_MATH_ICONV_HPP