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)
6 #ifndef BOOST_MATH_ICONV_HPP
7 #define BOOST_MATH_ICONV_HPP
13 #include <boost/math/special_functions/round.hpp>
14 #include <boost/type_traits/is_convertible.hpp>
16 namespace boost { namespace math { namespace detail{
18 template <class T, class Policy>
19 inline int iconv_imp(T v, Policy const&, mpl::true_ const&)
21 return static_cast<int>(v);
24 template <class T, class Policy>
25 inline int iconv_imp(T v, Policy const& pol, mpl::false_ const&)
28 return iround(v, pol);
31 template <class T, class Policy>
32 inline int iconv(T v, Policy const& pol)
34 typedef typename boost::is_convertible<T, int>::type tag_type;
35 return iconv_imp(v, pol, tag_type());
41 #endif // BOOST_MATH_ICONV_HPP