Skip to content

Commit

Permalink
Merge pull request #581 from ckormanyos/update_math
Browse files Browse the repository at this point in the history
Update complex and wide-decimal
  • Loading branch information
ckormanyos authored Nov 29, 2024
2 parents c13ec90 + 9c96c54 commit 429fd62
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
32 changes: 20 additions & 12 deletions ref_app/src/math/extended_complex/extended_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,27 @@
template<typename X>
EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex<X>& other) -> complex&
{
my_re = static_cast<value_type>(other.my_re);
my_im = static_cast<value_type>(other.my_im);
if(this != &other)
{
my_re = static_cast<value_type>(other.my_re);
my_im = static_cast<value_type>(other.my_im);
}

return *this;
}

EXTENDED_COMPLEX_CONSTEXPR auto operator=(const value_type& other_x) -> complex&
{
my_re = other_x;
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
imag(std::move(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)))));

return *this;
}

EXTENDED_COMPLEX_CONSTEXPR auto operator=(value_type&& other_x) noexcept -> complex&
{
my_re = std::move(other_x);
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
imag(std::move(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)))));

return *this;
}
Expand Down Expand Up @@ -271,8 +274,8 @@
{
if(this == &my_z)
{
real(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
real(std::move(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)))));
imag(std::move(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)))));
}
else
{
Expand Down Expand Up @@ -307,8 +310,8 @@
{
if(this == &my_z)
{
real(static_cast<value_type>(static_cast<unsigned>(UINT8_C(1))));
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
real(std::move(static_cast<value_type>(static_cast<unsigned>(UINT8_C(1)))));
imag(std::move(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)))));
}
else
{
Expand Down Expand Up @@ -354,6 +357,8 @@
public:
using value_type = T;

static_assert(std::is_floating_point<value_type>::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) { }
Expand All @@ -365,12 +370,12 @@
my_im(std::move(static_cast<value_type&&>(other.my_im))) { }

template<typename OtherFloatingPointType,
typename OtherFloatingPointEnableType = typename std::enable_if_t<std::is_floating_point<OtherFloatingPointType>::value && (sizeof(OtherFloatingPointType) != sizeof(value_type)), void>>
typename OtherEnableType = typename std::enable_if_t<std::is_floating_point<OtherFloatingPointType>::value && (sizeof(OtherFloatingPointType) != sizeof(value_type)), void>>
explicit EXTENDED_COMPLEX_CONSTEXPR complex(const complex<OtherFloatingPointType>& other)
: my_re(static_cast<value_type>(other.my_re)),
my_im(static_cast<value_type>(other.my_im)) { }

auto operator=(const complex& other) -> complex&
EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex& other) -> complex&
{
if(this != &other)
{
Expand Down Expand Up @@ -401,8 +406,11 @@
typename OtherFloatingPointEnableType = typename std::enable_if_t<std::is_floating_point<OtherFloatingPointType>::value && (sizeof(OtherFloatingPointType) != sizeof(value_type)), void>>
EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex<OtherFloatingPointType>& other) -> complex&
{
my_re = other.my_re;
my_im = other.my_im;
if(this != &other)
{
my_re = static_cast<value_type>(other.my_re);
my_im = static_cast<value_type>(other.my_im);
}

return *this;
}
Expand Down
8 changes: 4 additions & 4 deletions ref_app/src/math/wide_decimal/decwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math/wide_decimal/decwide_t_detail_ops.h>

#include <util/utility/util_baselexical_cast.h>

#include <cmath>
#include <cstddef>
#include <cstdlib>
Expand All @@ -41,10 +45,6 @@
#include <string>
#endif

#include <math/wide_decimal/decwide_t_detail_ops.h>

#include <util/utility/util_baselexical_cast.h>

#if !defined(WIDE_DECIMAL_NAMESPACE_BEGIN)
#error WIDE_DECIMAL_NAMESPACE_BEGIN is not defined. Ensure that <decwide_t_detail_namespace.h> is properly included.
#endif
Expand Down
10 changes: 6 additions & 4 deletions ref_app/src/math/wide_decimal/decwide_t_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math/wide_decimal/decwide_t_detail_namespace.h>

#include <util/utility/util_dynamic_array.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <initializer_list>
#include <limits>
#include <memory>

#include <util/utility/util_dynamic_array.h>

#include <math/wide_decimal/decwide_t_detail_namespace.h>

#if defined(_MSC_VER)
#if (_MSC_VER >= 1900) && defined(_HAS_CXX20) && (_HAS_CXX20 != 0)
#define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage)
Expand Down
2 changes: 1 addition & 1 deletion ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h
Original file line number Diff line number Diff line change
@@ -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) //
Expand Down
6 changes: 3 additions & 3 deletions ref_app/src/math/wide_decimal/decwide_t_detail_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <math/wide_decimal/decwide_t_detail.h>
#include <math/wide_decimal/decwide_t_detail_fft.h>

#include <cstdint>
#include <iterator>
#include <type_traits>

#include <math/wide_decimal/decwide_t_detail.h>
#include <math/wide_decimal/decwide_t_detail_fft.h>

WIDE_DECIMAL_NAMESPACE_BEGIN

#if(__cplusplus >= 201703L)
Expand Down

0 comments on commit 429fd62

Please sign in to comment.