Skip to content

Commit 1603baa

Browse files
committed
Add single arg version of check non finite for nan conversions
1 parent 9a64bdf commit 1603baa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/boost/decimal/decimal32_t.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ BOOST_DECIMAL_EXPORT class decimal32_t final // NOLINT(cppcoreguidelines-special
241241
template <typename Decimal>
242242
friend constexpr Decimal detail::check_non_finite(Decimal lhs, Decimal rhs) noexcept;
243243

244+
template <typename Decimal>
245+
friend constexpr Decimal detail::check_non_finite(Decimal x) noexcept;
246+
244247
public:
245248
// 3.2.2.1 construct/copy/destroy:
246249
constexpr decimal32_t() noexcept = default;

include/boost/decimal/detail/check_non_finite.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ constexpr Decimal check_non_finite(Decimal lhs, Decimal rhs) noexcept
4343
}
4444
}
4545

46+
template <typename Decimal>
47+
constexpr Decimal check_non_finite(Decimal x) noexcept
48+
{
49+
static_assert(is_decimal_floating_point_v<Decimal>, "Types must be a decimal type");
50+
51+
if (isnan(x))
52+
{
53+
return issignaling(x) ? nan_conversion(x) : x;
54+
}
55+
56+
BOOST_DECIMAL_ASSERT(isinf(x));
57+
return x;
58+
}
59+
4660
} //namespace detail
4761
} //namespace decimal
4862
} //namespace boost

0 commit comments

Comments
 (0)