From 0e8a0f4d32b4d0194914164c980e596213c10f99 Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Wed, 16 Sep 2026 13:25:54 +0800 Subject: [PATCH] Correct the spelling of rounding_mode under the toward zero macro - cfenv.hpp wrote rounding_mde in the branch of BOOST_DECIMAL_FE_DEC_TOWARD_ZERO, thus no program which defines the macro compiled. - A new test builds with the macro and makes sure that a quotient of either sign drops its extra digits. Fixes #1457 --- include/boost/decimal/cfenv.hpp | 2 +- test/Jamfile | 1 + test/test_toward_zero_rounding.cpp | 38 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/test_toward_zero_rounding.cpp 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(); +}