Skip to content

Commit

Permalink
Update wide-decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Feb 7, 2024
1 parent 0565bc4 commit fb0d1ad
Show file tree
Hide file tree
Showing 10 changed files with 1,148 additions and 1,207 deletions.
1,685 changes: 816 additions & 869 deletions ref_app/src/math/wide_decimal/decwide_t.h

Large diffs are not rendered by default.

303 changes: 143 additions & 160 deletions ref_app/src/math/wide_decimal/decwide_t_detail.h

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions ref_app/src/math/wide_decimal/decwide_t_detail_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,28 @@

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> std::enable_if_t<IsForwardFft, float_type>
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> typename std::enable_if<IsForwardFft, float_type>::type
{
return template_sin_order_1<float_type>(num_points);
}

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> std::enable_if_t<(!IsForwardFft), float_type>
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> typename std::enable_if<(!IsForwardFft), float_type>::type
{
return static_cast<float_type>(-template_sin_order_1<float_type>(num_points));
}

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> std::enable_if_t<IsForwardFft, float_type>
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> typename std::enable_if<IsForwardFft, float_type>::type
{
return template_sin_order_2<float_type>(num_points);
}

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> std::enable_if_t<(!IsForwardFft), float_type>
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> typename std::enable_if<(!IsForwardFft), float_type>::type
{
return static_cast<float_type>(-template_sin_order_2<float_type>(num_points));
}
Expand Down Expand Up @@ -248,8 +248,8 @@
{
if(j > i)
{
util::swap_unsafe(data[j - 1U], data[i - 1U]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
util::swap_unsafe(data[j], data[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
std::swap(data[j - 1U], data[i - 1U]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
std::swap(data[j], data[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}

auto m = num_points;
Expand All @@ -268,7 +268,7 @@

template<typename float_type,
const bool IsForwardFft>
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> std::enable_if_t<IsForwardFft>
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> typename std::enable_if<IsForwardFft, void>::type
{
fft_lanczos_fft<float_type, true>(num_points / 2U, data);

Expand Down Expand Up @@ -312,7 +312,7 @@

template<typename float_type,
const bool IsForwardFft>
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> std::enable_if_t<(!IsForwardFft)>
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> typename std::enable_if<(!IsForwardFft), void>::type
{
auto real_part = static_cast<float_type>(static_cast<float_type>(1) + const_unique_wp_real<float_type, false>(num_points));
auto imag_part = static_cast<float_type>( const_unique_wp_imag<float_type, false>(num_points));
Expand Down
24 changes: 7 additions & 17 deletions ref_app/src/math/wide_decimal/decwide_t_detail_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

template<typename InputIteratorLeftType,
typename InputIteratorRightType>
WIDE_DECIMAL_CONSTEXPR
auto compare_ranges( InputIteratorLeftType pa,
InputIteratorRightType pb,
const std::uint_fast32_t count) -> std::int_fast8_t
Expand Down Expand Up @@ -69,7 +68,6 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_add_n( OutputLimbIteratorType r,
InputLimbIteratorType u,
InputLimbIteratorType v,
Expand Down Expand Up @@ -109,7 +107,6 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_subtract_n( OutputLimbIteratorType r,
InputLimbIteratorType u, // NOLINT(bugprone-easily-swappable-parameters)
InputLimbIteratorType v,
Expand Down Expand Up @@ -169,14 +166,13 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
void eval_multiply_n_by_n_to_2n
(
OutputLimbIteratorType r,
InputLimbIteratorType a,
InputLimbIteratorType b,
const std::int_fast32_t count,
std::enable_if_t<std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint8_t>::value, int>* p_nullparam = static_cast<int*>(nullptr)
const typename std::enable_if<std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint8_t>::value>::type* p_nullparam = nullptr
)
{
static_cast<void>(p_nullparam);
Expand All @@ -199,7 +195,7 @@
count * static_cast<std::int_fast32_t>(INT8_C(2))
);

util::fill_unsafe(r, r + fill_dst, static_cast<local_limb_type>(UINT8_C(0)));
std::fill(r, r + fill_dst, static_cast<local_limb_type>(UINT8_C(0)));

const auto count_minus_one =
static_cast<std::int_fast32_t>
Expand Down Expand Up @@ -241,16 +237,14 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
void eval_multiply_n_by_n_to_2n
(
OutputLimbIteratorType r,
InputLimbIteratorType a,
InputLimbIteratorType b,
const std::int_fast32_t count,
std::enable_if_t<( std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint16_t>::value
|| std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint32_t>::value), int>* p_nullparam = static_cast<int*>(nullptr)
)
const typename std::enable_if<( std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint16_t>::value
|| std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint32_t>::value)>::type* p_nullparam = nullptr)
{
static_cast<void>(p_nullparam);

Expand Down Expand Up @@ -323,7 +317,6 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto mul_loop_n( LimbIteratorType u,
typename std::iterator_traits<LimbIteratorType>::value_type n,
const std::int32_t p) -> typename std::iterator_traits<LimbIteratorType>::value_type
Expand Down Expand Up @@ -361,7 +354,6 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto div_loop_n( LimbIteratorType u,
typename std::iterator_traits<LimbIteratorType>::value_type n,
const std::int32_t p) -> typename std::iterator_traits<LimbIteratorType>::value_type
Expand Down Expand Up @@ -397,7 +389,6 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_multiply_kara_propagate_carry( LimbIteratorType t,
const std::uint_fast32_t n,
const typename std::iterator_traits<LimbIteratorType>::value_type carry) -> void
Expand Down Expand Up @@ -442,7 +433,6 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_multiply_kara_propagate_borrow( LimbIteratorType t,
const std::uint_fast32_t n,
const bool has_borrow) -> void
Expand Down Expand Up @@ -558,7 +548,7 @@
// Step 1
eval_multiply_kara_n_by_n_to_2n(r0, a1, b1, nh, t);
eval_multiply_kara_n_by_n_to_2n(r2, a0, b0, nh, t);
util::copy_unsafe(r0, r0 + static_cast<std::size_t>(static_cast<std::size_t>(n) * static_cast<std::size_t>(UINT8_C(2))), t0);
std::copy(r0, r0 + static_cast<std::size_t>(static_cast<std::size_t>(n) * static_cast<std::size_t>(UINT8_C(2))), t0);

// Step 2
local_limb_type carry;
Expand Down Expand Up @@ -713,8 +703,8 @@
static_cast<std::size_t>(prec_elems_for_multiply) * static_cast<std::size_t>(UINT8_C(2))
);

util::fill_unsafe(af + fill_distance, af + n_fft, static_cast<local_fft_float_type>(0));
util::fill_unsafe(bf + fill_distance, bf + n_fft, static_cast<local_fft_float_type>(0));
std::fill(af + fill_distance, af + n_fft, static_cast<local_fft_float_type>(0));
std::fill(bf + fill_distance, bf + n_fft, static_cast<local_fft_float_type>(0));

// Perform forward FFTs on the data arrays a and b.
detail::fft::rfft_lanczos_rfft<local_fft_float_type, true>(n_fft, af);
Expand Down
33 changes: 25 additions & 8 deletions ref_app/src/mcal_lcd/mcal_lcd_base.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2019 - 2023.
// Copyright Christopher Kormanyos 2020 - 2022.
// 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)
//

#ifndef MCAL_LCD_BASE_2020_06_10_H
#ifndef MCAL_LCD_BASE_2020_06_10_H // NOLINT(llvm-header-guard)
#define MCAL_LCD_BASE_2020_06_10_H

#include <cstdint>

#include <util/utility/util_display.h>
#include <util/utility/util_noncopyable.h>

namespace mcal { namespace lcd {
#if(__cplusplus >= 201703L)
namespace mcal::lcd {
#else
namespace mcal { namespace lcd { // NOLINT(modernize-concat-nested-namespaces)
#endif

class lcd_base : public util::display_multiline_base
class lcd_base : private util::noncopyable // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
{
public:
~lcd_base() override = default;
virtual ~lcd_base() = default;

virtual auto init() -> bool = 0;

virtual auto write(const char* pstr,
std::uint_fast8_t length,
std::uint_fast8_t line_index) -> bool = 0;

protected:
lcd_base() noexcept = default;
lcd_base() = default; // LCOV_EXCL_LINE

virtual auto set_line_index(const std::uint8_t index) -> bool { static_cast<void>(index); return true; } // LCOV_EXCL_LINE
};

} } // namespace mcal::lcd
#if(__cplusplus >= 201703L)
} // namespace mcal::lcd
#else
} // namespace lcd
} // namespace mcal
#endif

#endif // MCAL_LCD_BASE_2020_06_10_H
37 changes: 24 additions & 13 deletions ref_app/src/mcal_lcd/mcal_lcd_console.h
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2019 - 2023.
// Copyright Christopher Kormanyos 2020 - 2022.
// 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)
//

#ifndef MCAL_LCD_CONSOLE_2020_06_10_H
#ifndef MCAL_LCD_CONSOLE_2020_06_10_H // NOLINT(llvm-header-guard)
#define MCAL_LCD_CONSOLE_2020_06_10_H

#include <iostream>
#include <string>

#include <mcal_lcd/mcal_lcd_base.h>

namespace mcal { namespace lcd {
#if(__cplusplus >= 201703L)
namespace mcal::lcd {
#else
namespace mcal { namespace lcd { // NOLINT(modernize-concat-nested-namespaces)
#endif

class lcd_console : public mcal::lcd::lcd_base
class lcd_console : public mcal::lcd::lcd_base // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
{
public:
lcd_console() noexcept = default;
lcd_console() = default; // LCOV_EXCL_LINE

~lcd_console() override = default;

auto write(const char* pstr, const std::uint_fast8_t length, const std::uint_fast8_t line_index) noexcept -> bool override
auto write(const char* pstr,
std::uint_fast8_t length, // NOLINT(bugprone-easily-swappable-parameters)
std::uint_fast8_t line_index) -> bool override
{
static_cast<void>(line_index);

auto result_write_is_ok = bool { };
bool write_is_ok { };

if((pstr != nullptr) && (length > 0U))
{
const auto str = std::string(pstr, pstr + length);
const std::string str(pstr, pstr + length); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)

std::cout << str << std::endl;

result_write_is_ok = true;
write_is_ok = true;
}
else
{
result_write_is_ok = false;
write_is_ok = false;
}

return result_write_is_ok;
return write_is_ok;
}

auto init() noexcept -> bool override { return true; }
auto init() -> bool override { return true; } // LCOV_EXCL_LINE
};

} } // namespace mcal::lcd
#if(__cplusplus >= 201703L)
} // namespace mcal::lcd
#else
} // namespace lcd
} // namespace mcal
#endif

#endif // MCAL_LCD_CONSOLE_2020_06_10_H
Loading

0 comments on commit fb0d1ad

Please sign in to comment.