@@ -29,30 +29,32 @@ namespace decimal {
2929
3030namespace detail {
3131
32- template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T1 >
33- constexpr auto nextafter_impl (T1 val, bool direction) noexcept -> T1
32+ template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType >
33+ constexpr auto nextafter_impl (DecimalType val, bool direction) noexcept -> DecimalType
3434{
35- constexpr T1 zero {0 };
35+ constexpr DecimalType zero {0 };
3636
3737 // Val < direction = +
3838 // Val > direction = -
3939 const auto abs_val {abs (val)};
4040
4141 if (val == zero)
4242 {
43- const auto min_val {direction ? std::numeric_limits<T1 >::denorm_min () :
44- -std::numeric_limits<T1 >::denorm_min ()};
43+ const auto min_val {direction ? std::numeric_limits<DecimalType >::denorm_min () :
44+ -std::numeric_limits<DecimalType >::denorm_min ()};
4545 return min_val;
4646 }
47- if (abs_val > zero && abs_val < std::numeric_limits<T1 >::epsilon ())
47+ else if (abs_val > zero && abs_val < std::numeric_limits<DecimalType >::epsilon ())
4848 {
49- const auto min_val {direction ? val + std::numeric_limits<T1>::min () :
50- val - std::numeric_limits<T1>::min ()};
51- return min_val;
49+ auto exp {val.biased_exponent ()};
50+ auto sig {val.full_significand ()};
51+ sig = direction ? sig + 1 : sig - 1 ;
52+
53+ return {sig, exp, val.isneg ()};
5254 }
5355
54- const auto val_eps {direction ? val + std::numeric_limits<T1 >::epsilon () :
55- val - std::numeric_limits<T1 >::epsilon ()};
56+ const auto val_eps {direction ? val + std::numeric_limits<DecimalType >::epsilon () :
57+ val - std::numeric_limits<DecimalType >::epsilon ()};
5658
5759 // If adding epsilon does nothing then we need to manipulate the representation
5860 if (val == val_eps)
@@ -62,7 +64,7 @@ constexpr auto nextafter_impl(T1 val, bool direction) noexcept -> T1
6264
6365 direction ? significand++ : significand--;
6466
65- return T1 {significand, exp};
67+ return DecimalType {significand, exp};
6668 }
6769 else
6870 {
0 commit comments