Skip to content

Commit 59ed8dd

Browse files
committed
Use sign enum is the remaining constructors
1 parent 34f7e15 commit 59ed8dd

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

include/boost/decimal/decimal128_t.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <boost/decimal/detail/chars_format.hpp>
4141
#include <boost/decimal/detail/components.hpp>
4242
#include <boost/decimal/detail/from_string.hpp>
43+
#include <boost/decimal/detail/construction_sign.hpp>
4344

4445
#ifndef BOOST_DECIMAL_BUILD_MODULE
4546

@@ -272,7 +273,7 @@ BOOST_DECIMAL_EXPORT class decimal128_t final
272273
#else
273274
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
274275
#endif
275-
constexpr decimal128_t(T1 coeff, T2 exp, bool is_negative = false) noexcept;
276+
constexpr decimal128_t(T1 coeff, T2 exp, detail::construction_sign_wrapper resultant_sign = construction_sign::positive) noexcept;
276277

277278
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
278279
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
@@ -730,8 +731,9 @@ template <BOOST_DECIMAL_UNSIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
730731
#else
731732
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
732733
#endif
733-
constexpr decimal128_t::decimal128_t(T1 coeff, T2 exp, bool is_negative) noexcept
734+
constexpr decimal128_t::decimal128_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
734735
{
736+
const auto is_negative {static_cast<bool>(resultant_sign)};
735737
bits_.high = is_negative ? detail::d128_sign_mask : UINT64_C(0);
736738

737739
// If the coeff is not in range make it so

include/boost/decimal/decimal64_t.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <boost/decimal/detail/chars_format.hpp>
4444
#include <boost/decimal/detail/to_chars_result.hpp>
4545
#include <boost/decimal/detail/from_string.hpp>
46+
#include <boost/decimal/detail/construction_sign.hpp>
4647

4748
#ifndef BOOST_DECIMAL_BUILD_MODULE
4849

@@ -335,7 +336,7 @@ BOOST_DECIMAL_EXPORT class decimal64_t final
335336
#else
336337
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
337338
#endif
338-
constexpr decimal64_t(T1 coeff, T2 exp, bool is_negative = false) noexcept;
339+
constexpr decimal64_t(T1 coeff, T2 exp, detail::construction_sign_wrapper resultant_sign = construction_sign::positive) noexcept;
339340

340341
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
341342
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
@@ -650,8 +651,9 @@ template <BOOST_DECIMAL_UNSIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
650651
#else
651652
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
652653
#endif
653-
constexpr decimal64_t::decimal64_t(T1 coeff, T2 exp, bool is_negative) noexcept
654+
constexpr decimal64_t::decimal64_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
654655
{
656+
const auto is_negative {static_cast<bool>(resultant_sign)};
655657
bits_ = is_negative ? detail::d64_sign_mask : UINT64_C(0);
656658

657659
// If the coeff is not in range, make it so

include/boost/decimal/decimal_fast128_t.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <boost/decimal/detail/chars_format.hpp>
4141
#include <boost/decimal/detail/components.hpp>
4242
#include <boost/decimal/detail/from_string.hpp>
43+
#include <boost/decimal/detail/construction_sign.hpp>
4344

4445
#ifndef BOOST_DECIMAL_BUILD_MODULE
4546

@@ -215,7 +216,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast128_t final
215216
#else
216217
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
217218
#endif
218-
constexpr decimal_fast128_t(T1 coeff, T2 exp, bool is_negative = false) noexcept;
219+
constexpr decimal_fast128_t(T1 coeff, T2 exp, detail::construction_sign_wrapper resultant_sign) noexcept;
219220

220221
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
221222
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
@@ -489,12 +490,13 @@ template <BOOST_DECIMAL_UNSIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
489490
#else
490491
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
491492
#endif
492-
constexpr decimal_fast128_t::decimal_fast128_t(T1 coeff, T2 exp, bool is_negative) noexcept
493+
constexpr decimal_fast128_t::decimal_fast128_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
493494
{
494495
using minimum_coefficient_size = std::conditional_t<(sizeof(T1) > sizeof(significand_type)), T1, significand_type>;
495496

496497
minimum_coefficient_size min_coeff {coeff};
497498

499+
const auto is_negative {static_cast<bool>(resultant_sign)};
498500
sign_ = is_negative;
499501

500502
// Normalize the significand in the constructor, so we don't have

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <boost/decimal/detail/to_chars_result.hpp>
4242
#include <boost/decimal/detail/chars_format.hpp>
4343
#include <boost/decimal/detail/from_string.hpp>
44+
#include <boost/decimal/detail/construction_sign.hpp>
4445

4546
#ifndef BOOST_DECIMAL_BUILD_MODULE
4647
#include <limits>
@@ -211,7 +212,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
211212
constexpr decimal_fast32_t() noexcept = default;
212213

213214
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
214-
constexpr decimal_fast32_t(T1 coeff, T2 exp, bool is_negative = false) noexcept;
215+
constexpr decimal_fast32_t(T1 coeff, T2 exp, detail::construction_sign_wrapper resultant_sign = construction_sign::positive) noexcept;
215216

216217
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
217218
constexpr decimal_fast32_t(T1, T2, bool) noexcept { static_assert(detail::is_unsigned_v<T1>, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
@@ -479,12 +480,13 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
479480
};
480481

481482
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
482-
constexpr decimal_fast32_t::decimal_fast32_t(T1 coeff, T2 exp, bool is_negative) noexcept
483+
constexpr decimal_fast32_t::decimal_fast32_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
483484
{
484485
using minimum_coefficient_size = std::conditional_t<(sizeof(T1) > sizeof(significand_type)), T1, significand_type>;
485486

486487
minimum_coefficient_size min_coeff {coeff};
487488

489+
const auto is_negative {static_cast<bool>(resultant_sign)};
488490
sign_ = is_negative;
489491

490492
// Normalize in the constructor, so we never have to worry about it again

include/boost/decimal/decimal_fast64_t.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <boost/decimal/detail/to_chars_result.hpp>
4242
#include <boost/decimal/detail/chars_format.hpp>
4343
#include <boost/decimal/detail/from_string.hpp>
44+
#include <boost/decimal/detail/construction_sign.hpp>
4445

4546
#ifndef BOOST_DECIMAL_BUILD_MODULE
4647

@@ -222,7 +223,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
222223
#else
223224
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
224225
#endif
225-
constexpr decimal_fast64_t(T1 coeff, T2 exp, bool is_negative = false) noexcept;
226+
constexpr decimal_fast64_t(T1 coeff, T2 exp, detail::construction_sign_wrapper resultant_sign = construction_sign::positive) noexcept;
226227

227228
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
228229
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
@@ -484,12 +485,13 @@ template <BOOST_DECIMAL_UNSIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
484485
#else
485486
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
486487
#endif
487-
constexpr decimal_fast64_t::decimal_fast64_t(T1 coeff, T2 exp, bool is_negative) noexcept
488+
constexpr decimal_fast64_t::decimal_fast64_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
488489
{
489490
using minimum_coefficient_size = std::conditional_t<(sizeof(T1) > sizeof(significand_type)), T1, significand_type>;
490491

491492
minimum_coefficient_size min_coeff {coeff};
492493

494+
const auto is_negative {static_cast<bool>(resultant_sign)};
493495
sign_ = is_negative;
494496

495497
// Normalize the value, so we don't have to worry about it with operations

0 commit comments

Comments
 (0)