Skip to content

Commit 4094aa2

Browse files
committed
Fix handling of denormal values
1 parent 415f785 commit 4094aa2

File tree

1 file changed

+12
-1
lines changed
  • include/boost/decimal/detail/cmath

1 file changed

+12
-1
lines changed

include/boost/decimal/detail/cmath/next.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,20 @@ constexpr auto nextafter_impl(const DecimalType val, const bool direction) noexc
5353

5454
if (!isnormal(val))
5555
{
56-
// Not to make sure that denorms aren't normalized
56+
// Denorms need separate handling
5757
sig = removed_zeros.trimmed_number;
5858
exp += static_cast<int>(removed_zeros.number_of_removed_zeros);
59+
60+
if (removed_zeros.number_of_removed_zeros > 0)
61+
{
62+
// We need to shift an add
63+
// 1 -> 11 instead of 2 since 11e-101 < 2e-100 starting at 1e-100
64+
sig *= 10U;
65+
++sig;
66+
--exp;
67+
}
68+
69+
return DecimalType{sig, exp, is_neg};
5970
}
6071

6172
if (direction)

0 commit comments

Comments
 (0)