@@ -45,9 +45,29 @@ void test()
4545
4646 const auto zero_next {nextafter (zero, one)};
4747 BOOST_TEST_EQ (zero_next, std::numeric_limits<T>::denorm_min ());
48+ }
49+
50+ // Per IEEE 754 nextafter is allowed to break cohort
51+ void test_non_preserving ()
52+ {
53+ const auto val = decimal32_t {" 1e-100" };
54+ const auto two_val = decimal32_t {2 , boost::decimal::detail::etiny_v<decimal32_t >};
55+ const auto one = decimal32_t {" 1e0" };
56+ const auto next = nextafter (val,one);
57+ const auto between = decimal32_t {" 11e-101" };
4858
49- const auto two_next_zero {nextafter (zero_next, one)};
50- BOOST_TEST_EQ (two_next_zero, T (2 , detail::etiny_v<T>));
59+ BOOST_TEST_LE (val, between);
60+ BOOST_TEST_EQ (next, between);
61+ BOOST_TEST_LE (two_val, next);
62+
63+ const auto nines_value = decimal32_t {" 99e-101" };
64+ const auto next_nines_res = decimal32_t {" 991e-102" };
65+ const auto res = nextafter (nines_value, one);
66+ BOOST_TEST_EQ (res, next_nines_res);
67+
68+ const auto wrap_value = decimal32_t {" 9999999e-107" };
69+ const auto next_after_wrap = nextafter (wrap_value, one);
70+ BOOST_TEST_GT (next_after_wrap, wrap_value);
5171}
5272
5373int main ()
@@ -56,5 +76,7 @@ int main()
5676 test<decimal64_t >();
5777 test<decimal128_t >();
5878
79+ test_non_preserving ();
80+
5981 return boost::report_errors ();
6082}
0 commit comments