Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/decimal/cfenv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE auto _boost_decimal_global_rounding_mode
#elif defined(BOOST_DECIMAL_FE_DEC_TO_NEAREST_FROM_ZERO)
rounding_mode::fe_dec_to_nearest_from_zero
#elif defined (BOOST_DECIMAL_FE_DEC_TOWARD_ZERO)
rounding_mde::fe_dec_toward_zero
rounding_mode::fe_dec_toward_zero
#elif defined(BOOST_DECIMAL_FE_DEC_UPWARD)
rounding_mode::fe_dec_upward
#else
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ run test_tgamma.cpp ;
run test_to_chars.cpp ;
run test_to_string.cpp ;
run test_total_ordering.cpp ;
run test_toward_zero_rounding.cpp ;
run test_upward_rounding.cpp ;
run test_zeta.cpp ;

Expand Down
38 changes: 38 additions & 0 deletions test/test_toward_zero_rounding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2026 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

// The mode is compile time, thus the test runs on every platform
#define BOOST_DECIMAL_FE_DEC_TOWARD_ZERO

#include <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>

using namespace boost::decimal;
using namespace boost::decimal::literals;

// A quotient of either sign drops its extra digits; downward gives -0.6666667
template <typename T>
void test(const T two, const T three, const T quotient)
{
BOOST_TEST_EQ(two / three, quotient);
BOOST_TEST_EQ(-two / three, -quotient);
}

int main()
{
BOOST_TEST(_boost_decimal_global_rounding_mode == rounding_mode::fe_dec_toward_zero);
BOOST_TEST(boost::decimal::fegetround() == rounding_mode::fe_dec_toward_zero);

static_assert(-2_DF / 3_DF == -0.6666666_DF, "");
static_assert(-2_DL / 3_DL == -0.6666666666666666666666666666666666_DL, "");

test(2_DF, 3_DF, 0.6666666_DF);
test(2_DFF, 3_DFF, 0.6666666_DFF);
test(2_DD, 3_DD, 0.6666666666666666_DD);
test(2_DDF, 3_DDF, 0.6666666666666666_DDF);
test(2_DL, 3_DL, 0.6666666666666666666666666666666666_DL);
test(2_DLF, 3_DLF, 0.6666666666666666666666666666666666_DLF);

return boost::report_errors();
}
Loading