From 9c96c548b83312ba6c7adbc2b3cf160750783776 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Fri, 29 Nov 2024 11:08:31 +0100 Subject: [PATCH] Update complex and wide-decimal --- .../math/extended_complex/extended_complex.h | 32 ++++++++++++------- ref_app/src/math/wide_decimal/decwide_t.h | 8 ++--- .../src/math/wide_decimal/decwide_t_detail.h | 10 +++--- .../wide_decimal/decwide_t_detail_namespace.h | 2 +- .../math/wide_decimal/decwide_t_detail_ops.h | 6 ++-- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/ref_app/src/math/extended_complex/extended_complex.h b/ref_app/src/math/extended_complex/extended_complex.h index c965a4065..4ee762d84 100644 --- a/ref_app/src/math/extended_complex/extended_complex.h +++ b/ref_app/src/math/extended_complex/extended_complex.h @@ -196,8 +196,11 @@ template EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex& other) -> complex& { - my_re = static_cast(other.my_re); - my_im = static_cast(other.my_im); + if(this != &other) + { + my_re = static_cast(other.my_re); + my_im = static_cast(other.my_im); + } return *this; } @@ -205,7 +208,7 @@ EXTENDED_COMPLEX_CONSTEXPR auto operator=(const value_type& other_x) -> complex& { my_re = other_x; - imag(static_cast(static_cast(UINT8_C(0)))); + imag(std::move(static_cast(static_cast(UINT8_C(0))))); return *this; } @@ -213,7 +216,7 @@ EXTENDED_COMPLEX_CONSTEXPR auto operator=(value_type&& other_x) noexcept -> complex& { my_re = std::move(other_x); - imag(static_cast(static_cast(UINT8_C(0)))); + imag(std::move(static_cast(static_cast(UINT8_C(0))))); return *this; } @@ -271,8 +274,8 @@ { if(this == &my_z) { - real(static_cast(static_cast(UINT8_C(0)))); - imag(static_cast(static_cast(UINT8_C(0)))); + real(std::move(static_cast(static_cast(UINT8_C(0))))); + imag(std::move(static_cast(static_cast(UINT8_C(0))))); } else { @@ -307,8 +310,8 @@ { if(this == &my_z) { - real(static_cast(static_cast(UINT8_C(1)))); - imag(static_cast(static_cast(UINT8_C(0)))); + real(std::move(static_cast(static_cast(UINT8_C(1))))); + imag(std::move(static_cast(static_cast(UINT8_C(0))))); } else { @@ -354,6 +357,8 @@ public: using value_type = T; + static_assert(std::is_floating_point::value, "Error: The template parameter must be a built-in floating-point type"); + EXTENDED_COMPLEX_CONSTEXPR complex(value_type my_x = value_type(), value_type my_y = value_type()) : my_re(my_x), my_im(my_y) { } @@ -365,12 +370,12 @@ my_im(std::move(static_cast(other.my_im))) { } template::value && (sizeof(OtherFloatingPointType) != sizeof(value_type)), void>> + typename OtherEnableType = typename std::enable_if_t::value && (sizeof(OtherFloatingPointType) != sizeof(value_type)), void>> explicit EXTENDED_COMPLEX_CONSTEXPR complex(const complex& other) : my_re(static_cast(other.my_re)), my_im(static_cast(other.my_im)) { } - auto operator=(const complex& other) -> complex& + EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex& other) -> complex& { if(this != &other) { @@ -401,8 +406,11 @@ typename OtherFloatingPointEnableType = typename std::enable_if_t::value && (sizeof(OtherFloatingPointType) != sizeof(value_type)), void>> EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex& other) -> complex& { - my_re = other.my_re; - my_im = other.my_im; + if(this != &other) + { + my_re = static_cast(other.my_re); + my_im = static_cast(other.my_im); + } return *this; } diff --git a/ref_app/src/math/wide_decimal/decwide_t.h b/ref_app/src/math/wide_decimal/decwide_t.h index 33bd26fd0..14fa86545 100644 --- a/ref_app/src/math/wide_decimal/decwide_t.h +++ b/ref_app/src/math/wide_decimal/decwide_t.h @@ -24,6 +24,10 @@ //#define WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION //#define WIDE_DECIMAL_NAMESPACE=something_unique // (best if done on the command line) + #include + + #include + #include #include #include @@ -41,10 +45,6 @@ #include #endif - #include - - #include - #if !defined(WIDE_DECIMAL_NAMESPACE_BEGIN) #error WIDE_DECIMAL_NAMESPACE_BEGIN is not defined. Ensure that is properly included. #endif diff --git a/ref_app/src/math/wide_decimal/decwide_t_detail.h b/ref_app/src/math/wide_decimal/decwide_t_detail.h index daa6e63c0..9d04ac9eb 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail.h @@ -14,16 +14,18 @@ #ifndef DECWIDE_T_DETAIL_2020_10_26_H // NOLINT(llvm-header-guard) #define DECWIDE_T_DETAIL_2020_10_26_H + #include + + #include + #include #include + #include #include #include + #include #include - #include - - #include - #if defined(_MSC_VER) #if (_MSC_VER >= 1900) && defined(_HAS_CXX20) && (_HAS_CXX20 != 0) #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) diff --git a/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h b/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h index 270b67ec6..d8241437e 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2022 - 2023. // +// Copyright Christopher Kormanyos 2022 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/ref_app/src/math/wide_decimal/decwide_t_detail_ops.h b/ref_app/src/math/wide_decimal/decwide_t_detail_ops.h index cf698c9e5..311f944fd 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail_ops.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail_ops.h @@ -17,13 +17,13 @@ #ifndef DECWIDE_T_DETAIL_OPS_2021_04_12_H // NOLINT(llvm-header-guard) #define DECWIDE_T_DETAIL_OPS_2021_04_12_H + #include + #include + #include #include #include - #include - #include - WIDE_DECIMAL_NAMESPACE_BEGIN #if(__cplusplus >= 201703L)