1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright 2022 Matt Borland. Distributed under the Boost
3 // 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_MP_DETAIL_FUNCTIONS_TRUNC_HPP
7 #define BOOST_MP_DETAIL_FUNCTIONS_TRUNC_HPP
12 #include <boost/multiprecision/detail/standalone_config.hpp>
13 #include <boost/multiprecision/detail/no_exceptions_support.hpp>
15 #ifdef BOOST_MP_MATH_AVAILABLE
16 #include <boost/math/special_functions/trunc.hpp>
19 namespace boost { namespace multiprecision { namespace detail {
24 inline T trunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
29 return (arg > 0) ? floor(arg) : ceil(arg);
34 #ifdef BOOST_MP_MATH_AVAILABLE
37 inline long long lltrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
39 return boost::math::lltrunc(arg);
43 inline int itrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
45 return boost::math::itrunc(arg);
51 inline long long lltrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
55 BOOST_MP_THROW_EXCEPTION(std::domain_error("arg cannot be converted into a long long"));
58 return static_cast<long long>(boost::multiprecision::detail::impl::trunc(arg));
62 inline int itrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
66 BOOST_MP_THROW_EXCEPTION(std::domain_error("arg cannot be converted into an int"));
69 return static_cast<int>(boost::multiprecision::detail::impl::trunc(arg));
76 #endif // BOOST_MP_DETAIL_FUNCTIONS_TRUNC_HPP