Trunc
Nearest integer floating point operations
Returns the nearest integral value not greater in magnitude than the argument.
template<FloatingPointType T>
constexpr inline T Trunc( T value ) noexcept;
Computes the nearest integer not greater in magnitude than value
.
template<IntegerType T>
constexpr inline T Trunc( T value ) noexcept
Returns value
.
Example/Test code
constexpr float value1 = -1.5f;
constexpr float value2 = -0.5f;
constexpr float value3 = -0.0f;
constexpr float value4 = 0.0f;
constexpr float value5 = 0.5f;
constexpr float value6 = 1.5f;
constexpr double result1 = Trunc( value1 );
BOOST_CHECK( result1 == -1.f );
constexpr double result2 = Trunc( value2 );
BOOST_CHECK( result2 == -0.f );
constexpr double result3 = Trunc( value3 );
BOOST_CHECK( result3 == -0.f );
constexpr double result4 = Trunc( value4 );
BOOST_CHECK( result4 == 0.f );
constexpr double result5 = Trunc( value5 );
BOOST_CHECK( result5 == 0.f );
constexpr double result6 = Trunc( value6 );
BOOST_CHECK( result6 == 1.f );