Boost
C++ Libraries
...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
This is an older version of Boost and was released in 2023. The current version is 1.89.0.
#include <boost/math/special_functions/trunc.hpp>
template <class T> T trunc(const T& v); template <class T, class Policy> T trunc(const T& v, const Policy&); template <class T> int itrunc(const T& v); template <class T, class Policy> int itrunc(const T& v, const Policy&); template <class T> long ltrunc(const T& v); template <class T, class Policy> long ltrunc(const T& v, const Policy&); template <class T> long long lltrunc(const T& v); template <class T, class Policy> long long lltrunc(const T& v, const Policy&);
The trunc functions round their argument to the integer value, nearest to but no larger in magnitude than the argument.
For example itrunc(3.7) would
return 3 and ltrunc(-4.6)
would return -4.
If the argument v is either non-finite or else outside
the range of the result type, then returns the result of rounding_error:
by default this throws an instance of boost::math::rounding_error.