diff --git a/include/boost/decimal/cfenv.hpp b/include/boost/decimal/cfenv.hpp index 6636c2a65..4cbf2ed2c 100644 --- a/include/boost/decimal/cfenv.hpp +++ b/include/boost/decimal/cfenv.hpp @@ -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 diff --git a/test/Jamfile b/test/Jamfile index 47cbcc96a..54b970b42 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/test_toward_zero_rounding.cpp b/test/test_toward_zero_rounding.cpp new file mode 100644 index 000000000..05bd8f00c --- /dev/null +++ b/test/test_toward_zero_rounding.cpp @@ -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 +#include + +using namespace boost::decimal; +using namespace boost::decimal::literals; + +// A quotient of either sign drops its extra digits; downward gives -0.6666667 +template +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(); +}