Skip to content

Commit cf408fd

Browse files
committed
Temporary workaround to make abs constexpr
1 parent 51d2077 commit cf408fd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

include/boost/decimal/detail/to_integral.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
namespace boost {
2020
namespace decimal {
2121

22+
namespace detail {
23+
24+
template<typename T>
25+
constexpr auto make_me_constexpr_abs(T a) -> T { return ((a < T(0)) ? -a : a); }
26+
27+
}
28+
2229
// MSVC 14.1 warns of unary minus being applied to unsigned type from numeric_limits::min
2330
// 14.2 and on get it right
2431
#ifdef _MSC_VER
@@ -52,7 +59,7 @@ constexpr auto to_integral(Decimal val) noexcept
5259
auto result {static_cast<Conversion_Type>(val.full_significand())};
5360
auto expval {val.biased_exponent()};
5461

55-
if (std::abs(expval) >= 19)
62+
if (detail::make_me_constexpr_abs(expval) >= 19)
5663
{
5764
result = 0;
5865
}
@@ -94,7 +101,7 @@ constexpr auto to_integral_128(Decimal val) noexcept
94101
auto sig {val.full_significand()};
95102
auto expval {val.biased_exponent()};
96103

97-
if (std::abs(expval) >= 38)
104+
if (detail::make_me_constexpr_abs(expval) >= 38)
98105
{
99106
sig = 0;
100107
}

0 commit comments

Comments
 (0)