From fb0d1ad27a2368613aa8e7e80b41be2ef888f84d Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Wed, 7 Feb 2024 07:28:30 +0100 Subject: [PATCH] Update wide-decimal --- ref_app/src/math/wide_decimal/decwide_t.h | 1685 ++++++++--------- .../src/math/wide_decimal/decwide_t_detail.h | 303 ++- .../math/wide_decimal/decwide_t_detail_fft.h | 16 +- .../math/wide_decimal/decwide_t_detail_ops.h | 24 +- ref_app/src/mcal_lcd/mcal_lcd_base.h | 33 +- ref_app/src/mcal_lcd/mcal_lcd_console.h | 37 +- .../src/mcal_lcd/mcal_lcd_generic_st7066.h | 99 +- .../util/memory/util_n_slot_array_allocator.h | 43 +- ref_app/src/util/utility/util_dynamic_array.h | 113 +- ref_app/src/util/utility/util_noncopyable.h | 2 +- 10 files changed, 1148 insertions(+), 1207 deletions(-) diff --git a/ref_app/src/math/wide_decimal/decwide_t.h b/ref_app/src/math/wide_decimal/decwide_t.h index f472245c8..7e0b1bddd 100644 --- a/ref_app/src/math/wide_decimal/decwide_t.h +++ b/ref_app/src/math/wide_decimal/decwide_t.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 1999 - 2023. // +// Copyright Christopher Kormanyos 1999 - 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) // @@ -44,7 +44,6 @@ #include #include - #include #if !defined(WIDE_DECIMAL_NAMESPACE_BEGIN) #error WIDE_DECIMAL_NAMESPACE_BEGIN is not defined. Ensure that is properly included. @@ -143,9 +142,9 @@ typename ExponentType = std::int64_t, typename FftFloatType = double> #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>; + auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type; #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>; + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type; #endif template #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; #endif template #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; #endif template #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_pi(const std::function& pfn_callback_to_report_digits10 = nullptr) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t) = nullptr) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; #endif template - auto calc_ln_two() -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>; + auto calc_ln_two() -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type; template - auto calc_ln_two() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_ln_two() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; template - auto calc_ln_two() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_ln_two() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; template - auto calc_ln_two() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_ln_two() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; template - auto calc_ln_ten_low_precision() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_ln_ten_low_precision() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; template - auto calc_ln_ten_low_precision() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_ln_ten_low_precision() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; template - auto calc_ln_ten_low_precision() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>; + auto calc_ln_ten_low_precision() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type; template auto constexpr unsigned_long_long_max() -> decwide_t; template auto constexpr signed_long_long_min () -> decwide_t; @@ -251,34 +250,34 @@ template auto (isinf) (const decwide_t& x) -> bool; template auto (signbit) (const decwide_t& x) -> bool; - template auto fabs (const decwide_t& x) -> decwide_t; - template auto abs (const decwide_t& x) -> decwide_t; - template auto floor (const decwide_t& x) -> decwide_t; - template auto ceil (const decwide_t& x) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto ldexp (const decwide_t& v, - int e) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto frexp (const decwide_t& v, - int* expon) -> decwide_t; - template auto fmod (const decwide_t& v1, - const decwide_t& v2) -> decwide_t; - template auto ilogb (const decwide_t& x) -> typename decwide_t::exponent_type; - template auto sqrt (const decwide_t& x) -> decwide_t; - template auto cbrt (const decwide_t& x) -> decwide_t; - template auto rootn (const decwide_t& x, // NOLINT(misc-no-recursion) - std::int32_t p) -> decwide_t; - template auto rootn_inv(const decwide_t& x, - std::int32_t p) -> decwide_t; - template auto log (const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>; // NOLINT(misc-no-recursion) - template auto log (const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen <= static_cast(INT8_C(51))), decwide_t>; // NOLINT(misc-no-recursion) - template auto exp (const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT32_C(2000))), decwide_t>; - template auto exp (const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen <= static_cast(INT32_C(2000))), decwide_t>; - template auto sinh (const decwide_t& x) -> decwide_t; - template auto cosh (const decwide_t& x) -> decwide_t; - template auto tanh (const decwide_t& x) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto pow (const decwide_t& b, // NOLINT(misc-no-recursion) - std::int64_t p) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto pow (const decwide_t& x, - const decwide_t& a) -> decwide_t; + template auto fabs (const decwide_t& x) -> decwide_t; + template auto abs (const decwide_t& x) -> decwide_t; + template auto floor (const decwide_t& x) -> decwide_t; + template auto ceil (const decwide_t& x) -> decwide_t; + template auto ldexp (const decwide_t& v, + int e) -> decwide_t; + template auto frexp (const decwide_t& v, + int* expon) -> decwide_t; + template auto fmod (const decwide_t& v1, + const decwide_t& v2) -> decwide_t; + template auto ilogb (const decwide_t& x) -> typename decwide_t::exponent_type; + template auto sqrt (const decwide_t& x) -> decwide_t; + template auto cbrt (const decwide_t& x) -> decwide_t; + template auto rootn (const decwide_t& x, // NOLINT(misc-no-recursion) + std::int32_t p) -> decwide_t; + template auto rootn_inv(const decwide_t& x, + std::int32_t p) -> decwide_t; + template auto log (const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type; // NOLINT(misc-no-recursion) + template auto log (const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen <= static_cast(INT8_C(51))), decwide_t>::type; // NOLINT(misc-no-recursion) + template auto exp (const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT32_C(2000))), decwide_t>::type; + template auto exp (const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen <= static_cast(INT32_C(2000))), decwide_t>::type; + template auto sinh (const decwide_t& x) -> decwide_t; + template auto cosh (const decwide_t& x) -> decwide_t; + template auto tanh (const decwide_t& x) -> decwide_t; + template auto pow (const decwide_t& b, // NOLINT(misc-no-recursion) + std::int64_t p) -> decwide_t; + template auto pow (const decwide_t& x, + const decwide_t& a) -> decwide_t; #if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM) template WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& self) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& self) -> decwide_t; + template auto operator+(const decwide_t& self) -> decwide_t; + template auto operator-(const decwide_t& self) -> decwide_t; // Global add/sub/mul/div of const decwide_t& with const decwide_t&. - template WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, const decwide_t& v) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, const decwide_t& v) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, const decwide_t& v) -> decwide_t; - template WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, const decwide_t& v) -> decwide_t; + template auto operator+(const decwide_t& u, const decwide_t& v) -> decwide_t; + template auto operator-(const decwide_t& u, const decwide_t& v) -> decwide_t; + template auto operator*(const decwide_t& u, const decwide_t& v) -> decwide_t; + template auto operator/(const decwide_t& u, const decwide_t& v) -> decwide_t; // Global add/sub/mul/div of const decwide_t& with all built-in types. template - WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; // Global add/sub/mul/div of all built-in types with const decwide_t&. template - WIDE_DECIMAL_CONSTEXPR auto operator+(SignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator+(UnsignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator+(FloatingPointType f, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t>; + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-(ArithmeticType n, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t>; + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*(SignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*(UnsignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*(FloatingPointType f, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t>; + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/(ArithmeticType n, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t>; + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type; // Global self add/sub/mul/div of decwide_t& with all built-in types. template - WIDE_DECIMAL_CONSTEXPR auto operator+=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator+=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator+=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator-=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator*=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t>; + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t>; + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type; template - WIDE_DECIMAL_CONSTEXPR auto operator/=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t>; + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type; // Global comparison operators of const decwide_t& with const decwide_t&. - template WIDE_DECIMAL_CONSTEXPR auto operator< (const decwide_t& u, const decwide_t& v) -> bool; - template WIDE_DECIMAL_CONSTEXPR auto operator<=(const decwide_t& u, const decwide_t& v) -> bool; - template WIDE_DECIMAL_CONSTEXPR auto operator==(const decwide_t& u, const decwide_t& v) -> bool; - template WIDE_DECIMAL_CONSTEXPR auto operator!=(const decwide_t& u, const decwide_t& v) -> bool; - template WIDE_DECIMAL_CONSTEXPR auto operator>=(const decwide_t& u, const decwide_t& v) -> bool; - template WIDE_DECIMAL_CONSTEXPR auto operator> (const decwide_t& u, const decwide_t& v) -> bool; + template auto operator< (const decwide_t& u, const decwide_t& v) -> bool; + template auto operator<=(const decwide_t& u, const decwide_t& v) -> bool; + template auto operator==(const decwide_t& u, const decwide_t& v) -> bool; + template auto operator!=(const decwide_t& u, const decwide_t& v) -> bool; + template auto operator>=(const decwide_t& u, const decwide_t& v) -> bool; + template auto operator> (const decwide_t& u, const decwide_t& v) -> bool; // Global comparison operators of const decwide_t& with all built-in types. - template WIDE_DECIMAL_CONSTEXPR auto operator< (const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator<=(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator==(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator!=(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator>=(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator> (const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool>; + template auto operator< (const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type; + template auto operator<=(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type; + template auto operator==(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type; + template auto operator!=(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type; + template auto operator>=(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type; + template auto operator> (const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type; // Global comparison operators of all built-in types with const decwide_t&. - template WIDE_DECIMAL_CONSTEXPR auto operator< (ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator<=(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator==(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator!=(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator>=(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool>; - template WIDE_DECIMAL_CONSTEXPR auto operator> (ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool>; + template auto operator< (ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type; + template auto operator<=(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type; + template auto operator==(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type; + template auto operator!=(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type; + template auto operator>=(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type; + template auto operator> (ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type; template, + typename std::conditional::value, #else - typename std::conditional_t, - AllocatorType>; + std::allocator, + AllocatorType>::type; public: using allocator_type = @@ -610,23 +577,23 @@ using representation_type = #if (defined(_MSC_VER) && (_MSC_VER < 1920)) - typename std::conditional_t::value, + typename std::conditional::value, #else - typename std::conditional_t(decwide_t_elem_number)>, - detail::fixed_dynamic_array(decwide_t_elem_number), allocator_type>>; + detail::fixed_static_array (decwide_t_elem_number)>, + detail::fixed_dynamic_array(decwide_t_elem_number), allocator_type>>::type; using double_limb_type = - std::conditional_t::value, - std::uint64_t, - std::conditional_t::value, - std::uint32_t, - std::uint16_t>>; + typename std::conditional::value, + std::uint64_t, + typename std::conditional::value, + std::uint32_t, + std::uint16_t>::type>::type; - using signed_limb_type = std::make_signed_t; + using signed_limb_type = typename std::make_signed::type; - using unsigned_exponent_type = std::make_unsigned_t; + using unsigned_exponent_type = typename std::make_unsigned::type; // TBD: Consider supporting more floating-point classes. // In particular, support for NaN is already being @@ -648,108 +615,108 @@ // Note: For long double, you need to verify that the // mantissa fits in unsigned long long. - explicit WIDE_DECIMAL_CONSTEXPR native_float_parts(FloatingPointType f) - : my_sign_part(f < static_cast(0)) + explicit native_float_parts(FloatingPointType f) { using native_float_type = FloatingPointType; static_assert(std::numeric_limits::digits <= std::numeric_limits::digits, // NOLINT(google-runtime-int) "Error: The width of the mantissa does not fit in unsigned long long"); - const native_float_type ff = ((!my_sign_part) ? f : static_cast(-f)); + const native_float_type ff = ((f < static_cast(0)) ? static_cast(-f) : f); - if(ff >= (std::numeric_limits::min)()) + if(ff < (std::numeric_limits::min)()) { - // Get the fraction and base-2 exponent. + return; + } - auto man = static_cast(util::frexp_unsafe(ff, &my_exponent_part)); + using std::frexp; - auto n2 = static_cast(UINT8_C(0)); + // Get the fraction and base-2 exponent. - for(auto i = static_cast(UINT8_C(0)); - i < static_cast(std::numeric_limits::digits); - ++i) - { - // Extract the mantissa of the floating-point type in base-2 - // (one bit at a time) and store it in an unsigned long long. - man *= 2; + // TBD: Need to properly handle frexp when GCC's __float128 + // is active (in case of -std=gnu++XX). + // This happens when native_float_type is of type __float128. - n2 = static_cast(man); - man -= static_cast(n2); + auto man = static_cast(frexp(static_cast(f), &my_exponent_part)); - if(n2 != static_cast(UINT8_C(0))) - { - my_mantissa_part |= static_cast(UINT8_C(1)); - } + auto n2 = static_cast(UINT8_C(0)); - if(i < static_cast(std::numeric_limits::digits - 1)) - { - my_mantissa_part <<= static_cast(UINT8_C(1)); - } + for(auto i = static_cast(UINT8_C(0)); + i < static_cast(std::numeric_limits::digits); + ++i) + { + // Extract the mantissa of the floating-point type in base-2 + // (one bit at a time) and store it in an unsigned long long. + man *= 2; + + n2 = static_cast(man); + man -= static_cast(n2); + + if(n2 != static_cast(UINT8_C(0))) + { + my_mantissa_part |= static_cast(UINT8_C(1)); } - // Ensure that the value is normalized and adjust the exponent. + if(i < static_cast(std::numeric_limits::digits - 1)) + { + my_mantissa_part <<= static_cast(UINT8_C(1)); + } + } - // TBD: Need to properly handle this left shift amount - // when GCC's __float128 is active (in case of -std=gnu++XX). - // This happens when native_float_type is of type __float128. - constexpr auto max_left_shift_amount = - static_cast - ( - (std::numeric_limits::digits < std::numeric_limits::digits) - ? std::numeric_limits::digits - : std::numeric_limits::digits - ); + // Ensure that the value is normalized and adjust the exponent. - my_mantissa_part |= static_cast(1ULL << static_cast(max_left_shift_amount - 1)); // NOLINT(google-runtime-int) + // TBD: Need to properly handle this left shift amount + // when GCC's __float128 is active (in case of -std=gnu++XX). + // This happens when native_float_type is of type __float128. + constexpr auto max_left_shift_amount = + static_cast + ( + (std::numeric_limits::digits < std::numeric_limits::digits) + ? std::numeric_limits::digits + : std::numeric_limits::digits + ); - my_exponent_part -= 1; - } + my_mantissa_part |= static_cast(1ULL << static_cast(max_left_shift_amount - 1)); // NOLINT(google-runtime-int) + my_exponent_part -= 1; } constexpr native_float_parts(const native_float_parts& other) noexcept : my_mantissa_part(other.my_mantissa_part), - my_exponent_part(other.my_exponent_part), - my_sign_part (other.my_sign_part) { } + my_exponent_part(other.my_exponent_part) { } constexpr native_float_parts(native_float_parts&& other) noexcept : my_mantissa_part(other.my_mantissa_part), - my_exponent_part(other.my_exponent_part), - my_sign_part (other.my_sign_part) { } + my_exponent_part(other.my_exponent_part) { } + + native_float_parts() = delete; ~native_float_parts() noexcept = default; // LCOV_EXCL_LINE - constexpr auto operator=(const native_float_parts& other) noexcept -> native_float_parts& // NOLINT(cert-oop54-cpp) + auto operator=(const native_float_parts& other) noexcept -> native_float_parts& // NOLINT(cert-oop54-cpp) { if(this != &other) { my_mantissa_part = other.my_mantissa_part; my_exponent_part = other.my_exponent_part; - my_sign_part = other.my_sign_part; } return *this; } - constexpr auto operator=(native_float_parts&& other) noexcept -> native_float_parts& + auto operator=(native_float_parts&& other) noexcept -> native_float_parts& { my_mantissa_part = other.my_mantissa_part; my_exponent_part = other.my_exponent_part; - my_sign_part = other.my_sign_part; return *this; } WIDE_DECIMAL_NODISCARD constexpr auto get_mantissa() const noexcept -> unsigned long long { return my_mantissa_part; } // NOLINT(google-runtime-int) WIDE_DECIMAL_NODISCARD constexpr auto get_exponent() const noexcept -> int { return my_exponent_part; } - WIDE_DECIMAL_NODISCARD constexpr auto get_sign () const noexcept -> bool { return my_sign_part; } private: unsigned long long my_mantissa_part { }; // NOLINT(readability-identifier-naming,google-runtime-int) int my_exponent_part { }; // NOLINT(readability-identifier-naming) - bool my_sign_part { }; // NOLINT(readability-identifier-naming) - - constexpr native_float_parts() = default; }; #if !defined(WIDE_DECIMAL_DISABLE_CACHED_CONSTANTS) @@ -757,7 +724,7 @@ // Static data initializer struct initializer { - WIDE_DECIMAL_CONSTEXPR initializer() noexcept + initializer() noexcept { static_cast(decwide_t::my_value_pi()); static_cast(decwide_t::my_value_ln_two()); @@ -771,7 +738,7 @@ ~initializer() noexcept = default; - WIDE_DECIMAL_CONSTEXPR auto do_nothing() const noexcept -> void + auto do_nothing() const noexcept -> void { // Do nothing on purpose. } @@ -792,14 +759,24 @@ public: // Default constructor. - constexpr decwide_t() noexcept = default; + constexpr decwide_t() noexcept + : my_data (), + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { } // Constructors from built-in unsigned integral types. template::value - && std::is_unsigned::value - && (std::numeric_limits::digits <= std::numeric_limits::digits))> const* = nullptr> + typename std::enable_if<( std::is_integral::value + && std::is_unsigned::value + && (std::numeric_limits::digits <= std::numeric_limits::digits))>::type const* = nullptr> constexpr decwide_t(const UnsignedIntegralType u) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + : my_data (decwide_t_elem_number), + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { const auto u_is_less_than_mask = (static_cast(u) < static_cast(decwide_t_elem_mask)); @@ -821,19 +798,27 @@ // Constructors from built-in unsigned integral types. template::value - && std::is_unsigned::value - && (std::numeric_limits::digits < std::numeric_limits::digits))> const* = nullptr> - constexpr decwide_t(const UnsignedIntegralType u) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + typename std::enable_if<( std::is_integral::value + && std::is_unsigned::value + && (std::numeric_limits::digits < std::numeric_limits::digits))>::type const* = nullptr> + decwide_t(const UnsignedIntegralType u) : my_data (), // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { from_unsigned_long_long(u); } // Constructors from built-in signed integral types. template::value - && std::is_signed ::value)> const* = nullptr> - constexpr decwide_t(const SignedIntegralType n) : my_neg(n < static_cast(INT8_C(0))) // NOLINT(google-runtime-int,google-explicit-constructor,hicpp-explicit-conversions) + typename std::enable_if<( std::is_integral::value + && std::is_signed ::value)>::type const* = nullptr> + decwide_t(const SignedIntegralType n) : my_data (), // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + my_exp (static_cast(INT8_C(0))), + my_neg (n < static_cast(INT8_C(0))), // NOLINT(google-runtime-int) + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { const auto u = static_cast // NOLINT(google-runtime-int) @@ -847,15 +832,23 @@ // Constructors from built-in floating-point types. template::value, int>* = nullptr> - WIDE_DECIMAL_CONSTEXPR decwide_t(const FloatingPointType f) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + typename std::enable_if::value == true>::type const* = nullptr> + decwide_t(const FloatingPointType f) : my_data (), // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { from_builtin_float_type(f); } #if !defined(WIDE_DECIMAL_DISABLE_CONSTRUCT_FROM_STRING) // Constructors from character representations. - explicit decwide_t(const char* s) + explicit decwide_t(const char* s) : my_data (), + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { static_cast(rd_string(s)); } @@ -878,12 +871,22 @@ // Constructor from floating-point class type, even though // (at the moment) decwide_t instances can only be finite. - explicit constexpr decwide_t(fpclass_type) { } // NOLINT(hicpp-named-parameter,readability-named-parameter) + explicit constexpr decwide_t(fpclass_type) // NOLINT(hicpp-named-parameter,readability-named-parameter) + : my_data (), + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { } private: // Constructor from mantissa and exponent. - explicit WIDE_DECIMAL_CONSTEXPR decwide_t(const internal_float_type mantissa, - const exponent_type exponent) + explicit decwide_t(const internal_float_type mantissa, + const exponent_type exponent) + : my_data (), + my_exp (static_cast(INT8_C(0))), + my_neg (false), + my_fpclass (fpclass_type::decwide_t_finite), + my_prec_elem(decwide_t_elem_number) { // Create a decwide_t from mantissa and exponent. // This constructor is, in fact, intended to maintain @@ -983,17 +986,17 @@ d *= static_cast(decwide_t_elem_mask); } - util::fill_unsafe(my_data.begin() + static_cast(limb_index), - my_data.end(), - static_cast(UINT8_C(0))); + std::fill(my_data.begin() + static_cast(limb_index), + my_data.end(), + static_cast(UINT8_C(0))); } } public: - WIDE_DECIMAL_CONSTEXPR ~decwide_t() = default; + ~decwide_t() = default; // Assignment operator. - WIDE_DECIMAL_CONSTEXPR auto operator=(const decwide_t& other) -> decwide_t& // NOLINT(cert-oop54-cpp) + auto operator=(const decwide_t& other) -> decwide_t& // NOLINT(cert-oop54-cpp) { if(this != &other) { @@ -1008,7 +1011,7 @@ } // Move assignment operator. - WIDE_DECIMAL_CONSTEXPR auto operator=(decwide_t&& other) noexcept -> decwide_t& + auto operator=(decwide_t&& other) noexcept -> decwide_t& { my_data = static_cast(other.my_data); my_exp = other.my_exp; @@ -1024,7 +1027,7 @@ WIDE_DECIMAL_NODISCARD auto crepresentation() const noexcept -> const representation_type& { return my_data; } // Binary arithmetic operators. - WIDE_DECIMAL_CONSTEXPR auto operator+=(const decwide_t& v) -> decwide_t& // NOLINT(readability-function-cognitive-complexity) + auto operator+=(const decwide_t& v) -> decwide_t& // NOLINT(readability-function-cognitive-complexity) { // TBD: Eliminate the temporary storage array my_n_data_for_add_sub. @@ -1039,7 +1042,7 @@ const auto prec_elems_for_add_sub = static_cast ( - util::min_unsafe(my_prec_elem, v.my_prec_elem) + (std::min)(my_prec_elem, v.my_prec_elem) ); // Get the offset for the add/sub operation. @@ -1094,13 +1097,13 @@ // at a time, each element with carry. if(ofs >= static_cast(INT8_C(0))) { - util::copy_unsafe(v.my_data.cbegin(), - v.my_data.cend() - static_cast(ofs), - my_n_data_for_add_sub.begin() + static_cast(ofs)); + std::copy(v.my_data.cbegin(), + v.my_data.cend() - static_cast(ofs), + my_n_data_for_add_sub.begin() + static_cast(ofs)); - util::fill_unsafe(my_n_data_for_add_sub.begin(), - my_n_data_for_add_sub.begin() + static_cast(ofs), - static_cast(UINT8_C(0))); + std::fill(my_n_data_for_add_sub.begin(), + my_n_data_for_add_sub.begin() + static_cast(ofs), + static_cast(UINT8_C(0))); using const_limb_pointer_type = typename std::add_const::type; @@ -1112,14 +1115,14 @@ } else { - util::copy_unsafe(my_data.cbegin(), - my_data.cend() - static_cast(-ofs), - my_n_data_for_add_sub.begin() + static_cast(-ofs)); + std::copy(my_data.cbegin(), + my_data.cend() - static_cast(-ofs), + my_n_data_for_add_sub.begin() + static_cast(-ofs)); // LCOV_EXCL_START - util::fill_unsafe(my_n_data_for_add_sub.begin(), - my_n_data_for_add_sub.begin() + static_cast(-ofs), - static_cast(UINT8_C(0))); + std::fill(my_n_data_for_add_sub.begin(), + my_n_data_for_add_sub.begin() + static_cast(-ofs), + static_cast(UINT8_C(0))); // LCOV_EXCL_STOP using const_limb_pointer_type = typename std::add_const::type; @@ -1145,9 +1148,9 @@ #endif #endif - util::copy_unsafe(static_cast(my_n_data_for_add_sub.data()), - static_cast(my_n_data_for_add_sub.data()) + static_cast(prec_elems_for_add_sub), - my_data.data()); + std::copy(static_cast(my_n_data_for_add_sub.data()), + static_cast(my_n_data_for_add_sub.data()) + static_cast(prec_elems_for_add_sub), + my_data.data()); #if (defined(__GNUC__) && !defined(__clang__)) #if(__GNUC__ >= 12) @@ -1175,9 +1178,9 @@ + static_cast(INT8_C(1)) ); - util::copy_backward_unsafe(my_data.cbegin(), - my_data.cend() - offset_to_end, - my_data.end()); + std::copy_backward(my_data.cbegin(), + my_data.cend() - offset_to_end, + my_data.end()); using local_size_type = typename representation_type::size_type; @@ -1204,13 +1207,13 @@ // Copy the data of v, shifted down to a lower value // into the data array m_n. Set the operand pointer p_v // to point to the copied, shifted data m_n. - util::copy_unsafe(v.my_data.cbegin(), - v.my_data.cend() - static_cast(ofs), - my_n_data_for_add_sub.begin() + static_cast(ofs)); + std::copy(v.my_data.cbegin(), + v.my_data.cend() - static_cast(ofs), + my_n_data_for_add_sub.begin() + static_cast(ofs)); - util::fill_unsafe(my_n_data_for_add_sub.begin(), - my_n_data_for_add_sub.begin() + static_cast(ofs), - static_cast(UINT8_C(0))); + std::fill(my_n_data_for_add_sub.begin(), + my_n_data_for_add_sub.begin() + static_cast(ofs), + static_cast(UINT8_C(0))); using const_limb_pointer_type = typename std::add_const::type; @@ -1229,22 +1232,22 @@ { // In this case, |u| < |v| and ofs is negative. // Shift the data of u down to a lower value. - util::copy_backward_unsafe(my_data.cbegin(), - my_data.cend() - static_cast(-ofs), - my_data.end()); + std::copy_backward(my_data.cbegin(), + my_data.cend() - static_cast(-ofs), + my_data.end()); - util::fill_unsafe(my_data.begin(), - my_data.begin() + static_cast(-ofs), - static_cast(UINT8_C(0))); + std::fill(my_data.begin(), + my_data.begin() + static_cast(-ofs), + static_cast(UINT8_C(0))); } // Copy the data of v into the data array my_n_data_for_add_sub. // Set the u-pointer p_u to point to m_n and the // operand pointer p_v to point to the shifted // data m_data. - util::copy_unsafe(v.my_data.cbegin(), - v.my_data.cbegin() + static_cast(prec_elems_for_add_sub), - my_n_data_for_add_sub.begin()); + std::copy(v.my_data.cbegin(), + v.my_data.cbegin() + static_cast(prec_elems_for_add_sub), + my_n_data_for_add_sub.begin()); using const_limb_pointer_type = typename std::add_const::type; @@ -1257,9 +1260,9 @@ static_cast(has_borrow); - util::copy_unsafe(my_n_data_for_add_sub.cbegin(), - my_n_data_for_add_sub.cbegin() + static_cast(prec_elems_for_add_sub), - my_data.begin()); + std::copy(my_n_data_for_add_sub.cbegin(), + my_n_data_for_add_sub.cbegin() + static_cast(prec_elems_for_add_sub), + my_data.begin()); my_exp = v.my_exp; my_neg = v.my_neg; @@ -1267,12 +1270,12 @@ // Is it necessary to justify the data? const auto first_nonzero_elem = // NOLINT(llvm-qualified-auto,readability-qualified-auto) - util::find_if_unsafe(my_data.cbegin(), - my_data.cbegin() + static_cast(prec_elems_for_add_sub), - [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) - { - return (d != static_cast(UINT8_C(0))); - }); + std::find_if(my_data.cbegin(), + my_data.cbegin() + static_cast(prec_elems_for_add_sub), + [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) + { + return (d != static_cast(UINT8_C(0))); + }); if(first_nonzero_elem != my_data.cbegin()) { @@ -1288,13 +1291,13 @@ // Justify the data const auto sj = std::distance(my_data.cbegin(), first_nonzero_elem); - util::copy_unsafe(my_data.cbegin() + sj, - my_data.cend(), - my_data.begin()); + std::copy(my_data.cbegin() + sj, + my_data.cend(), + my_data.begin()); - util::fill_unsafe(my_data.end() - sj, - my_data.end(), - static_cast(UINT8_C(0))); + std::fill(my_data.end() - sj, + my_data.end(), + static_cast(UINT8_C(0))); my_exp = static_cast @@ -1310,12 +1313,12 @@ } // Check for underflow. - if(util::all_of_unsafe(my_data.cbegin(), - my_data.cend(), - [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) - { - return (d == static_cast(UINT8_C(0))); - })) + if(std::all_of(my_data.cbegin(), + my_data.cend(), + [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) + { + return (d == static_cast(UINT8_C(0))); + })) { static_cast ( @@ -1327,13 +1330,13 @@ return *this; } - WIDE_DECIMAL_CONSTEXPR auto operator-=(const decwide_t& v) -> decwide_t& + auto operator-=(const decwide_t& v) -> decwide_t& { // Use *this - v = -(-*this + v). return (negate().operator+=(v)).negate(); } - WIDE_DECIMAL_CONSTEXPR auto operator*=(const decwide_t& v) -> decwide_t& + auto operator*=(const decwide_t& v) -> decwide_t& { // Handle multiplication by zero. if(iszero() || v.iszero()) @@ -1389,7 +1392,7 @@ : detail::negate(static_cast(result_exp.get_value_unsigned())) ); - const auto prec_elems_for_multiply = util::min_unsafe(my_prec_elem, v.my_prec_elem); + const auto prec_elems_for_multiply = (std::min)(my_prec_elem, v.my_prec_elem); #if (defined(__GNUC__) && !defined(__clang__)) #if(__GNUC__ >= 12) @@ -1402,7 +1405,7 @@ #endif #endif - eval_mul_dispatch_multiplication_method(v, prec_elems_for_multiply); + eval_mul_dispatch_multiplication_method(v, prec_elems_for_multiply); #if (defined(__GNUC__) && !defined(__clang__)) #if(__GNUC__ >= 12) @@ -1421,7 +1424,7 @@ return *this; } - WIDE_DECIMAL_CONSTEXPR auto operator/=(const decwide_t& v) -> decwide_t& + auto operator/=(const decwide_t& v) -> decwide_t& { const auto u_and_v_are_identical = ( (my_fpclass == v.my_fpclass) @@ -1453,19 +1456,19 @@ } // Arithmetic operators with unsigned long long. - WIDE_DECIMAL_CONSTEXPR auto add_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto add_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) { // Non-optimized addition of unsigned long long. return operator+=(decwide_t(n)); } - WIDE_DECIMAL_CONSTEXPR auto sub_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto sub_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) { // Non-optimized subtraction of unsigned long long. return operator-=(decwide_t(n)); } - WIDE_DECIMAL_CONSTEXPR auto mul_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto mul_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) { // Multiply *this with a constant unsigned long long. @@ -1522,9 +1525,9 @@ my_exp = static_cast(my_exp + static_cast(decwide_t_elem_digits10)); // Shift the result of the multiplication one element to the right. - util::copy_backward_unsafe(my_data.cbegin(), - my_data.cbegin() + static_cast(static_cast(my_prec_elem) - static_cast(INT8_C(1))), - my_data.begin() + static_cast(my_prec_elem)); + std::copy_backward(my_data.cbegin(), + my_data.cbegin() + static_cast(static_cast(my_prec_elem) - static_cast(INT8_C(1))), + my_data.begin() + static_cast(my_prec_elem)); my_data.front() = static_cast(carry); } @@ -1535,7 +1538,7 @@ return *this; } - WIDE_DECIMAL_CONSTEXPR auto div_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto div_unsigned_long_long(unsigned long long n) -> decwide_t& // NOLINT(google-runtime-int) { // Divide *this by a constant unsigned long long. @@ -1587,9 +1590,9 @@ - static_cast(INT8_C(1)) ); - util::copy_unsafe(my_data.cbegin() + static_cast(INT8_C(1)), - my_data.cbegin() + prec_minus_one, - my_data.begin()); + std::copy(my_data.cbegin() + static_cast(INT8_C(1)), + my_data.cbegin() + prec_minus_one, + my_data.begin()); const auto index_prev = static_cast @@ -1625,7 +1628,7 @@ } // Arithmetic operators with signed long long. - WIDE_DECIMAL_CONSTEXPR auto add_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto add_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) { if(n < static_cast(INT8_C(0))) // NOLINT(google-runtime-int) { @@ -1641,12 +1644,12 @@ return *this; } - WIDE_DECIMAL_CONSTEXPR auto sub_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto sub_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) { return add_signed_long_long(static_cast(-n)); // NOLINT(google-runtime-int) } - WIDE_DECIMAL_CONSTEXPR auto mul_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto mul_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) { const auto b_neg = (n < static_cast(INT8_C(0))); // NOLINT(google-runtime-int) @@ -1659,30 +1662,27 @@ return ((!b_neg) ? *this : negate()); } - WIDE_DECIMAL_CONSTEXPR auto div_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) + auto div_signed_long_long(signed long long n) -> decwide_t& // NOLINT(google-runtime-int) { const auto b_neg = (n < static_cast(INT8_C(0))); // NOLINT(google-runtime-int) - const auto n_long_long = - static_cast // NOLINT(google-runtime-int) - ( - (!b_neg) ? static_cast(n) // NOLINT(google-runtime-int) - : detail::negate(static_cast(n)) // NOLINT(google-runtime-int) - ); - - div_unsigned_long_long(n_long_long); + div_unsigned_long_long + ( + (!b_neg) ? static_cast(n) // NOLINT(google-runtime-int) + : detail::negate(static_cast(n)) // NOLINT(google-runtime-int) + ); return ((!b_neg) ? *this : negate()); } - WIDE_DECIMAL_NODISCARD constexpr auto cmp(const decwide_t& v) const -> std::int_fast8_t // NOLINT(readability-function-cognitive-complexity) + WIDE_DECIMAL_NODISCARD auto cmp(const decwide_t& v) const -> std::int_fast8_t // NOLINT(readability-function-cognitive-complexity) { // Compare v with *this. // Return +1 for *this > v // 0 for *this = v // -1 for *this < v - std::int_fast8_t n_result { }; + auto n_result = std::int_fast8_t { }; // Handle all *finite* cases only. if(iszero()) @@ -1814,7 +1814,7 @@ } #endif - WIDE_DECIMAL_CONSTEXPR auto precision(const std::int32_t prec_digits) noexcept -> void + auto precision(const std::int32_t prec_digits) noexcept -> void { const auto prec_digits_elem_digits10_div = static_cast(prec_digits / decwide_t_elem_digits10); const auto prec_digits_elem_digits10_mod = static_cast(prec_digits % decwide_t_elem_digits10); @@ -1832,9 +1832,9 @@ ); { - const auto elems_least = util::max_unsafe(elems_needed_for_digits, static_cast(INT8_C(2))); + const auto elems_least = (std::max)(elems_needed_for_digits, static_cast(INT8_C(2))); - my_prec_elem = util::min_unsafe(decwide_t_elem_number, elems_least); + my_prec_elem = (std::min)(decwide_t_elem_number, elems_least); } } @@ -1843,31 +1843,30 @@ return static_cast(x.my_prec_elem * decwide_t_elem_digits10); } - WIDE_DECIMAL_CONSTEXPR auto swap(decwide_t& other) noexcept -> void + auto swap(decwide_t& other) noexcept -> void { if(this != &other) { - my_data.swap(static_cast(other.my_data)); + const decwide_t tmp(*this); + + *this = other; - util::swap_unsafe(my_exp, other.my_exp); - util::swap_unsafe(my_neg, other.my_neg); - util::swap_unsafe(my_fpclass, other.my_fpclass); - util::swap_unsafe(my_prec_elem, other.my_prec_elem); + other = tmp; } } - WIDE_DECIMAL_CONSTEXPR auto swap(decwide_t&& other) noexcept -> void + auto swap(decwide_t&& other) noexcept -> void { my_data.swap(static_cast(other.my_data)); - util::swap_unsafe(my_exp, other.my_exp); - util::swap_unsafe(my_neg, other.my_neg); - util::swap_unsafe(my_fpclass, other.my_fpclass); - util::swap_unsafe(my_prec_elem, other.my_prec_elem); + std::swap(my_exp, other.my_exp); + std::swap(my_neg, other.my_neg); + std::swap(my_fpclass, other.my_fpclass); + std::swap(my_prec_elem, other.my_prec_elem); } // Elementary primitives. - WIDE_DECIMAL_CONSTEXPR auto calculate_inv() -> decwide_t& + auto calculate_inv() -> decwide_t& { // Compute the inverse of *this. // Handle the special case of zero. @@ -1918,8 +1917,8 @@ digits *= static_cast(INT8_C(2))) { // Adjust precision of the terms. - constexpr auto min_elem_digits10_plus_one = - util::min_unsafe + const auto min_elem_digits10_plus_one = + (std::min) ( static_cast(decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(INT8_C(9)) @@ -2033,7 +2032,7 @@ { // Adjust precision of the terms. const auto min_elem_digits10_plus_one = - util::min_unsafe + (std::min) ( static_cast(decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(INT8_C(9)) @@ -2121,7 +2120,7 @@ { // Adjust precision of the terms. const auto min_elem_digits10_plus_one = - util::min_unsafe + (std::min) ( static_cast(decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(INT8_C(9)) @@ -2209,7 +2208,7 @@ } } - WIDE_DECIMAL_CONSTEXPR auto negate() -> decwide_t& + auto negate() -> decwide_t& { if(!iszero()) { @@ -2231,19 +2230,19 @@ return (my_data[static_cast(UINT8_C(0))] == static_cast(UINT8_C(0))); } - WIDE_DECIMAL_NODISCARD constexpr auto isone() const -> bool + WIDE_DECIMAL_NODISCARD auto isone() const -> bool { // Check if the value of *this is identically 1 or very close to 1. return ((!my_neg) && isone_sign_neutral(*this)); } - WIDE_DECIMAL_NODISCARD constexpr auto isone_minus() const -> bool + WIDE_DECIMAL_NODISCARD auto isone_minus() const -> bool { // Check if the value of *this is identically 1 or very close to 1. return (my_neg && isone_sign_neutral(*this)); } - WIDE_DECIMAL_NODISCARD constexpr auto isint() const noexcept -> bool + WIDE_DECIMAL_NODISCARD auto isint() const noexcept -> bool { auto value_is_int = bool { }; @@ -2278,12 +2277,12 @@ else { const auto it_non_zero = // NOLINT(llvm-qualified-auto,readability-qualified-auto) - util::find_if_unsafe(my_data.cbegin() + static_cast(offset_decimal_part), - my_data.cend(), - [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) - { - return (d != static_cast(UINT8_C(0))); - }); + std::find_if(my_data.cbegin() + static_cast(offset_decimal_part), + my_data.cend(), + [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) + { + return (d != static_cast(UINT8_C(0))); + }); value_is_int = (it_non_zero == my_data.cend()); } @@ -2296,15 +2295,15 @@ WIDE_DECIMAL_NODISCARD constexpr auto ispos() const noexcept -> bool { return (!isneg()); } // Operators pre-increment and pre-decrement. - WIDE_DECIMAL_CONSTEXPR auto operator++() -> decwide_t& { return *this += one(); } - WIDE_DECIMAL_CONSTEXPR auto operator--() -> decwide_t& { return *this -= one(); } + auto operator++() -> decwide_t& { return *this += one(); } + auto operator--() -> decwide_t& { return *this -= one(); } // Operators post-increment and post-decrement. - WIDE_DECIMAL_CONSTEXPR auto operator++(int) -> decwide_t { const decwide_t w(*this); static_cast(++(*this)); return w; } - WIDE_DECIMAL_CONSTEXPR auto operator--(int) -> decwide_t { const decwide_t w(*this); static_cast(--(*this)); return w; } + auto operator++(int) -> decwide_t { const decwide_t w(*this); static_cast(++(*this)); return w; } + auto operator--(int) -> decwide_t { const decwide_t w(*this); static_cast(--(*this)); return w; } // Conversion routines. - WIDE_DECIMAL_CONSTEXPR auto extract_parts(internal_float_type& mantissa, exponent_type& exponent) const -> void + auto extract_parts(internal_float_type& mantissa, exponent_type& exponent) const -> void { // Extracts the mantissa as a decimal part less in magnitude // than 1 and the base-10 exponent parts of this decwide_t. @@ -2355,7 +2354,7 @@ const auto digit_loops_max = static_cast ( - util::min_unsafe(my_data.size(), static_cast(digit_loops)) + (std::min)(my_data.size(), static_cast(digit_loops)) ); for(auto limb_index = static_cast(UINT8_C(0)); @@ -2373,7 +2372,7 @@ } } - WIDE_DECIMAL_NODISCARD WIDE_DECIMAL_CONSTEXPR auto extract_integer_part() const -> decwide_t + WIDE_DECIMAL_NODISCARD auto extract_integer_part() const -> decwide_t { // Compute the signed integer part of x. @@ -2412,14 +2411,14 @@ const auto last_clear = static_cast(decwide_t_elem_number); - util::fill_unsafe(x.my_data.begin() + first_clear, - x.my_data.begin() + last_clear, - static_cast(UINT8_C(0))); + std::fill(x.my_data.begin() + first_clear, + x.my_data.begin() + last_clear, + static_cast(UINT8_C(0))); return x; } - WIDE_DECIMAL_NODISCARD WIDE_DECIMAL_CONSTEXPR auto extract_long_double() const -> long double + WIDE_DECIMAL_NODISCARD auto extract_long_double() const -> long double { // Returns the long double conversion of a decwide_t. @@ -2443,13 +2442,15 @@ + static_cast(INT8_C(1)) ); - const auto elems_of_ldbl_to_get = + constexpr auto elems_of_ldbl_to_get = static_cast ( - util::min_unsafe(elems_of_ldbl_to_get_try, decwide_t_elem_number) + // Caution: Do not use (std::min) here because some language + // standards (such as C++11) do not have constexpr-. + (elems_of_ldbl_to_get_try < decwide_t_elem_number) ? elems_of_ldbl_to_get_try : decwide_t_elem_number ); - using local_unsigned_exponent_type = typename std::make_unsigned_t; + using local_unsigned_exponent_type = typename std::make_unsigned::type; constexpr auto ldbl_max_width_for_exp = static_cast(std::numeric_limits::digits10); @@ -2528,9 +2529,9 @@ const auto exp_len = std::distance(static_cast(data_exp_buf.data()), p_end); - util::copy_unsafe(data_exp_buf.cbegin(), - data_exp_buf.cbegin() + static_cast(exp_len), - ldbl_str_rep.begin() + ldbl_str_pos); + std::copy(data_exp_buf.cbegin(), + data_exp_buf.cbegin() + static_cast(exp_len), + ldbl_str_rep.begin() + ldbl_str_pos); } // Use the C-style library function strtold() in order @@ -2541,7 +2542,7 @@ return ldbl_retrieved; } - WIDE_DECIMAL_NODISCARD WIDE_DECIMAL_CONSTEXPR auto extract_signed_long_long() const -> signed long long // NOLINT(google-runtime-int) + WIDE_DECIMAL_NODISCARD auto extract_signed_long_long() const -> signed long long // NOLINT(google-runtime-int) { // Extracts a signed long long from *this. // If either (x > maximum of signed long long) @@ -2579,7 +2580,7 @@ auto val = static_cast(xn.my_data[static_cast(UINT8_C(0))]); // NOLINT(google-runtime-int) const auto imax = - util::min_unsafe + (std::min) ( static_cast(static_cast(xn.my_exp) / decwide_t_elem_digits10), static_cast(decwide_t_elem_number - static_cast(INT8_C(1))) @@ -2604,7 +2605,7 @@ return signed_long_long_result; } - WIDE_DECIMAL_NODISCARD WIDE_DECIMAL_CONSTEXPR auto extract_unsigned_long_long() const -> unsigned long long // NOLINT(google-runtime-int) + WIDE_DECIMAL_NODISCARD auto extract_unsigned_long_long() const -> unsigned long long // NOLINT(google-runtime-int) { // Extracts an unsigned long long from *this. // If x exceeds the maximum of unsigned long long, @@ -2642,8 +2643,8 @@ const auto imax = static_cast ( - util::min_unsafe(static_cast(static_cast(xn.my_exp) / decwide_t_elem_digits10), - static_cast(decwide_t_elem_number - static_cast(INT8_C(1)))) + (std::min)(static_cast(static_cast(xn.my_exp) / decwide_t_elem_digits10), + static_cast(decwide_t_elem_number - static_cast(INT8_C(1)))) ); using local_size_type = typename representation_type::size_type; @@ -2664,12 +2665,12 @@ return unsigned_long_long_result; } - explicit WIDE_DECIMAL_CONSTEXPR operator long double() const { return extract_long_double(); } - explicit WIDE_DECIMAL_CONSTEXPR operator double () const { return static_cast(extract_long_double()); } - explicit WIDE_DECIMAL_CONSTEXPR operator float () const { return static_cast (extract_long_double()); } + explicit operator long double() const { return extract_long_double(); } + explicit operator double () const { return static_cast(extract_long_double()); } + explicit operator float () const { return static_cast (extract_long_double()); } template::value>> + typename = typename std::enable_if::value>::type> explicit constexpr operator IntegralType() const { return @@ -2684,9 +2685,9 @@ // Cast operator to built-in Boolean type. explicit constexpr operator bool() const { return (!iszero()); } - static WIDE_DECIMAL_CONSTEXPR auto from_lst( std::initializer_list limb_values, - const exponent_type e = static_cast(INT8_C(0)), - const bool is_neg = false) -> decwide_t + static auto from_lst( std::initializer_list limb_values, + const exponent_type e = static_cast(INT8_C(0)), + const bool is_neg = false) -> decwide_t { // Initialization from initializer list of limbs, // exponent value (normed to limb granularity) @@ -2695,19 +2696,19 @@ if(limb_values.size() < a.my_data.size()) { - util::copy_unsafe(limb_values.begin(), - limb_values.end(), - a.my_data.begin()); + std::copy(limb_values.begin(), + limb_values.end(), + a.my_data.begin()); - util::fill_unsafe(a.my_data.begin() + limb_values.size(), - a.my_data.end(), - static_cast(UINT8_C(0))); + std::fill(a.my_data.begin() + limb_values.size(), + a.my_data.end(), + static_cast(UINT8_C(0))); } else { - util::copy_unsafe(limb_values.begin(), - limb_values.begin() + a.my_data.size(), - a.my_data.begin()); + std::copy(limb_values.begin(), + limb_values.begin() + a.my_data.size(), + a.my_data.begin()); } a.my_exp = e; @@ -2741,19 +2742,19 @@ #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) #else static std::array((decwide_t_elems_for_kara - 1) * 2)> my_school_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) - static std::array(detail::a029750_as_constexpr(static_cast(static_cast(decwide_t_elems_for_fft - 1)) * 8UL))> my_kara_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - static std::array(detail::a000079_as_constexpr(static_cast(static_cast(decwide_t_elem_number)) * 4UL))> my_af_fft_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) - static std::array(detail::a000079_as_constexpr(static_cast(static_cast(decwide_t_elem_number)) * 4UL))> my_bf_fft_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static std::array(detail::a029750::a029750_as_constexpr(static_cast(static_cast(decwide_t_elems_for_fft - 1)) * 8UL))> my_kara_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + static std::array(detail::a000079::a000079_as_constexpr(static_cast(static_cast(decwide_t_elem_number)) * 4UL))> my_af_fft_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static std::array(detail::a000079::a000079_as_constexpr(static_cast(static_cast(decwide_t_elem_number)) * 4UL))> my_bf_fft_mul_pool; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) static representation_type my_n_data_for_add_sub; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) #endif - representation_type my_data { }; // NOLINT(readability-identifier-naming) - exponent_type my_exp { }; // NOLINT(readability-identifier-naming) - bool my_neg { false }; // NOLINT(readability-identifier-naming,modernize-use-default-member-init) - fpclass_type my_fpclass { fpclass_type::decwide_t_finite}; // NOLINT(readability-identifier-naming) - std::int32_t my_prec_elem { decwide_t_elem_number }; // NOLINT(readability-identifier-naming) + representation_type my_data; // NOLINT(readability-identifier-naming) + exponent_type my_exp; // NOLINT(readability-identifier-naming) + bool my_neg; // NOLINT(readability-identifier-naming,modernize-use-default-member-init) + fpclass_type my_fpclass; // NOLINT(readability-identifier-naming) + std::int32_t my_prec_elem; // NOLINT(readability-identifier-naming) - WIDE_DECIMAL_NODISCARD static WIDE_DECIMAL_CONSTEXPR auto isone_sign_neutral(const decwide_t& x) -> bool + WIDE_DECIMAL_NODISCARD static auto isone_sign_neutral(const decwide_t& x) -> bool { // Check if the value of *this is identically 1 or very close to 1. @@ -2765,12 +2766,12 @@ && (x.my_exp == static_cast(INT8_C(0)))) { const auto it_non_zero = // NOLINT(llvm-qualified-auto,readability-qualified-auto) - util::find_if_unsafe(x.my_data.cbegin() + static_cast(INT8_C(1)), - x.my_data.cend(), - [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) - { - return (d != static_cast(UINT8_C(0))); - }); + std::find_if(x.my_data.cbegin() + static_cast(INT8_C(1)), + x.my_data.cend(), + [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) + { + return (d != static_cast(UINT8_C(0))); + }); value_is_one = (it_non_zero == x.my_data.cend()); } @@ -2778,12 +2779,12 @@ && (x.my_exp == static_cast(-decwide_t_elem_digits10))) { const auto it_non_nine = // NOLINT(llvm-qualified-auto,readability-qualified-auto) - util::find_if_unsafe(x.my_data.cbegin() + static_cast(INT8_C(1)), - x.my_data.cend(), - [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) - { - return (d != static_cast(decwide_t_elem_mask_min1)); - }); + std::find_if(x.my_data.cbegin() + static_cast(INT8_C(1)), + x.my_data.cend(), + [](const limb_type& d) // NOLINT(modernize-use-trailing-return-type) + { + return (d != static_cast(decwide_t_elem_mask_min1)); + }); value_is_one = (it_non_nine == x.my_data.cend()); } @@ -2791,84 +2792,83 @@ return value_is_one; } - constexpr auto from_unsigned_long_long(unsigned long long u) -> void // NOLINT(google-runtime-int) + auto from_unsigned_long_long(unsigned long long u) -> void // NOLINT(google-runtime-int) { my_exp = static_cast(INT8_C(0)); - util::fill_unsafe(my_data.begin(), my_data.end(), static_cast(UINT8_C(0))); - - auto index_n = static_cast(UINT8_C(0)); - - if(u > static_cast(UINT8_C(0))) // NOLINT(google-runtime-int) - { - auto uu = u; - - constexpr auto local_tmp_array_size = - static_cast - ( - static_cast - ( - std::numeric_limits::digits10 // NOLINT(google-runtime-int) - / static_cast(decwide_t_elem_digits10) - ) - + static_cast(UINT8_C(3)) - ); + auto i = static_cast(UINT8_C(0)); - using local_tmp_array_type = std::array; + auto uu = u; - local_tmp_array_type tmp { }; + constexpr auto local_tmp_array_size = + static_cast + ( + static_cast + ( + std::numeric_limits::digits10 // NOLINT(google-runtime-int) + / static_cast(decwide_t_elem_digits10) + ) + + static_cast(UINT8_C(3)) + ); - util::fill_unsafe(tmp.begin(), tmp.end(), static_cast(UINT8_C(0))); + using local_tmp_array_type = std::array; - while - ( - (uu != static_cast(UINT8_C(0))) // NOLINT(google-runtime-int,altera-id-dependent-backward-branch) - && (index_n < static_cast(std::tuple_size::value)) - ) - { - tmp[static_cast(index_n)] = - static_cast(uu % static_cast(decwide_t_elem_mask)); // NOLINT(google-runtime-int) + local_tmp_array_type tmp; - uu = static_cast(uu / static_cast(decwide_t_elem_mask)); // NOLINT(google-runtime-int) + tmp.fill(static_cast(UINT8_C(0))); - ++index_n; - } + while + ( + (uu != static_cast(UINT8_C(0))) // NOLINT(google-runtime-int,altera-id-dependent-backward-branch) + && (i < static_cast(std::tuple_size::value)) + ) + { + tmp[static_cast(i)] = + static_cast(uu % static_cast(decwide_t_elem_mask)); // NOLINT(google-runtime-int) - if(index_n > static_cast(UINT8_C(1))) - { - my_exp = - static_cast - ( - my_exp - + static_cast - ( - static_cast(index_n - static_cast(UINT8_C(1))) - * static_cast(decwide_t_elem_digits10) - ) - ); + uu = static_cast(uu / static_cast(decwide_t_elem_mask)); // NOLINT(google-runtime-int) - util::reverse_unsafe(tmp.begin(), tmp.begin() + index_n); - } + ++i; + } - constexpr auto copy_limit = - static_cast + if(i > static_cast(UINT8_C(1))) + { + my_exp = + static_cast ( - util::min_unsafe(static_cast(std::tuple_size::value), - static_cast(decwide_t_elem_number)) + my_exp + + static_cast + ( + static_cast(i - static_cast(UINT8_C(1))) + * static_cast(decwide_t_elem_digits10) + ) ); + } - const auto copy_amount = static_cast(util::min_unsafe(static_cast(index_n), copy_limit)); + std::reverse(tmp.begin(), tmp.begin() + i); - util::copy_unsafe(tmp.cbegin(), tmp.cbegin() + copy_amount, my_data.begin()); - } + const auto copy_limit = + static_cast + ( + (std::min)(static_cast(std::tuple_size::value), + static_cast(decwide_t_elem_number)) + ); + + std::copy(tmp.cbegin(), + tmp.cbegin() + static_cast((std::min)(static_cast(i), copy_limit)), + my_data.begin()); + + std::fill(my_data.begin() + static_cast((std::min)(static_cast(i), copy_limit)), + my_data.end(), + static_cast(UINT8_C(0))); } template - WIDE_DECIMAL_CONSTEXPR auto from_builtin_float_type(FloatingPointType flt) -> void + auto from_builtin_float_type(FloatingPointType flt) -> void { - using local_floating_point_type = FloatingPointType; + const auto b_neg = (flt < static_cast(0.0F)); - const native_float_parts ld_parts(flt); + const native_float_parts ld_parts((!b_neg) ? flt : -flt); // Create a decwide_t from the fractional part of the // mantissa expressed as an unsigned long long. @@ -2880,7 +2880,7 @@ static_cast ( ld_parts.get_exponent() - - static_cast(std::numeric_limits::digits - static_cast(INT8_C(1))) + - static_cast(std::numeric_limits::digits - static_cast(INT8_C(1))) ); if (p2 < static_cast(INT8_C(-2))) { *this *= pow(half(), -p2); } @@ -2891,18 +2891,19 @@ else if(p2 == static_cast(INT8_C( 2))) { *this *= static_cast(UINT8_C(4)); } else { *this *= pow(two(), p2); } - my_neg = ld_parts.get_sign(); + my_neg = b_neg; } template - WIDE_DECIMAL_CONSTEXPR auto eval_mul_dispatch_multiplication_method + auto eval_mul_dispatch_multiplication_method ( const decwide_t& v, const std::int32_t prec_elems_for_multiply, - std::enable_if_t<((OtherDigits10 == ParamDigitsBaseTen) && !(decwide_t::decwide_t_elem_number >= decwide_t_elems_for_kara)), int>* p_nullptr = static_cast(nullptr) + const typename std::enable_if<( (OtherDigits10 == ParamDigitsBaseTen) + && !(decwide_t::decwide_t_elem_number >= decwide_t_elems_for_kara))>::type* p_nullparam = nullptr ) -> void { - static_cast(p_nullptr); + static_cast(p_nullparam); // Use school multiplication. #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) @@ -2934,22 +2935,19 @@ my_exp = static_cast(my_exp + static_cast(decwide_t_elem_digits10)); // Shift the result of the multiplication one element to the right. - util::copy_unsafe(result, - result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result, + result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } else { - const auto copy_limit = - static_cast - ( - util::min_unsafe(static_cast(prec_elems_for_multiply + static_cast(INT8_C(1))), - util::min_unsafe(decwide_t_elem_number, decwide_t_elems_for_kara)) - ); + const auto kara_limit = (std::min)(decwide_t_elem_number, decwide_t_elems_for_kara); - util::copy_unsafe(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - result + copy_limit, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + const auto copy_limit = static_cast((std::min)(prec_elems_for_multiply, kara_limit)); + + std::copy(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + result + static_cast(static_cast(INT8_C(1)) + copy_limit), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } } @@ -2958,10 +2956,12 @@ ( const decwide_t& v, const std::int32_t prec_elems_for_multiply, - std::enable_if_t<((OtherDigits10 == ParamDigitsBaseTen) && (decwide_t::decwide_t_elem_number >= decwide_t_elems_for_kara) && (decwide_t::decwide_t_elem_number < decwide_t_elems_for_fft)), int>* p_nullptr = static_cast(nullptr) + const typename std::enable_if<( (OtherDigits10 == ParamDigitsBaseTen) + && (decwide_t::decwide_t_elem_number >= decwide_t_elems_for_kara) + && (decwide_t::decwide_t_elem_number < decwide_t_elems_for_fft))>::type* p_nullparam = nullptr ) -> void { - static_cast(p_nullptr); + static_cast(p_nullparam); if(prec_elems_for_multiply < decwide_t_elems_for_kara) { @@ -2995,22 +2995,19 @@ my_exp = static_cast(my_exp + static_cast(decwide_t_elem_digits10)); // Shift the result of the multiplication one element to the right. - util::copy_unsafe(result, - result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result, + result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } else { - const auto copy_limit = - static_cast - ( - util::min_unsafe(static_cast(prec_elems_for_multiply + static_cast(INT8_C(1))), - util::min_unsafe(decwide_t_elem_number, decwide_t_elems_for_kara)) - ); + const auto kara_limit = (std::min)(decwide_t_elem_number, decwide_t_elems_for_kara); + + const auto copy_limit = static_cast((std::min)(prec_elems_for_multiply, kara_limit)); - util::copy_unsafe(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - result + copy_limit, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + result + static_cast(static_cast(INT8_C(1)) + copy_limit), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } } else if( (prec_elems_for_multiply >= decwide_t_elems_for_kara) @@ -3020,7 +3017,7 @@ // Sloanes's A029750: Numbers of the form 2^k times 1, 3, 5 or 7. const auto kara_elems_for_multiply = - detail::a029750_as_runtime_value(static_cast(prec_elems_for_multiply)); + detail::a029750::a029750_as_runtime_value(static_cast(prec_elems_for_multiply)); #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) using kara_mul_pool_type = util::dynamic_array; @@ -3041,11 +3038,11 @@ limb_type* result = my_kara_mul_pool.data() + static_cast(static_cast(kara_elems_for_multiply) * static_cast(UINT8_C(2))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) limb_type* t = my_kara_mul_pool.data() + static_cast(static_cast(kara_elems_for_multiply) * static_cast(UINT8_C(4))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - util::copy_unsafe(my_data.cbegin(), my_data.cbegin() + prec_elems_for_multiply, u_local); - util::copy_unsafe(v.my_data.cbegin(), v.my_data.cbegin() + static_cast(prec_elems_for_multiply), v_local); + std::copy(my_data.cbegin(), my_data.cbegin() + prec_elems_for_multiply, u_local); + std::copy(v.my_data.cbegin(), v.my_data.cbegin() + static_cast(prec_elems_for_multiply), v_local); - util::fill_unsafe(u_local + prec_elems_for_multiply, u_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - util::fill_unsafe(v_local + prec_elems_for_multiply, v_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + std::fill(u_local + prec_elems_for_multiply, u_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + std::fill(v_local + prec_elems_for_multiply, v_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) detail::eval_multiply_kara_n_by_n_to_2n(result, u_local, @@ -3059,22 +3056,19 @@ my_exp = static_cast(my_exp + static_cast(decwide_t_elem_digits10)); // Shift the result of the multiplication one element to the right. - util::copy_unsafe(result, - result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result, + result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } else { - const auto copy_limit = - static_cast - ( - util::min_unsafe(static_cast(prec_elems_for_multiply + static_cast(INT8_C(1))), - util::min_unsafe(decwide_t_elem_number, decwide_t_elems_for_fft)) - ); + const auto fft_limit = (std::min)(decwide_t_elem_number, decwide_t_elems_for_fft); + + const auto copy_limit = static_cast((std::min)(prec_elems_for_multiply, fft_limit)); - util::copy_unsafe(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - result + copy_limit, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + result + static_cast(static_cast(INT8_C(1)) + copy_limit), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } } } @@ -3084,10 +3078,11 @@ ( const decwide_t& v, const std::int32_t prec_elems_for_multiply, - std::enable_if_t<((OtherDigits10 == ParamDigitsBaseTen) && (decwide_t::decwide_t_elem_number >= decwide_t_elems_for_fft)), int>* p_nullptr = static_cast(nullptr) + const typename std::enable_if<( (OtherDigits10 == ParamDigitsBaseTen) + && (decwide_t::decwide_t_elem_number >= decwide_t_elems_for_fft))>::type* p_nullparam = nullptr ) -> void { - static_cast(p_nullptr); + static_cast(p_nullparam); if(prec_elems_for_multiply < decwide_t_elems_for_kara) { @@ -3122,22 +3117,19 @@ my_exp += static_cast(decwide_t_elem_digits10); // Shift the result of the multiplication one element to the right. - util::copy_unsafe(result, - result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result, + result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } else { - const auto copy_limit = - static_cast - ( - util::min_unsafe(static_cast(prec_elems_for_multiply + static_cast(INT8_C(1))), - util::min_unsafe(decwide_t_elem_number, decwide_t_elems_for_kara)) - ); + const auto kara_limit = (std::min)(decwide_t_elem_number, decwide_t_elems_for_kara); + + const auto copy_limit = static_cast((std::min)(prec_elems_for_multiply, kara_limit)); - util::copy_unsafe(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - result + copy_limit, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + result + static_cast(static_cast(INT8_C(1)) + copy_limit), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } } else if( (prec_elems_for_multiply >= decwide_t_elems_for_kara) @@ -3147,7 +3139,7 @@ // Use Sloane's A029750: The so-called 7-smooth numbers having the form 2^k times 1, 3, 5 or 7. const auto kara_elems_for_multiply = - detail::a029750_as_runtime_value(static_cast(prec_elems_for_multiply)); + detail::a029750::a029750_as_runtime_value(static_cast(prec_elems_for_multiply)); #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) using kara_mul_pool_type = util::dynamic_array; @@ -3168,11 +3160,11 @@ limb_type* result = my_kara_mul_pool.data() + static_cast(static_cast(kara_elems_for_multiply) * static_cast(UINT8_C(2))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) limb_type* t = my_kara_mul_pool.data() + static_cast(static_cast(kara_elems_for_multiply) * static_cast(UINT8_C(4))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - util::copy_unsafe(my_data.cbegin(), my_data.cbegin() + prec_elems_for_multiply, u_local); - util::copy_unsafe(v.my_data.cbegin(), v.my_data.cbegin() + static_cast(prec_elems_for_multiply), v_local); + std::copy(my_data.cbegin(), my_data.cbegin() + prec_elems_for_multiply, u_local); + std::copy(v.my_data.cbegin(), v.my_data.cbegin() + static_cast(prec_elems_for_multiply), v_local); - util::fill_unsafe(u_local + prec_elems_for_multiply, u_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - util::fill_unsafe(v_local + prec_elems_for_multiply, v_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + std::fill(u_local + prec_elems_for_multiply, u_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + std::fill(v_local + prec_elems_for_multiply, v_local + kara_elems_for_multiply, static_cast(UINT8_C(0))); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) detail::eval_multiply_kara_n_by_n_to_2n(result, u_local, @@ -3186,22 +3178,19 @@ my_exp = static_cast(my_exp + static_cast(decwide_t_elem_digits10)); // Shift the result of the multiplication one element to the right. - util::copy_unsafe(result, - result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(result, + result + static_cast(prec_elems_for_multiply), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } else { - const auto copy_limit = - static_cast - ( - util::min_unsafe(static_cast(prec_elems_for_multiply + static_cast(INT8_C(1))), - util::min_unsafe(decwide_t_elem_number, decwide_t_elems_for_fft)) - ); + const auto fft_limit = (std::min)(decwide_t_elem_number, decwide_t_elems_for_fft); - util::copy_unsafe(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - result + copy_limit, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + const auto copy_limit = static_cast((std::min)(prec_elems_for_multiply, fft_limit)); + + std::copy(result + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + result + static_cast(static_cast(INT8_C(1)) + copy_limit), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); } } else if(prec_elems_for_multiply >= decwide_t_elems_for_fft) @@ -3226,7 +3215,7 @@ const auto n_fft = static_cast ( - detail::a000079_as_constexpr(static_cast(prec_elems_for_multiply)) + detail::a000079::a000079_as_constexpr(static_cast(prec_elems_for_multiply)) * static_cast(UINT8_C(4)) ); @@ -3254,17 +3243,11 @@ } else { - const auto copy_limit = - static_cast - ( - util::min_unsafe(static_cast(prec_elems_for_multiply + static_cast(INT8_C(1))), - decwide_t_elem_number) - ); + const auto copy_limit = static_cast((std::min)(prec_elems_for_multiply, decwide_t_elem_number)); - // Justify the data if necessary. - util::copy_unsafe(my_data.cbegin() + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.cbegin() + copy_limit, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - my_data.begin()); + std::copy(my_data.cbegin() + static_cast(INT8_C(1)), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.cbegin() + static_cast(static_cast(INT8_C(1)) + copy_limit), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + my_data.begin()); my_data.back() = static_cast(UINT8_C(0)); } @@ -3387,9 +3370,9 @@ if(do_clear_lower_limbs) { - util::fill_unsafe(my_data.begin() + static_cast(least_digit_idx_plus_one), - my_data.end(), - static_cast(UINT8_C(0))); + std::fill(my_data.begin() + static_cast(least_digit_idx_plus_one), + my_data.end(), + static_cast(UINT8_C(0))); } } @@ -3451,9 +3434,9 @@ // In rare cases, propagation of the carry reaches the zero'th limb // of highest significance, and we must shift the data, create a new limb // with the carry value of 1 and adjust the exponent accordingly. - util::copy_backward_unsafe(my_data.cbegin(), - my_data.cend() - static_cast(INT8_C(1)), - my_data.end()); + std::copy_backward(my_data.cbegin(), + my_data.cend() - static_cast(INT8_C(1)), + my_data.end()); my_data[static_cast(UINT8_C(0))] = carry_out; @@ -3465,7 +3448,7 @@ } #if !defined(WIDE_DECIMAL_DISABLE_CONSTRUCT_FROM_STRING) - static WIDE_DECIMAL_CONSTEXPR auto pos_of_e_func(const std::string& local_str) -> std::string::size_type + static auto pos_of_e_func(const std::string& local_str) -> std::string::size_type { auto pos_of_e = std::string::npos; @@ -3534,12 +3517,12 @@ // Remove leading zeros for all input types. const auto fwd_it_leading_zero = - util::find_if_unsafe(str.begin(), - str.end(), - [](const char& c) // NOLINT(modernize-use-trailing-return-type) - { - return (c != '0'); - }); + std::find_if(str.begin(), + str.end(), + [](const char& c) // NOLINT(modernize-use-trailing-return-type) + { + return (c != '0'); + }); if(fwd_it_leading_zero != str.begin()) { @@ -3571,12 +3554,12 @@ { // Remove all trailing insignificant zeros. const auto rit_non_zero = - util::find_if_unsafe(str.crbegin(), - str.crend(), - [](const char& c) // NOLINT(modernize-use-trailing-return-type) - { - return (c != '0'); - }); + std::find_if(str.crbegin(), + str.crend(), + [](const char& c) // NOLINT(modernize-use-trailing-return-type) + { + return (c != '0'); + }); if(rit_non_zero != str.crbegin()) { @@ -3625,12 +3608,12 @@ if(str.at(static_cast(UINT8_C(0))) == '.') { const auto it_non_zero = - util::find_if_unsafe(str.cbegin() + static_cast(INT8_C(1)), - str.cend(), - [](const char& c) // NOLINT(modernize-use-trailing-return-type) - { - return (c != '0'); - }); + std::find_if(str.cbegin() + static_cast(INT8_C(1)), + str.cend(), + [](const char& c) // NOLINT(modernize-use-trailing-return-type) + { + return (c != '0'); + }); const auto delta_exp = static_cast @@ -3790,7 +3773,7 @@ // input form as described in the comment above. // Set all the data elements to 0. - util::fill_unsafe(my_data.begin(), my_data.end(), static_cast(UINT8_C(0))); + std::fill(my_data.begin(), my_data.end(), static_cast(UINT8_C(0))); // Extract the data. @@ -3863,11 +3846,11 @@ } #endif //!(WIDE_DECIMAL_DISABLE_CONSTRUCT_FROM_STRING) - static WIDE_DECIMAL_CONSTEXPR auto get_output_digits(const decwide_t& x, - char* it_dst, - const std::uint_fast32_t number_of_elements, - std::size_t* count_retrieved, - const bool include_decimal_point = false) -> void + static auto get_output_digits(const decwide_t& x, + char* it_dst, + const std::uint_fast32_t number_of_elements, + std::size_t* count_retrieved, + const bool include_decimal_point = false) -> void { // Extract the required digits from decwide_t, including // digits both before as well as after the decimal point. @@ -3894,9 +3877,9 @@ std::distance(static_cast(data_elem_buf.data()), p_end) ); - it_dst = util::copy_unsafe(data_elem_buf.cbegin(), - data_elem_buf.cbegin() + *count_retrieved, - it_dst); + it_dst = std::copy(data_elem_buf.cbegin(), + data_elem_buf.cbegin() + *count_retrieved, + it_dst); // Include the decimal point if requested. if(include_decimal_point) @@ -3914,15 +3897,15 @@ ++it_rep; - auto rit = util::copy_unsafe(static_cast>(p_end), - static_cast>(static_cast(data_elem_buf.data())), - data_elem_array.rbegin()); + auto rit = std::copy(static_cast>(p_end), + static_cast>(static_cast(data_elem_buf.data())), + data_elem_array.rbegin()); - util::fill_unsafe(rit, data_elem_array.rend(), '0'); + std::fill(rit, data_elem_array.rend(), '0'); - it_dst = util::copy_unsafe(data_elem_array.cbegin(), - data_elem_array.cend(), - it_dst); + it_dst = std::copy(data_elem_array.cbegin(), + data_elem_array.cend(), + it_dst); *count_retrieved = static_cast @@ -3941,8 +3924,8 @@ { // Determine the number of elements needed to provide the requested digits from decwide_t. const std::uint_fast32_t number_of_elements = - util::min_unsafe(static_cast(static_cast(number_of_digits / static_cast(decwide_t_elem_digits10)) + static_cast(UINT8_C(2))), - static_cast(decwide_t_elem_number)); + (std::min)(static_cast(static_cast(number_of_digits / static_cast(decwide_t_elem_digits10)) + static_cast(UINT8_C(2))), + static_cast(decwide_t_elem_number)); // Extract the remaining digits from decwide_t after the decimal point. @@ -3966,9 +3949,9 @@ str.resize(count_retrieved); - util::copy_unsafe(str_tmp_mem.cbegin(), - str_tmp_mem.cbegin() + count_retrieved, - str.begin()); + std::copy(str_tmp_mem.cbegin(), + str_tmp_mem.cbegin() + count_retrieved, + str.begin()); // Cut the output to the size of the precision. if(str.length() > number_of_digits) @@ -4051,12 +4034,12 @@ if(trim_trailing_zeros) { const std::string::const_reverse_iterator rit_non_zero = - util::find_if_unsafe(str.crbegin(), - str.crend(), - [](const char& c) // NOLINT(modernize-use-trailing-return-type) - { - return (c != '0'); - }); + std::find_if(str.crbegin(), + str.crend(), + [](const char& c) // NOLINT(modernize-use-trailing-return-type) + { + return (c != '0'); + }); if(rit_non_zero != str.crbegin()) { @@ -4211,12 +4194,12 @@ if(trim_trailing_zeros) { const auto rit_non_zero = - util::find_if_unsafe(str.crbegin(), - str.crend(), - [](const char& c) // NOLINT(modernize-use-trailing-return-type) - { - return (c != '0'); - }); + std::find_if(str.crbegin(), + str.crend(), + [](const char& c) // NOLINT(modernize-use-trailing-return-type) + { + return (c != '0'); + }); if(rit_non_zero != str.crbegin()) { @@ -4270,12 +4253,12 @@ { // This is a non-zero decimal less than 1 that needs zero extension. const auto it_non_zero = - util::find_if_unsafe(str.cbegin() + static_cast(INT8_C(2)), - str.cend(), - [](const char& c) // NOLINT(modernize-use-trailing-return-type) - { - return (c != '0'); - }); + std::find_if(str.cbegin() + static_cast(INT8_C(2)), + str.cend(), + [](const char& c) // NOLINT(modernize-use-trailing-return-type) + { + return (c != '0'); + }); const auto len_non_zero_part = static_cast @@ -4336,7 +4319,7 @@ } #endif // !WIDE_DECIMAL_DISABLE_IOSTREAM - friend inline WIDE_DECIMAL_CONSTEXPR auto fabs(const decwide_t& x) -> decwide_t + friend inline auto fabs(const decwide_t& x) -> decwide_t { return (x.isneg() ? decwide_t(x).negate() : x); } @@ -4346,7 +4329,7 @@ return fabs(x); } - friend inline WIDE_DECIMAL_CONSTEXPR auto floor(const decwide_t& x) -> decwide_t + friend inline auto floor(const decwide_t& x) -> decwide_t { auto result(x); @@ -4368,7 +4351,7 @@ return result; } - friend inline WIDE_DECIMAL_CONSTEXPR auto ceil(const decwide_t& x) -> decwide_t + friend inline auto ceil(const decwide_t& x) -> decwide_t { auto result(x); @@ -4390,7 +4373,7 @@ return result; } - friend inline WIDE_DECIMAL_CONSTEXPR auto ilogb(const decwide_t& x) -> exponent_type + friend inline auto ilogb(const decwide_t& x) -> exponent_type { using local_size_type = typename representation_type::size_type; @@ -4494,9 +4477,9 @@ #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) #else template std::array::limb_type, static_cast((decwide_t::decwide_t_elems_for_kara - 1) * 2)> decwide_t::my_school_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables) - template std::array::limb_type, static_cast(detail::a029750_as_constexpr (static_cast(static_cast(decwide_t::decwide_t_elems_for_fft - 1)) * 8UL))> decwide_t::my_kara_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - template std::array::fft_float_type, static_cast(detail::a000079_as_constexpr(static_cast(static_cast(decwide_t::decwide_t_elem_number)) * 4UL))> decwide_t::my_af_fft_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp) - template std::array::fft_float_type, static_cast(detail::a000079_as_constexpr(static_cast(static_cast(decwide_t::decwide_t_elem_number)) * 4UL))> decwide_t::my_bf_fft_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp) + template std::array::limb_type, static_cast(detail::a029750::a029750_as_constexpr (static_cast(static_cast(decwide_t::decwide_t_elems_for_fft - 1)) * 8UL))> decwide_t::my_kara_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + template std::array::fft_float_type, static_cast(detail::a000079::a000079_as_constexpr(static_cast(static_cast(decwide_t::decwide_t_elem_number)) * 4UL))> decwide_t::my_af_fft_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp) + template std::array::fft_float_type, static_cast(detail::a000079::a000079_as_constexpr(static_cast(static_cast(decwide_t::decwide_t_elem_number)) * 4UL))> decwide_t::my_bf_fft_mul_pool; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp) template typename decwide_t::representation_type decwide_t::my_n_data_for_add_sub; // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix,cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp) #endif @@ -4552,9 +4535,9 @@ // Set up the range for dynamic detection of scientific notation. // If the exponent is less than -4 or larger than a precision-dependent // positive bound, then scientific notation is used. - constexpr auto neg_bound_for_scientific_neg_exp = static_cast(INT8_C(-4)); - const auto min_bound_for_scientific_pos_exp = util::max_unsafe(static_cast(os_precision), static_cast(prec_default)); - const auto pos_bound_for_scientific_pos_exp = util::min_unsafe(static_cast(decwide_t_digits10), min_bound_for_scientific_pos_exp); + static const auto neg_bound_for_scientific_neg_exp = static_cast(INT8_C(-4)); + const auto min_bound_for_scientific_pos_exp = (std::max)(static_cast(os_precision), static_cast(prec_default)); + const auto pos_bound_for_scientific_pos_exp = (std::min)(static_cast(decwide_t_digits10), min_bound_for_scientific_pos_exp); if( (the_exp < neg_bound_for_scientific_neg_exp) || (the_exp >= pos_bound_for_scientific_pos_exp) @@ -4588,7 +4571,7 @@ static_cast(UINT8_C(1)) + os_precision ); - number_of_digits10_i_want = util::min_unsafe(max10_plus_one, prec_plus_one); + number_of_digits10_i_want = (std::min)(max10_plus_one, prec_plus_one); } if(use_fixed) @@ -4607,12 +4590,12 @@ number_of_digits10_i_want = static_cast ( - util::min_unsafe(exp_plus_one_plus_my_precision, static_cast(max10_plus_one)) + (std::min)(exp_plus_one_plus_my_precision, static_cast(max10_plus_one)) ); } else { - number_of_digits10_i_want = util::min_unsafe(os_precision, max10_plus_one); + number_of_digits10_i_want = (std::min)(os_precision, max10_plus_one); } } @@ -4621,9 +4604,9 @@ // nor decwide_t's max_digits10. if(my_float_field == detail::os_float_field_type::none) { - const auto max_dig10 = util::min_unsafe(os_precision, static_cast(decwide_t_max_digits10)); + const auto max_dig10 = (std::min)(os_precision, static_cast(decwide_t_max_digits10)); - number_of_digits10_i_want = util::min_unsafe(number_of_digits10_i_want, max_dig10); + number_of_digits10_i_want = (std::min)(number_of_digits10_i_want, max_dig10); } // Extract the rounded output string with the desired number of digits. @@ -4677,9 +4660,9 @@ typename ExponentType, typename FftFloatType> #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t> + auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t> + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type #endif { // Compute pi using a quadratically convergent Gauss AGM. @@ -4726,12 +4709,12 @@ // than about 25 or 30. After about 20 iterations, the precision // is about one million decimal digits. - constexpr auto digits10_iteration_goal = + const auto digits10_iteration_goal = static_cast ( static_cast(std::numeric_limits::digits10 / 2) - + util::max_unsafe(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), - static_cast(UINT8_C(9))) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(UINT8_C(9))) ); using std::log; @@ -4748,7 +4731,7 @@ ( 1000.0F * log(static_cast(std::numeric_limits::radix)) ) - / 2.30258509299404568402F + / log(10.0F) ) ) ); @@ -4770,7 +4753,7 @@ local_wide_decimal_type iterate_term(bB); iterate_term -= val_pi; - iterate_term *= static_cast(static_cast(UINT8_C(1)) << static_cast(k + static_cast(UINT8_C(1)))); // NOLINT(google-runtime-int) + iterate_term *= static_cast(1ULL << (k + static_cast(UINT8_C(1)))); // NOLINT(google-runtime-int) s += iterate_term; @@ -4780,8 +4763,8 @@ const auto ib = static_cast ( - util::max_unsafe(static_cast(INT8_C(0)), - static_cast(-ilogb(iterate_term))) + (std::max)(static_cast(INT8_C(0)), + static_cast(-ilogb(iterate_term))) ); const auto digits10_of_iteration = @@ -4830,9 +4813,9 @@ typename ExponentType, typename FftFloatType> #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type #endif { // N[Pi, 121] @@ -4867,9 +4850,9 @@ typename ExponentType, typename FftFloatType> #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type #endif { // N[Pi, 121] @@ -4904,9 +4887,9 @@ typename ExponentType, typename FftFloatType> #if !defined(WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION) - auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_pi(const std::function& pfn_callback_to_report_digits10) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type #else - auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_pi(void(*pfn_callback_to_report_digits10)(const std::uint32_t)) -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type #endif { // N[Pi, 121] @@ -4935,7 +4918,7 @@ } template - auto calc_ln_two() -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t> + auto calc_ln_two() -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -4954,8 +4937,8 @@ // Ensure that the resulting power is non-negative. // Also enforce that m >= 3. - constexpr auto m = - util::max_unsafe + const auto m = + (std::max) ( static_cast(n_times_factor), static_cast(3) @@ -4968,8 +4951,8 @@ static_cast ( static_cast(std::numeric_limits::digits10 / 2) - + util::max_unsafe(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), - static_cast(UINT8_C(9))) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(UINT8_C(9))) ); using std::log; @@ -5002,8 +4985,8 @@ // half of the requested digits have been achieved, // then break after the upcoming iteration. - const auto ib = util::max_unsafe(static_cast(INT8_C(0)), - static_cast(-ilogb(ak - bk))); + const auto ib = (std::max)(static_cast(INT8_C(0)), + static_cast(-ilogb(ak - bk))); const auto digits10_of_iteration = static_cast @@ -5041,7 +5024,7 @@ } template - auto calc_ln_two() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_ln_two() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type { // N[Log[2], 121] // 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857337 @@ -5068,7 +5051,7 @@ } template - auto calc_ln_two() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_ln_two() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type { // N[Log[2], 121] // 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857337 @@ -5095,7 +5078,7 @@ } template - auto calc_ln_two() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_ln_two() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type { // N[Log[2], 121] // 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857337 @@ -5122,7 +5105,7 @@ } template - auto calc_ln_ten_low_precision() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_ln_ten_low_precision() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type { // N[Log[10], 121] // 2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286248633 @@ -5148,7 +5131,7 @@ } template - auto calc_ln_ten_low_precision() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_ln_ten_low_precision() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type { // N[Log[10], 121] // 2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286248633 @@ -5174,7 +5157,7 @@ } template - auto calc_ln_ten_low_precision() -> std::enable_if_t<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t> + auto calc_ln_ten_low_precision() -> typename std::enable_if<((ParamDigitsBaseTen <= static_cast(INT8_C(51))) && std::is_same::value), decwide_t>::type { // N[Log[10], 121] // 2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286248633 @@ -5240,22 +5223,21 @@ #endif // Global unary operators of decwide_t reference. - template WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& self) -> decwide_t { return self; } - template WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& self) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(self).negate(); } + template auto operator+(const decwide_t& self) -> decwide_t { return self; } + template auto operator-(const decwide_t& self) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(self).negate(); } // Global add/sub/mul/div of const decwide_t& with const decwide_t&. - template WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) += v; } - template WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) -= v; } - template WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) *= v; } - template WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) /= v; } + templateauto operator+(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) += v; } + templateauto operator-(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) -= v; } + templateauto operator*(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) *= v; } + templateauto operator/(const decwide_t& u, const decwide_t& v) -> decwide_t { using local_wide_decimal_type = decwide_t; return local_wide_decimal_type(u) /= v; } // Global add/sub/mul/div of const decwide_t& with all built-in types. template - WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5263,11 +5245,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5275,10 +5256,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator+(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5286,11 +5266,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5298,11 +5277,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5311,10 +5289,9 @@ // LCOV_EXCL_START template - WIDE_DECIMAL_CONSTEXPR auto operator-(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5323,11 +5300,10 @@ // LCOV_EXCL_STOP template - WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5335,11 +5311,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5347,10 +5322,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator*(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5358,11 +5332,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5370,11 +5343,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5382,10 +5354,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator/(const decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5394,11 +5365,10 @@ // Global add/sub/mul/div of all built-in types with const decwide_t&. template - WIDE_DECIMAL_CONSTEXPR auto operator+(SignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5406,11 +5376,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator+(UnsignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5418,10 +5387,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator+(FloatingPointType f, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t> + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5429,10 +5397,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator-(ArithmeticType n, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t> + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5440,11 +5407,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator*(SignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5452,11 +5418,10 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator*(UnsignedIntegralType n, - const decwide_t& u) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + const decwide_t& u) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5464,10 +5429,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator*(FloatingPointType f, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t> + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5475,10 +5439,9 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator/(ArithmeticType n, - const decwide_t& u) -> std::enable_if_t::value, - decwide_t> + const decwide_t& u) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5487,31 +5450,28 @@ // Global self add/sub/mul/div of decwide_t& with all built-in types. template - WIDE_DECIMAL_CONSTEXPR auto operator+=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { return u.add_signed_long_long(n); } // LCOV_EXCL_START template - WIDE_DECIMAL_CONSTEXPR auto operator+=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { return u.add_unsigned_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator+=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5519,30 +5479,27 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator-=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { return u.sub_signed_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator-=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { return u.sub_unsigned_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator-=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5550,30 +5507,27 @@ } template - WIDE_DECIMAL_CONSTEXPR auto operator*=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { return u.mul_signed_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator*=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { return u.mul_unsigned_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator*=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5582,30 +5536,27 @@ // LCOV_EXCL_STOP template - WIDE_DECIMAL_CONSTEXPR auto operator/=(decwide_t& u, - SignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && (!std::is_unsigned::value), - decwide_t> + SignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && (!std::is_unsigned::value), + decwide_t>::type { return u.div_signed_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator/=(decwide_t& u, - UnsignedIntegralType n) -> std::enable_if_t< std::is_integral::value - && std::is_unsigned::value, - decwide_t> + UnsignedIntegralType n) -> typename std::enable_if< std::is_integral::value + && std::is_unsigned::value, + decwide_t>::type { return u.div_unsigned_long_long(n); } template - WIDE_DECIMAL_CONSTEXPR auto operator/=(decwide_t& u, - FloatingPointType f) -> std::enable_if_t::value, - decwide_t> + FloatingPointType f) -> typename std::enable_if::value, + decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -5613,28 +5564,28 @@ } // Global comparison operators of const decwide_t& with const decwide_t&. - template WIDE_DECIMAL_CONSTEXPR auto operator< (const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) < static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator<=(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) <= static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator==(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) == static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator!=(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) != static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator>=(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) >= static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator> (const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) > static_cast(INT8_C(0))); } + template auto operator< (const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) < static_cast(INT8_C(0))); } + template auto operator<=(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) <= static_cast(INT8_C(0))); } + template auto operator==(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) == static_cast(INT8_C(0))); } + template auto operator!=(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) != static_cast(INT8_C(0))); } + template auto operator>=(const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) >= static_cast(INT8_C(0))); } + template auto operator> (const decwide_t& u, const decwide_t& v) -> bool { return (u.cmp(v) > static_cast(INT8_C(0))); } // Global comparison operators of const decwide_t& with all built-in types. - template WIDE_DECIMAL_CONSTEXPR auto operator< (const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool> { return (u.cmp(decwide_t(v)) < static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator<=(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool> { return (u.cmp(decwide_t(v)) <= static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator==(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool> { return (u.cmp(decwide_t(v)) == static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator!=(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool> { return (u.cmp(decwide_t(v)) != static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator>=(const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool> { return (u.cmp(decwide_t(v)) >= static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator> (const decwide_t& u, const ArithmeticType& v) -> std::enable_if_t::value, bool> { return (u.cmp(decwide_t(v)) > static_cast(INT8_C(0))); } + template auto operator< (const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type { return (u.cmp(decwide_t(v)) < static_cast(INT8_C(0))); } + template auto operator<=(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type { return (u.cmp(decwide_t(v)) <= static_cast(INT8_C(0))); } + template auto operator==(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type { return (u.cmp(decwide_t(v)) == static_cast(INT8_C(0))); } + template auto operator!=(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type { return (u.cmp(decwide_t(v)) != static_cast(INT8_C(0))); } + template auto operator>=(const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type { return (u.cmp(decwide_t(v)) >= static_cast(INT8_C(0))); } + template auto operator> (const decwide_t& u, const ArithmeticType& v) -> typename std::enable_if::value, bool>::type { return (u.cmp(decwide_t(v)) > static_cast(INT8_C(0))); } // Global comparison operators of all built-in types with const decwide_t&. - template WIDE_DECIMAL_CONSTEXPR auto operator< (ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool> { return (decwide_t(u).cmp(v) < static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator<=(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool> { return (decwide_t(u).cmp(v) <= static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator==(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool> { return (decwide_t(u).cmp(v) == static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator!=(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool> { return (decwide_t(u).cmp(v) != static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator>=(ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool> { return (decwide_t(u).cmp(v) >= static_cast(INT8_C(0))); } - template WIDE_DECIMAL_CONSTEXPR auto operator> (ArithmeticType u, const decwide_t& v) -> std::enable_if_t::value, bool> { return (decwide_t(u).cmp(v) > static_cast(INT8_C(0))); } + template auto operator< (ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type { return (decwide_t(u).cmp(v) < static_cast(INT8_C(0))); } + template auto operator<=(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type { return (decwide_t(u).cmp(v) <= static_cast(INT8_C(0))); } + template auto operator==(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type { return (decwide_t(u).cmp(v) == static_cast(INT8_C(0))); } + template auto operator!=(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type { return (decwide_t(u).cmp(v) != static_cast(INT8_C(0))); } + template auto operator>=(ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type { return (decwide_t(u).cmp(v) >= static_cast(INT8_C(0))); } + template auto operator> (ArithmeticType u, const decwide_t& v) -> typename std::enable_if::value, bool>::type { return (decwide_t(u).cmp(v) > static_cast(INT8_C(0))); } #if(__cplusplus >= 201703L) } // namespace math::wide_decimal @@ -5755,7 +5706,6 @@ template auto (signbit) (const decwide_t& x) -> bool { return x.isneg(); } template - WIDE_DECIMAL_CONSTEXPR auto pow(const decwide_t& x, const decwide_t& a) -> decwide_t { @@ -5765,7 +5715,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto ldexp(const decwide_t& v, int e) -> decwide_t { if(e == static_cast(INT8_C(0))) @@ -5789,7 +5738,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto frexp(const decwide_t& v, int* expon) -> decwide_t { @@ -5882,7 +5830,7 @@ } template - auto log(const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t> // NOLINT(misc-no-recursion) + auto log(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type // NOLINT(misc-no-recursion) { using local_wide_decimal_type = decwide_t; @@ -5926,12 +5874,12 @@ * log(static_cast(std::numeric_limits::radix)) ); - const auto lg_x_over_lg2 = static_cast(lg_x_approx / 0.693147180559945309417F); + const auto lg_x_over_lg2 = static_cast(lg_x_approx / log(2.0F)); // Ensure that the resulting power is non-negative. // Also enforce that m >= 3. - const auto m = util::max_unsafe(static_cast(n_times_factor - lg_x_over_lg2), - static_cast(3)); + const auto m = (std::max)(static_cast(n_times_factor - lg_x_over_lg2), + static_cast(3)); local_wide_decimal_type bk = one(); @@ -5943,26 +5891,26 @@ bk /= x; // TBD: Tolerance should have the log of the argument added to it (usually negligible). - constexpr auto digits10_iteration_goal_a = + const auto digits10_iteration_goal_a = static_cast ( static_cast(std::numeric_limits::digits10 / 2) - + util::max_unsafe(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), - static_cast(UINT8_C(9))) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(UINT8_C(9))) ); const auto digits10_iteration_goal_b = static_cast ( static_cast(precision_of_x / 2) - + util::max_unsafe(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), - static_cast(UINT8_C(9))) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(UINT8_C(9))) ); const auto digits10_iteration_goal = static_cast ( - util::min_unsafe(digits10_iteration_goal_a, digits10_iteration_goal_b) + (std::min)(digits10_iteration_goal_a, digits10_iteration_goal_b) ); using std::lround; @@ -5991,8 +5939,8 @@ // then break after the upcoming iteration. const auto ilogb_of_ak_minus_bk = - util::max_unsafe(static_cast(INT8_C(0)), - static_cast(-ilogb(result - bk))); + (std::max)(static_cast(INT8_C(0)), + static_cast(-ilogb(result - bk))); const auto digits10_of_iteration = static_cast @@ -6034,7 +5982,7 @@ } template - auto log(const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen <= static_cast(INT8_C(51))), decwide_t> // NOLINT(misc-no-recursion) + auto log(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen <= static_cast(INT8_C(51))), decwide_t>::type // NOLINT(misc-no-recursion) { using local_wide_decimal_type = decwide_t; @@ -6118,8 +6066,8 @@ if(i > static_cast(UINT8_C(4))) { const auto digits10_of_series = - util::max_unsafe(static_cast(INT8_C(0)), - static_cast(-ilogb(y_pow_n))); + (std::max)(static_cast(INT8_C(0)), + static_cast(-ilogb(y_pow_n))); if(y_pow_n.iszero() || (digits10_of_series > digits10_series_goal)) { @@ -6148,7 +6096,7 @@ } template - auto exp(const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen > static_cast(INT32_C(2000))), decwide_t> + auto exp(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT32_C(2000))), decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -6194,7 +6142,7 @@ { // Adjust precision of the terms. const auto min_elem_digits10_plus_one = - util::min_unsafe + (std::min) ( static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(INT8_C(9)) @@ -6244,7 +6192,7 @@ } template - auto exp(const decwide_t& x) -> std::enable_if_t<(ParamDigitsBaseTen <= static_cast(INT32_C(2000))), decwide_t> + auto exp(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen <= static_cast(INT32_C(2000))), decwide_t>::type { using local_wide_decimal_type = decwide_t; @@ -6303,15 +6251,15 @@ using std::ilogb; const auto iteration_goal_ilobg = - util::max_unsafe(static_cast(INT8_C(0)), - static_cast(-ilogb(std::numeric_limits::epsilon()))); + (std::max)(static_cast(INT8_C(0)), + static_cast(-ilogb(std::numeric_limits::epsilon()))); const auto iteration_goal_prec = static_cast(precision_of_x); const auto digits10_iteration_goal = static_cast ( - util::min_unsafe(iteration_goal_ilobg, iteration_goal_prec) + (std::min)(iteration_goal_ilobg, iteration_goal_prec) ); // Series expansion of hypergeometric_0f0(; ; x). @@ -6328,8 +6276,8 @@ // But only do this following the first few iterations. const auto iteration_result_so_far = - util::max_unsafe(static_cast(INT8_C(0)), - static_cast(-ilogb(x_pow_n_div_n_fact))); + (std::max)(static_cast(INT8_C(0)), + static_cast(-ilogb(x_pow_n_div_n_fact))); if(iteration_result_so_far > digits10_iteration_goal) { @@ -6395,7 +6343,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto pow(const decwide_t& b, std::int64_t p) -> decwide_t // NOLINT(misc-no-recursion) { // Calculate (b ^ p). 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 d1aac0abd..5ad9a6233 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail.h @@ -14,31 +14,30 @@ #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 #if defined(_MSC_VER) #if (_MSC_VER >= 1900) && defined(_HAS_CXX20) && (_HAS_CXX20 != 0) - #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) + #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) #else #define WIDE_DECIMAL_NODISCARD #endif #else #if (defined(__cplusplus) && (__cplusplus >= 201402L)) #if defined(__AVR__) && (!defined(__GNUC__) || (defined(__GNUC__) && (__GNUC__ > 6))) - #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) + #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) #elif (defined(__cpp_lib_constexpr_algorithms) && (__cpp_lib_constexpr_algorithms>=201806)) #if defined(__clang__) #if (__clang_major__ > 9) - #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) + #define WIDE_DECIMAL_NODISCARD [[nodiscard]] // NOLINT(cppcoreguidelines-macro-usage) #else #define WIDE_DECIMAL_NODISCARD #endif @@ -59,24 +58,6 @@ #endif #endif - #if defined(_MSVC_LANG) - #if (_MSVC_LANG >= 202002L) - #define WIDE_DECIMAL_CONSTEXPR constexpr // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_DECIMAL_CONSTEXPR_IS_COMPILE_TIME_CONST 1 // NOLINT(cppcoreguidelines-macro-usage) - #else - #define WIDE_DECIMAL_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_DECIMAL_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #endif - #else - #if (__cplusplus >= 202002L) - #define WIDE_DECIMAL_CONSTEXPR constexpr // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_DECIMAL_CONSTEXPR_IS_COMPILE_TIME_CONST 1 // NOLINT(cppcoreguidelines-macro-usage) - #else - #define WIDE_DECIMAL_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_DECIMAL_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #endif - #endif - WIDE_DECIMAL_NAMESPACE_BEGIN #if(__cplusplus >= 201703L) @@ -110,14 +91,14 @@ using fast_signed_type = std::intmax_t; }; - template struct uint_type_helper(UINT8_C( 8)))>> { using exact_unsigned_type = std::uint8_t; using exact_signed_type = std::int8_t; using fast_unsigned_type = std::uint_fast8_t; using fast_signed_type = std::int_fast8_t; }; - template struct uint_type_helper= static_cast(UINT8_C( 9))) && (BitCount <= static_cast(UINT8_C( 16)))>> { using exact_unsigned_type = std::uint16_t; using exact_signed_type = std::int16_t; using fast_unsigned_type = std::uint_fast16_t; using fast_signed_type = std::int_fast16_t; }; - template struct uint_type_helper= static_cast(UINT8_C(17))) && (BitCount <= static_cast(UINT8_C( 32)))>> { using exact_unsigned_type = std::uint32_t; using exact_signed_type = std::int32_t; using fast_unsigned_type = std::uint_fast32_t; using fast_signed_type = std::int_fast32_t; }; - template struct uint_type_helper= static_cast(UINT8_C(33))) && (BitCount <= static_cast(UINT8_C( 64)))>> { using exact_unsigned_type = std::uint64_t; using exact_signed_type = std::int64_t; using fast_unsigned_type = std::uint_fast64_t; using fast_signed_type = std::int_fast64_t; }; + template struct uint_type_helper(UINT8_C( 8)))>::type> { using exact_unsigned_type = std::uint8_t; using exact_signed_type = std::int8_t; using fast_unsigned_type = std::uint_fast8_t; using fast_signed_type = std::int_fast8_t; }; + template struct uint_type_helper= static_cast(UINT8_C( 9))) && (BitCount <= static_cast(UINT8_C( 16)))>::type> { using exact_unsigned_type = std::uint16_t; using exact_signed_type = std::int16_t; using fast_unsigned_type = std::uint_fast16_t; using fast_signed_type = std::int_fast16_t; }; + template struct uint_type_helper= static_cast(UINT8_C(17))) && (BitCount <= static_cast(UINT8_C( 32)))>::type> { using exact_unsigned_type = std::uint32_t; using exact_signed_type = std::int32_t; using fast_unsigned_type = std::uint_fast32_t; using fast_signed_type = std::int_fast32_t; }; + template struct uint_type_helper= static_cast(UINT8_C(33))) && (BitCount <= static_cast(UINT8_C( 64)))>::type> { using exact_unsigned_type = std::uint64_t; using exact_signed_type = std::int64_t; using fast_unsigned_type = std::uint_fast64_t; using fast_signed_type = std::int_fast64_t; }; template - constexpr auto negate(UnsignedIntegralType u) -> typename std::enable_if_t<( std::is_integral::value - && std::is_unsigned::value), UnsignedIntegralType> + constexpr auto negate(UnsignedIntegralType u) -> typename std::enable_if<( std::is_integral::value + && std::is_unsigned::value), UnsignedIntegralType>::type { using local_unsigned_integral_type = UnsignedIntegralType; @@ -129,8 +110,8 @@ } template - constexpr auto negate(SignedIntegralType n) -> typename std::enable_if_t<( std::is_integral::value - && std::is_signed ::value), SignedIntegralType> + constexpr auto negate(SignedIntegralType n) -> typename std::enable_if<( std::is_integral::value + && std::is_signed ::value), SignedIntegralType>::type { using local_signed_integral_type = SignedIntegralType; @@ -141,85 +122,85 @@ ); } - #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) - #else - // LCOV_EXCL_START - constexpr auto a029750_as_constexpr(std::uint32_t value) noexcept -> std::uint32_t // NOLINT(readability-function-cognitive-complexity) - { - // Sloane's A029750 List of numbers of the form 2^k times 1, 3, 5 or 7. - // CoefficientList[Series[-(x + 1)^2 (x^2 + 1)^2/(2 x^4 - 1), {x, 0, 91}], x] - return ((value <= static_cast(UINT32_C( 32))) ? static_cast(UINT32_C( 32)) : ((value <= static_cast(UINT32_C( 40))) ? static_cast(UINT32_C( 40)) : ((value <= static_cast(UINT32_C( 48))) ? static_cast(UINT32_C( 48)) : ((value <= static_cast(UINT32_C( 56))) ? static_cast(UINT32_C( 56)) : - ((value <= static_cast(UINT32_C( 64))) ? static_cast(UINT32_C( 64)) : ((value <= static_cast(UINT32_C( 80))) ? static_cast(UINT32_C( 80)) : ((value <= static_cast(UINT32_C( 96))) ? static_cast(UINT32_C( 96)) : ((value <= static_cast(UINT32_C( 112))) ? static_cast(UINT32_C( 112)) : - ((value <= static_cast(UINT32_C( 128))) ? static_cast(UINT32_C( 128)) : ((value <= static_cast(UINT32_C( 160))) ? static_cast(UINT32_C( 160)) : ((value <= static_cast(UINT32_C( 192))) ? static_cast(UINT32_C( 192)) : ((value <= static_cast(UINT32_C( 224))) ? static_cast(UINT32_C( 224)) : - ((value <= static_cast(UINT32_C( 256))) ? static_cast(UINT32_C( 256)) : ((value <= static_cast(UINT32_C( 320))) ? static_cast(UINT32_C( 320)) : ((value <= static_cast(UINT32_C( 384))) ? static_cast(UINT32_C( 384)) : ((value <= static_cast(UINT32_C( 448))) ? static_cast(UINT32_C( 448)) : - ((value <= static_cast(UINT32_C( 512))) ? static_cast(UINT32_C( 512)) : ((value <= static_cast(UINT32_C( 640))) ? static_cast(UINT32_C( 640)) : ((value <= static_cast(UINT32_C( 768))) ? static_cast(UINT32_C( 768)) : ((value <= static_cast(UINT32_C( 896))) ? static_cast(UINT32_C( 896)) : - ((value <= static_cast(UINT32_C( 1024))) ? static_cast(UINT32_C( 1024)) : ((value <= static_cast(UINT32_C( 1280))) ? static_cast(UINT32_C( 1280)) : ((value <= static_cast(UINT32_C( 1536))) ? static_cast(UINT32_C( 1536)) : ((value <= static_cast(UINT32_C( 1792))) ? static_cast(UINT32_C( 1792)) : - ((value <= static_cast(UINT32_C( 2048))) ? static_cast(UINT32_C( 2048)) : ((value <= static_cast(UINT32_C( 2560))) ? static_cast(UINT32_C( 2560)) : ((value <= static_cast(UINT32_C( 3072))) ? static_cast(UINT32_C( 3072)) : ((value <= static_cast(UINT32_C( 3584))) ? static_cast(UINT32_C( 3584)) : - ((value <= static_cast(UINT32_C( 4096))) ? static_cast(UINT32_C( 4096)) : ((value <= static_cast(UINT32_C( 5120))) ? static_cast(UINT32_C( 5120)) : ((value <= static_cast(UINT32_C( 6144))) ? static_cast(UINT32_C( 6144)) : ((value <= static_cast(UINT32_C( 7168))) ? static_cast(UINT32_C( 7168)) : - ((value <= static_cast(UINT32_C( 8192))) ? static_cast(UINT32_C( 8192)) : ((value <= static_cast(UINT32_C( 10240))) ? static_cast(UINT32_C( 10240)) : ((value <= static_cast(UINT32_C( 12288))) ? static_cast(UINT32_C( 12288)) : ((value <= static_cast(UINT32_C( 14336))) ? static_cast(UINT32_C( 14336)) : - ((value <= static_cast(UINT32_C( 16384))) ? static_cast(UINT32_C( 16384)) : ((value <= static_cast(UINT32_C( 20480))) ? static_cast(UINT32_C( 20480)) : ((value <= static_cast(UINT32_C( 24576))) ? static_cast(UINT32_C( 24576)) : ((value <= static_cast(UINT32_C( 28672))) ? static_cast(UINT32_C( 28672)) : - ((value <= static_cast(UINT32_C( 32768))) ? static_cast(UINT32_C( 32768)) : ((value <= static_cast(UINT32_C( 40960))) ? static_cast(UINT32_C( 40960)) : ((value <= static_cast(UINT32_C( 49152))) ? static_cast(UINT32_C( 49152)) : ((value <= static_cast(UINT32_C( 57344))) ? static_cast(UINT32_C( 57344)) : - ((value <= static_cast(UINT32_C( 65536))) ? static_cast(UINT32_C( 65536)) : ((value <= static_cast(UINT32_C( 81920))) ? static_cast(UINT32_C( 81920)) : ((value <= static_cast(UINT32_C( 98304))) ? static_cast(UINT32_C( 98304)) : ((value <= static_cast(UINT32_C( 114688))) ? static_cast(UINT32_C( 114688)) : - ((value <= static_cast(UINT32_C( 131072))) ? static_cast(UINT32_C( 131072)) : ((value <= static_cast(UINT32_C( 163840))) ? static_cast(UINT32_C( 163840)) : ((value <= static_cast(UINT32_C( 196608))) ? static_cast(UINT32_C( 196608)) : ((value <= static_cast(UINT32_C( 229376))) ? static_cast(UINT32_C( 229376)) : - ((value <= static_cast(UINT32_C( 262144))) ? static_cast(UINT32_C( 262144)) : ((value <= static_cast(UINT32_C( 327680))) ? static_cast(UINT32_C( 327680)) : ((value <= static_cast(UINT32_C( 393216))) ? static_cast(UINT32_C( 393216)) : ((value <= static_cast(UINT32_C( 458752))) ? static_cast(UINT32_C( 458752)) : - ((value <= static_cast(UINT32_C( 524288))) ? static_cast(UINT32_C( 524288)) : ((value <= static_cast(UINT32_C( 655360))) ? static_cast(UINT32_C( 655360)) : ((value <= static_cast(UINT32_C( 786432))) ? static_cast(UINT32_C( 786432)) : ((value <= static_cast(UINT32_C( 917504))) ? static_cast(UINT32_C( 917504)) : - ((value <= static_cast(UINT32_C(1048576))) ? static_cast(UINT32_C(1048576)) : ((value <= static_cast(UINT32_C( 1310720))) ? static_cast(UINT32_C( 1310720)) : ((value <= static_cast(UINT32_C( 1572864))) ? static_cast(UINT32_C( 1572864)) : ((value <= static_cast(UINT32_C( 1835008))) ? static_cast(UINT32_C( 1835008)) : static_cast(UINT32_C(2097152)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))); - } - // LCOV_EXCL_STOP - #endif - - constexpr auto a029750_as_runtime_value(std::uint32_t value) noexcept -> std::uint32_t + struct a029750 { - // Use Sloane's A029750: The so-called 7-smooth numbers having the form 2^k times 1, 3, 5 or 7. - // CoefficientList[Series[-(x + 1)^2 (x^2 + 1)^2/(2 x^4 - 1), {x, 0, 91}], x] - constexpr std::uint32_t a029750_data[static_cast(UINT8_C(65))] = // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + #if !defined(WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION) + #else + // LCOV_EXCL_START + static constexpr auto a029750_as_constexpr(std::uint32_t value) noexcept -> std::uint32_t // NOLINT(readability-function-cognitive-complexity) { - static_cast(UINT32_C( 32)), static_cast(UINT32_C( 40)), static_cast(UINT32_C( 48)), static_cast(UINT32_C( 56)), - static_cast(UINT32_C( 64)), static_cast(UINT32_C( 80)), static_cast(UINT32_C( 96)), static_cast(UINT32_C( 112)), - static_cast(UINT32_C( 128)), static_cast(UINT32_C( 160)), static_cast(UINT32_C( 192)), static_cast(UINT32_C( 224)), - static_cast(UINT32_C( 256)), static_cast(UINT32_C( 320)), static_cast(UINT32_C( 384)), static_cast(UINT32_C( 448)), - static_cast(UINT32_C( 512)), static_cast(UINT32_C( 640)), static_cast(UINT32_C( 768)), static_cast(UINT32_C( 896)), - static_cast(UINT32_C( 1024)), static_cast(UINT32_C( 1280)), static_cast(UINT32_C( 1536)), static_cast(UINT32_C( 1792)), - static_cast(UINT32_C( 2048)), static_cast(UINT32_C( 2560)), static_cast(UINT32_C( 3072)), static_cast(UINT32_C( 3584)), - static_cast(UINT32_C( 4096)), static_cast(UINT32_C( 5120)), static_cast(UINT32_C( 6144)), static_cast(UINT32_C( 7168)), - static_cast(UINT32_C( 8192)), static_cast(UINT32_C( 10240)), static_cast(UINT32_C( 12288)), static_cast(UINT32_C( 14336)), - static_cast(UINT32_C( 16384)), static_cast(UINT32_C( 20480)), static_cast(UINT32_C( 24576)), static_cast(UINT32_C( 28672)), - static_cast(UINT32_C( 32768)), static_cast(UINT32_C( 40960)), static_cast(UINT32_C( 49152)), static_cast(UINT32_C( 57344)), - static_cast(UINT32_C( 65536)), static_cast(UINT32_C( 81920)), static_cast(UINT32_C( 98304)), static_cast(UINT32_C( 114688)), - static_cast(UINT32_C( 131072)), static_cast(UINT32_C( 163840)), static_cast(UINT32_C( 196608)), static_cast(UINT32_C( 229376)), - static_cast(UINT32_C( 262144)), static_cast(UINT32_C( 327680)), static_cast(UINT32_C( 393216)), static_cast(UINT32_C( 458752)), - static_cast(UINT32_C( 524288)), static_cast(UINT32_C( 655360)), static_cast(UINT32_C( 786432)), static_cast(UINT32_C( 917504)), - static_cast(UINT32_C(1048576)), static_cast(UINT32_C(1310720)), static_cast(UINT32_C(1572864)), static_cast(UINT32_C(1835008)), - static_cast(UINT32_C(2097152)) - }; - - const std::uint32_t* it = util::lower_bound_unsafe(std::begin(a029750_data), std::end(a029750_data), value); - - const auto result = - static_cast - ( - (it != std::end(a029750_data)) - ? *it - : *(std::end(a029750_data) - static_cast(UINT8_C(1))) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - ); + // Sloane's A029750 List of numbers of the form 2^k times 1, 3, 5 or 7. + // CoefficientList[Series[-(x + 1)^2 (x^2 + 1)^2/(2 x^4 - 1), {x, 0, 91}], x] + return ((value <= static_cast(UINT32_C( 32))) ? static_cast(UINT32_C( 32)) : ((value <= static_cast(UINT32_C( 40))) ? static_cast(UINT32_C( 40)) : ((value <= static_cast(UINT32_C( 48))) ? static_cast(UINT32_C( 48)) : ((value <= static_cast(UINT32_C( 56))) ? static_cast(UINT32_C( 56)) : + ((value <= static_cast(UINT32_C( 64))) ? static_cast(UINT32_C( 64)) : ((value <= static_cast(UINT32_C( 80))) ? static_cast(UINT32_C( 80)) : ((value <= static_cast(UINT32_C( 96))) ? static_cast(UINT32_C( 96)) : ((value <= static_cast(UINT32_C( 112))) ? static_cast(UINT32_C( 112)) : + ((value <= static_cast(UINT32_C( 128))) ? static_cast(UINT32_C( 128)) : ((value <= static_cast(UINT32_C( 160))) ? static_cast(UINT32_C( 160)) : ((value <= static_cast(UINT32_C( 192))) ? static_cast(UINT32_C( 192)) : ((value <= static_cast(UINT32_C( 224))) ? static_cast(UINT32_C( 224)) : + ((value <= static_cast(UINT32_C( 256))) ? static_cast(UINT32_C( 256)) : ((value <= static_cast(UINT32_C( 320))) ? static_cast(UINT32_C( 320)) : ((value <= static_cast(UINT32_C( 384))) ? static_cast(UINT32_C( 384)) : ((value <= static_cast(UINT32_C( 448))) ? static_cast(UINT32_C( 448)) : + ((value <= static_cast(UINT32_C( 512))) ? static_cast(UINT32_C( 512)) : ((value <= static_cast(UINT32_C( 640))) ? static_cast(UINT32_C( 640)) : ((value <= static_cast(UINT32_C( 768))) ? static_cast(UINT32_C( 768)) : ((value <= static_cast(UINT32_C( 896))) ? static_cast(UINT32_C( 896)) : + ((value <= static_cast(UINT32_C( 1024))) ? static_cast(UINT32_C( 1024)) : ((value <= static_cast(UINT32_C( 1280))) ? static_cast(UINT32_C( 1280)) : ((value <= static_cast(UINT32_C( 1536))) ? static_cast(UINT32_C( 1536)) : ((value <= static_cast(UINT32_C( 1792))) ? static_cast(UINT32_C( 1792)) : + ((value <= static_cast(UINT32_C( 2048))) ? static_cast(UINT32_C( 2048)) : ((value <= static_cast(UINT32_C( 2560))) ? static_cast(UINT32_C( 2560)) : ((value <= static_cast(UINT32_C( 3072))) ? static_cast(UINT32_C( 3072)) : ((value <= static_cast(UINT32_C( 3584))) ? static_cast(UINT32_C( 3584)) : + ((value <= static_cast(UINT32_C( 4096))) ? static_cast(UINT32_C( 4096)) : ((value <= static_cast(UINT32_C( 5120))) ? static_cast(UINT32_C( 5120)) : ((value <= static_cast(UINT32_C( 6144))) ? static_cast(UINT32_C( 6144)) : ((value <= static_cast(UINT32_C( 7168))) ? static_cast(UINT32_C( 7168)) : + ((value <= static_cast(UINT32_C( 8192))) ? static_cast(UINT32_C( 8192)) : ((value <= static_cast(UINT32_C( 10240))) ? static_cast(UINT32_C( 10240)) : ((value <= static_cast(UINT32_C( 12288))) ? static_cast(UINT32_C( 12288)) : ((value <= static_cast(UINT32_C( 14336))) ? static_cast(UINT32_C( 14336)) : + ((value <= static_cast(UINT32_C( 16384))) ? static_cast(UINT32_C( 16384)) : ((value <= static_cast(UINT32_C( 20480))) ? static_cast(UINT32_C( 20480)) : ((value <= static_cast(UINT32_C( 24576))) ? static_cast(UINT32_C( 24576)) : ((value <= static_cast(UINT32_C( 28672))) ? static_cast(UINT32_C( 28672)) : + ((value <= static_cast(UINT32_C( 32768))) ? static_cast(UINT32_C( 32768)) : ((value <= static_cast(UINT32_C( 40960))) ? static_cast(UINT32_C( 40960)) : ((value <= static_cast(UINT32_C( 49152))) ? static_cast(UINT32_C( 49152)) : ((value <= static_cast(UINT32_C( 57344))) ? static_cast(UINT32_C( 57344)) : + ((value <= static_cast(UINT32_C( 65536))) ? static_cast(UINT32_C( 65536)) : ((value <= static_cast(UINT32_C( 81920))) ? static_cast(UINT32_C( 81920)) : ((value <= static_cast(UINT32_C( 98304))) ? static_cast(UINT32_C( 98304)) : ((value <= static_cast(UINT32_C( 114688))) ? static_cast(UINT32_C( 114688)) : + ((value <= static_cast(UINT32_C( 131072))) ? static_cast(UINT32_C( 131072)) : ((value <= static_cast(UINT32_C( 163840))) ? static_cast(UINT32_C( 163840)) : ((value <= static_cast(UINT32_C( 196608))) ? static_cast(UINT32_C( 196608)) : ((value <= static_cast(UINT32_C( 229376))) ? static_cast(UINT32_C( 229376)) : + ((value <= static_cast(UINT32_C( 262144))) ? static_cast(UINT32_C( 262144)) : ((value <= static_cast(UINT32_C( 327680))) ? static_cast(UINT32_C( 327680)) : ((value <= static_cast(UINT32_C( 393216))) ? static_cast(UINT32_C( 393216)) : ((value <= static_cast(UINT32_C( 458752))) ? static_cast(UINT32_C( 458752)) : + ((value <= static_cast(UINT32_C( 524288))) ? static_cast(UINT32_C( 524288)) : ((value <= static_cast(UINT32_C( 655360))) ? static_cast(UINT32_C( 655360)) : ((value <= static_cast(UINT32_C( 786432))) ? static_cast(UINT32_C( 786432)) : ((value <= static_cast(UINT32_C( 917504))) ? static_cast(UINT32_C( 917504)) : + ((value <= static_cast(UINT32_C(1048576))) ? static_cast(UINT32_C(1048576)) : ((value <= static_cast(UINT32_C( 1310720))) ? static_cast(UINT32_C( 1310720)) : ((value <= static_cast(UINT32_C( 1572864))) ? static_cast(UINT32_C( 1572864)) : ((value <= static_cast(UINT32_C( 1835008))) ? static_cast(UINT32_C( 1835008)) : static_cast(UINT32_C(2097152)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))); + } + // LCOV_EXCL_STOP + #endif - return result; - } + static auto a029750_as_runtime_value(std::uint32_t value) noexcept -> std::uint32_t + { + using local_array_type = std::array; // NOLINT(,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + + // Use Sloane's A029750: The so-called 7-smooth numbers having the form 2^k times 1, 3, 5 or 7. + // CoefficientList[Series[-(x + 1)^2 (x^2 + 1)^2/(2 x^4 - 1), {x, 0, 91}], x] + constexpr local_array_type a029750_data = + {{ + static_cast(UINT32_C( 32)), static_cast(UINT32_C( 40)), static_cast(UINT32_C( 48)), static_cast(UINT32_C( 56)), + static_cast(UINT32_C( 64)), static_cast(UINT32_C( 80)), static_cast(UINT32_C( 96)), static_cast(UINT32_C( 112)), + static_cast(UINT32_C( 128)), static_cast(UINT32_C( 160)), static_cast(UINT32_C( 192)), static_cast(UINT32_C( 224)), + static_cast(UINT32_C( 256)), static_cast(UINT32_C( 320)), static_cast(UINT32_C( 384)), static_cast(UINT32_C( 448)), + static_cast(UINT32_C( 512)), static_cast(UINT32_C( 640)), static_cast(UINT32_C( 768)), static_cast(UINT32_C( 896)), + static_cast(UINT32_C( 1024)), static_cast(UINT32_C( 1280)), static_cast(UINT32_C( 1536)), static_cast(UINT32_C( 1792)), + static_cast(UINT32_C( 2048)), static_cast(UINT32_C( 2560)), static_cast(UINT32_C( 3072)), static_cast(UINT32_C( 3584)), + static_cast(UINT32_C( 4096)), static_cast(UINT32_C( 5120)), static_cast(UINT32_C( 6144)), static_cast(UINT32_C( 7168)), + static_cast(UINT32_C( 8192)), static_cast(UINT32_C( 10240)), static_cast(UINT32_C( 12288)), static_cast(UINT32_C( 14336)), + static_cast(UINT32_C( 16384)), static_cast(UINT32_C( 20480)), static_cast(UINT32_C( 24576)), static_cast(UINT32_C( 28672)), + static_cast(UINT32_C( 32768)), static_cast(UINT32_C( 40960)), static_cast(UINT32_C( 49152)), static_cast(UINT32_C( 57344)), + static_cast(UINT32_C( 65536)), static_cast(UINT32_C( 81920)), static_cast(UINT32_C( 98304)), static_cast(UINT32_C( 114688)), + static_cast(UINT32_C( 131072)), static_cast(UINT32_C( 163840)), static_cast(UINT32_C( 196608)), static_cast(UINT32_C( 229376)), + static_cast(UINT32_C( 262144)), static_cast(UINT32_C( 327680)), static_cast(UINT32_C( 393216)), static_cast(UINT32_C( 458752)), + static_cast(UINT32_C( 524288)), static_cast(UINT32_C( 655360)), static_cast(UINT32_C( 786432)), static_cast(UINT32_C( 917504)), + static_cast(UINT32_C( 1048576)), static_cast(UINT32_C( 1310720)), static_cast(UINT32_C( 1572864)), static_cast(UINT32_C( 1835008)), + static_cast(UINT32_C( 2097152)) + }}; + + const auto it = std::lower_bound(a029750_data.cbegin(), a029750_data.cend(), value); // NOLINT(llvm-qualified-auto,readability-qualified-auto) + + return ((it != a029750_data.cend()) ? *it : a029750_data.back()); + } + }; - constexpr auto a000079_as_constexpr(const std::uint32_t value) noexcept -> std::uint32_t // NOLINT(readability-function-cognitive-complexity) + struct a000079 { - // Use Sloane's A000079: List of numbers of powers of 2. - // Table[2^n, {n, 0, 31, 1}] - return ((value <= static_cast(UINT32_C( 8))) ? static_cast(UINT32_C( 8)) : ((value <= static_cast(UINT32_C( 16))) ? static_cast(UINT32_C( 16)) : ((value <= static_cast(UINT32_C( 32))) ? static_cast(UINT32_C( 32)) : ((value <= static_cast(UINT32_C( 64))) ? static_cast(UINT32_C( 64)) : - ((value <= static_cast(UINT32_C( 128))) ? static_cast(UINT32_C( 128)) : ((value <= static_cast(UINT32_C( 256))) ? static_cast(UINT32_C( 256)) : ((value <= static_cast(UINT32_C( 512))) ? static_cast(UINT32_C( 512)) : ((value <= static_cast(UINT32_C( 1024))) ? static_cast(UINT32_C( 1024)) : - ((value <= static_cast(UINT32_C( 2048))) ? static_cast(UINT32_C( 2048)) : ((value <= static_cast(UINT32_C( 4096))) ? static_cast(UINT32_C( 4096)) : ((value <= static_cast(UINT32_C( 8192))) ? static_cast(UINT32_C( 8192)) : ((value <= static_cast(UINT32_C( 16384))) ? static_cast(UINT32_C( 16384)) : - // LCOV_EXCL_START - ((value <= static_cast(UINT32_C( 32768))) ? static_cast(UINT32_C( 32768)) : ((value <= static_cast(UINT32_C( 65536))) ? static_cast(UINT32_C( 65536)) : ((value <= static_cast(UINT32_C( 131072))) ? static_cast(UINT32_C( 131072)) : ((value <= static_cast(UINT32_C( 262144))) ? static_cast(UINT32_C( 262144)) : - ((value <= static_cast(UINT32_C( 524288))) ? static_cast(UINT32_C( 524288)) : ((value <= static_cast(UINT32_C( 1048576))) ? static_cast(UINT32_C( 1048576)) : ((value <= static_cast(UINT32_C( 2097152))) ? static_cast(UINT32_C( 2097152)) : ((value <= static_cast(UINT32_C( 4194304))) ? static_cast(UINT32_C( 4194304)) : - ((value <= static_cast(UINT32_C( 8388608))) ? static_cast(UINT32_C( 8388608)) : ((value <= static_cast(UINT32_C( 16777216))) ? static_cast(UINT32_C( 16777216)) : ((value <= static_cast(UINT32_C( 33554432))) ? static_cast(UINT32_C( 33554432)) : ((value <= static_cast(UINT32_C( 67108864))) ? static_cast(UINT32_C( 67108864)) : - ((value <= static_cast(UINT32_C(134217728))) ? static_cast(UINT32_C(134217728)) : ((value <= static_cast(UINT32_C(268435456))) ? static_cast(UINT32_C(268435456)) : ((value <= static_cast(UINT32_C(536870912))) ? static_cast(UINT32_C(536870912)) : ((value <= static_cast(UINT32_C(1073741824))) ? static_cast(UINT32_C(1073741824)) : static_cast(UINT32_C(2147483648)))))))))))))))))))))))))))))); - // LCOV_EXCL_STOP - } + static constexpr auto a000079_as_constexpr(const std::uint32_t value) noexcept -> std::uint32_t // NOLINT(readability-function-cognitive-complexity) + { + // Use Sloane's A000079: List of numbers of powers of 2. + // Table[2^n, {n, 0, 31, 1}] + return ((value <= static_cast(UINT32_C( 8))) ? static_cast(UINT32_C( 8)) : ((value <= static_cast(UINT32_C( 16))) ? static_cast(UINT32_C( 16)) : ((value <= static_cast(UINT32_C( 32))) ? static_cast(UINT32_C( 32)) : ((value <= static_cast(UINT32_C( 64))) ? static_cast(UINT32_C( 64)) : + ((value <= static_cast(UINT32_C( 128))) ? static_cast(UINT32_C( 128)) : ((value <= static_cast(UINT32_C( 256))) ? static_cast(UINT32_C( 256)) : ((value <= static_cast(UINT32_C( 512))) ? static_cast(UINT32_C( 512)) : ((value <= static_cast(UINT32_C( 1024))) ? static_cast(UINT32_C( 1024)) : + ((value <= static_cast(UINT32_C( 2048))) ? static_cast(UINT32_C( 2048)) : ((value <= static_cast(UINT32_C( 4096))) ? static_cast(UINT32_C( 4096)) : ((value <= static_cast(UINT32_C( 8192))) ? static_cast(UINT32_C( 8192)) : ((value <= static_cast(UINT32_C( 16384))) ? static_cast(UINT32_C( 16384)) : + // LCOV_EXCL_START + ((value <= static_cast(UINT32_C( 32768))) ? static_cast(UINT32_C( 32768)) : ((value <= static_cast(UINT32_C( 65536))) ? static_cast(UINT32_C( 65536)) : ((value <= static_cast(UINT32_C( 131072))) ? static_cast(UINT32_C( 131072)) : ((value <= static_cast(UINT32_C( 262144))) ? static_cast(UINT32_C( 262144)) : + ((value <= static_cast(UINT32_C( 524288))) ? static_cast(UINT32_C( 524288)) : ((value <= static_cast(UINT32_C( 1048576))) ? static_cast(UINT32_C( 1048576)) : ((value <= static_cast(UINT32_C( 2097152))) ? static_cast(UINT32_C( 2097152)) : ((value <= static_cast(UINT32_C( 4194304))) ? static_cast(UINT32_C( 4194304)) : + ((value <= static_cast(UINT32_C( 8388608))) ? static_cast(UINT32_C( 8388608)) : ((value <= static_cast(UINT32_C( 16777216))) ? static_cast(UINT32_C( 16777216)) : ((value <= static_cast(UINT32_C( 33554432))) ? static_cast(UINT32_C( 33554432)) : ((value <= static_cast(UINT32_C( 67108864))) ? static_cast(UINT32_C( 67108864)) : + ((value <= static_cast(UINT32_C(134217728))) ? static_cast(UINT32_C(134217728)) : ((value <= static_cast(UINT32_C(268435456))) ? static_cast(UINT32_C(268435456)) : ((value <= static_cast(UINT32_C(536870912))) ? static_cast(UINT32_C(536870912)) : ((value <= static_cast(UINT32_C(1073741824))) ? static_cast(UINT32_C(1073741824)) : static_cast(UINT32_C(2147483648)))))))))))))))))))))))))))))); + // LCOV_EXCL_STOP + } + }; // LCOV_EXCL_START constexpr auto pow10_maker(std::uint32_t n) noexcept -> std::uint32_t // NOLINT(misc-no-recursion) @@ -239,10 +220,12 @@ } // LCOV_EXCL_STOP - constexpr auto pow10_maker_as_runtime_value(std::uint32_t n) noexcept -> std::uint32_t + inline auto pow10_maker_as_runtime_value(std::uint32_t n) noexcept -> std::uint32_t { - constexpr std::uint32_t local_p10_table[static_cast(UINT8_C(10))] = // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - { + using local_array_type = std::array(UINT8_C(10))>; // NOLINT(,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + + constexpr local_array_type local_p10_table = + {{ static_cast(UINT32_C(1)), static_cast(UINT32_C(10)), static_cast(UINT32_C(100)), @@ -253,16 +236,15 @@ static_cast(UINT32_C(10000000)), static_cast(UINT32_C(100000000)), static_cast(UINT32_C(1000000000)) - }; + }}; - const std::uint32_t result = - ( - (n < static_cast(sizeof(local_p10_table) / sizeof(local_p10_table[static_cast(UINT8_C(0))]))) - ? local_p10_table[static_cast(n)] // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index) - : *(std::end(local_p10_table) - static_cast(UINT8_C(1))) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - ); + { + using local_size_type = typename local_array_type::size_type; - return result; + return ((n < static_cast(std::tuple_size::value)) + ? local_p10_table[static_cast(n)] + : local_p10_table.back()); // LCOV_EXCL_LINE + } } template typename base_class_type::size_type { return MySize; } - explicit constexpr fixed_dynamic_array(const typename base_class_type::size_type s = MySize, // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) - const typename base_class_type::value_type& v = typename base_class_type::value_type(), - const typename base_class_type::allocator_type& a = typename base_class_type::allocator_type()) noexcept + explicit fixed_dynamic_array(const typename base_class_type::size_type s = MySize, // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) + const typename base_class_type::value_type& v = typename base_class_type::value_type(), + const typename base_class_type::allocator_type& a = typename base_class_type::allocator_type()) noexcept : base_class_type(MySize, typename base_class_type::value_type(), a) { - util::fill_unsafe(base_class_type::begin(), - base_class_type::begin() + util::min_unsafe(MySize, static_cast(s)), - v); + std::fill(base_class_type::begin(), + base_class_type::begin() + (std::min)(MySize, static_cast(s)), + v); } constexpr fixed_dynamic_array(const fixed_dynamic_array& other) : base_class_type(static_cast(other)) { } - constexpr explicit fixed_dynamic_array(std::initializer_list lst) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + fixed_dynamic_array(std::initializer_list lst) : base_class_type(MySize) { - util::copy_unsafe(lst.begin(), - lst.begin() + util::min_unsafe(static_cast(lst.size()), MySize), - base_class_type::begin()); + std::copy(lst.begin(), + lst.begin() + (std::min)(static_cast(lst.size()), MySize), + base_class_type::begin()); } constexpr fixed_dynamic_array(fixed_dynamic_array&& other) noexcept : base_class_type(static_cast(other)) { } - WIDE_DECIMAL_CONSTEXPR - ~fixed_dynamic_array() override = default; - - constexpr auto operator=(const fixed_dynamic_array& other) -> fixed_dynamic_array& // NOLINT(cert-oop54-cpp) + auto operator=(const fixed_dynamic_array& other) -> fixed_dynamic_array& // NOLINT(cert-oop54-cpp) { if(this != &other) { @@ -414,17 +393,19 @@ return *this; } - constexpr auto operator=(fixed_dynamic_array&& other) noexcept -> fixed_dynamic_array& + auto operator=(fixed_dynamic_array&& other) noexcept -> fixed_dynamic_array& { base_class_type::operator=(static_cast(other)); return *this; } + + ~fixed_dynamic_array() override = default; }; template - class fixed_static_array final : public std::array(MySize)> // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) + class fixed_static_array final : public std::array(MySize)> { private: using base_class_type = std::array(MySize)>; @@ -437,13 +418,13 @@ constexpr fixed_static_array() = default; // LCOV_EXCL_LINE - explicit constexpr fixed_static_array(const size_type s, - const value_type& v = value_type()) + explicit fixed_static_array(const size_type s, + const value_type& v = value_type()) { if(s < static_size()) { - util::fill_unsafe(base_class_type::begin(), base_class_type::begin() + s, v); - util::fill_unsafe(base_class_type::begin() + s, base_class_type::end(), value_type()); + std::fill(base_class_type::begin(), base_class_type::begin() + s, v); + std::fill(base_class_type::begin() + s, base_class_type::end(), value_type()); } else { @@ -451,38 +432,40 @@ } } - constexpr fixed_static_array(const fixed_static_array&) = default; - constexpr fixed_static_array(fixed_static_array&&) noexcept = default; + fixed_static_array(const fixed_static_array&) = default; + fixed_static_array(fixed_static_array&&) noexcept = default; - constexpr explicit fixed_static_array(std::initializer_list lst) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + fixed_static_array(std::initializer_list lst) { const auto size_to_copy = - util::min_unsafe(static_cast(lst.size()), - static_cast(MySize)); + (std::min)(static_cast(lst.size()), + static_cast(MySize)); if(size_to_copy < static_cast(base_class_type::size())) { - util::copy_unsafe(lst.begin(), - lst.begin() + size_to_copy, - base_class_type::begin()); + std::copy(lst.begin(), + lst.begin() + size_to_copy, + base_class_type::begin()); - util::fill_unsafe(base_class_type::begin() + size_to_copy, - base_class_type::end(), - static_cast(UINT8_C(0))); + std::fill(base_class_type::begin() + size_to_copy, + base_class_type::end(), + static_cast(UINT8_C(0))); } else { - util::copy_unsafe(lst.begin(), - lst.begin() + size_to_copy, - base_class_type::begin()); + std::copy(lst.begin(), + lst.begin() + size_to_copy, + base_class_type::begin()); } } - constexpr auto operator=(const fixed_static_array& other_array) -> fixed_static_array& = default; - constexpr auto operator=(fixed_static_array&& other_array) noexcept -> fixed_static_array& = default; + ~fixed_static_array() = default; // LCOV_EXCL_LINE + + auto operator=(const fixed_static_array& other_array) -> fixed_static_array& = default; + auto operator=(fixed_static_array&& other_array) noexcept -> fixed_static_array& = default; - constexpr auto operator[](const size_type i) -> typename base_class_type::reference { return base_class_type::operator[](static_cast(i)); } - constexpr auto operator[](const size_type i) const -> typename base_class_type::const_reference { return base_class_type::operator[](static_cast(i)); } + auto operator[](const size_type i) -> typename base_class_type::reference { return base_class_type::operator[](static_cast(i)); } + auto operator[](const size_type i) const -> typename base_class_type::const_reference { return base_class_type::operator[](static_cast(i)); } }; enum class os_float_field_type @@ -514,7 +497,7 @@ ~unsigned_wrap() noexcept = default; // LCOV_EXCL_LINE - constexpr auto operator=(const unsigned_wrap& other) noexcept -> unsigned_wrap& + auto operator=(const unsigned_wrap& other) noexcept -> unsigned_wrap& { if(this != &other) { @@ -525,7 +508,7 @@ return *this; } - constexpr auto operator=(unsigned_wrap&& other) noexcept -> unsigned_wrap& + auto operator=(unsigned_wrap&& other) noexcept -> unsigned_wrap& { my_neg = other.my_neg; my_value = other.my_value; @@ -540,7 +523,7 @@ bool my_neg; // NOLINT(misc-non-private-member-variables-in-classes) unsigned_type my_value; // NOLINT(misc-non-private-member-variables-in-classes) - constexpr auto operator+=(const unsigned_wrap& other) noexcept -> unsigned_wrap& + auto operator+=(const unsigned_wrap& other) noexcept -> unsigned_wrap& { if(my_neg == other.my_neg) { @@ -585,7 +568,7 @@ return *this; } - constexpr auto operator-=(const unsigned_wrap& other) noexcept -> unsigned_wrap& + auto operator-=(const unsigned_wrap& other) noexcept -> unsigned_wrap& { if(my_value == static_cast(UINT8_C(0))) { @@ -607,8 +590,8 @@ } }; - template constexpr auto operator+(const unsigned_wrap& a, const unsigned_wrap& b) -> unsigned_wrap { return unsigned_wrap(a) += b; } - template constexpr auto operator-(const unsigned_wrap& a, const unsigned_wrap& b) -> unsigned_wrap { return unsigned_wrap(a) -= b; } + template inline auto operator+(const unsigned_wrap& a, const unsigned_wrap& b) -> unsigned_wrap { return unsigned_wrap(a) += b; } + template inline auto operator-(const unsigned_wrap& a, const unsigned_wrap& b) -> unsigned_wrap { return unsigned_wrap(a) -= b; } #if(__cplusplus >= 201703L) } // namespace math::wide_decimal::detail diff --git a/ref_app/src/math/wide_decimal/decwide_t_detail_fft.h b/ref_app/src/math/wide_decimal/decwide_t_detail_fft.h index bbb1e5e68..a34779622 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail_fft.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail_fft.h @@ -114,28 +114,28 @@ template - constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> std::enable_if_t + constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> typename std::enable_if::type { return template_sin_order_1(num_points); } template - 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(-template_sin_order_1(num_points)); } template - constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> std::enable_if_t + constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> typename std::enable_if::type { return template_sin_order_2(num_points); } template - 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(-template_sin_order_2(num_points)); } @@ -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; @@ -268,7 +268,7 @@ template - auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> std::enable_if_t + auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> typename std::enable_if::type { fft_lanczos_fft(num_points / 2U, data); @@ -312,7 +312,7 @@ template - 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(static_cast(1) + const_unique_wp_real(num_points)); auto imag_part = static_cast( const_unique_wp_imag(num_points)); 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 4273fe040..92f954057 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 @@ -34,7 +34,6 @@ template - WIDE_DECIMAL_CONSTEXPR auto compare_ranges( InputIteratorLeftType pa, InputIteratorRightType pb, const std::uint_fast32_t count) -> std::int_fast8_t @@ -69,7 +68,6 @@ template - WIDE_DECIMAL_CONSTEXPR auto eval_add_n( OutputLimbIteratorType r, InputLimbIteratorType u, InputLimbIteratorType v, @@ -109,7 +107,6 @@ template - WIDE_DECIMAL_CONSTEXPR auto eval_subtract_n( OutputLimbIteratorType r, InputLimbIteratorType u, // NOLINT(bugprone-easily-swappable-parameters) InputLimbIteratorType v, @@ -169,14 +166,13 @@ template - 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::value_type, std::uint8_t>::value, int>* p_nullparam = static_cast(nullptr) + const typename std::enable_if::value_type, std::uint8_t>::value>::type* p_nullparam = nullptr ) { static_cast(p_nullparam); @@ -199,7 +195,7 @@ count * static_cast(INT8_C(2)) ); - util::fill_unsafe(r, r + fill_dst, static_cast(UINT8_C(0))); + std::fill(r, r + fill_dst, static_cast(UINT8_C(0))); const auto count_minus_one = static_cast @@ -241,16 +237,14 @@ template - 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::value_type, std::uint16_t>::value - || std::is_same::value_type, std::uint32_t>::value), int>* p_nullparam = static_cast(nullptr) - ) + const typename std::enable_if<( std::is_same::value_type, std::uint16_t>::value + || std::is_same::value_type, std::uint32_t>::value)>::type* p_nullparam = nullptr) { static_cast(p_nullparam); @@ -323,7 +317,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto mul_loop_n( LimbIteratorType u, typename std::iterator_traits::value_type n, const std::int32_t p) -> typename std::iterator_traits::value_type @@ -361,7 +354,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto div_loop_n( LimbIteratorType u, typename std::iterator_traits::value_type n, const std::int32_t p) -> typename std::iterator_traits::value_type @@ -397,7 +389,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto eval_multiply_kara_propagate_carry( LimbIteratorType t, const std::uint_fast32_t n, const typename std::iterator_traits::value_type carry) -> void @@ -442,7 +433,6 @@ } template - WIDE_DECIMAL_CONSTEXPR auto eval_multiply_kara_propagate_borrow( LimbIteratorType t, const std::uint_fast32_t n, const bool has_borrow) -> void @@ -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(static_cast(n) * static_cast(UINT8_C(2))), t0); + std::copy(r0, r0 + static_cast(static_cast(n) * static_cast(UINT8_C(2))), t0); // Step 2 local_limb_type carry; @@ -713,8 +703,8 @@ static_cast(prec_elems_for_multiply) * static_cast(UINT8_C(2)) ); - util::fill_unsafe(af + fill_distance, af + n_fft, static_cast(0)); - util::fill_unsafe(bf + fill_distance, bf + n_fft, static_cast(0)); + std::fill(af + fill_distance, af + n_fft, static_cast(0)); + std::fill(bf + fill_distance, bf + n_fft, static_cast(0)); // Perform forward FFTs on the data arrays a and b. detail::fft::rfft_lanczos_rfft(n_fft, af); diff --git a/ref_app/src/mcal_lcd/mcal_lcd_base.h b/ref_app/src/mcal_lcd/mcal_lcd_base.h index 69207313b..1a11fd194 100644 --- a/ref_app/src/mcal_lcd/mcal_lcd_base.h +++ b/ref_app/src/mcal_lcd/mcal_lcd_base.h @@ -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 - #include + #include - 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(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 diff --git a/ref_app/src/mcal_lcd/mcal_lcd_console.h b/ref_app/src/mcal_lcd/mcal_lcd_console.h index 20cdaef1c..557ad861e 100644 --- a/ref_app/src/mcal_lcd/mcal_lcd_console.h +++ b/ref_app/src/mcal_lcd/mcal_lcd_console.h @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// 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 @@ -13,40 +13,51 @@ #include - 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(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 diff --git a/ref_app/src/mcal_lcd/mcal_lcd_generic_st7066.h b/ref_app/src/mcal_lcd/mcal_lcd_generic_st7066.h index 617929e81..5380a834d 100644 --- a/ref_app/src/mcal_lcd/mcal_lcd_generic_st7066.h +++ b/ref_app/src/mcal_lcd/mcal_lcd_generic_st7066.h @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// 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_GENERIC_ST7066_2020_05_07_H +#ifndef MCAL_LCD_GENERIC_ST7066_2020_05_07_H // NOLINT(llvm-header-guard) #define MCAL_LCD_GENERIC_ST7066_2020_05_07_H #include @@ -15,7 +15,13 @@ #include #include - namespace mcal { namespace lcd { + #include + + #if(__cplusplus >= 201703L) + namespace mcal::lcd { + #else + namespace mcal { namespace lcd { // NOLINT(modernize-concat-nested-namespaces) + #endif template(UINT8_C(16))> + const std::uint_fast8_t lcd_line_width = 16U> class lcd_generic_st7066 final : public mcal::lcd::lcd_base { + private: + using timer_type = util::timer; + + static void blocking_delay(const typename timer_type::tick_type blocking_delay_value) + { + timer_type::blocking_delay(blocking_delay_value); + } + public: lcd_generic_st7066() = default; - ~lcd_generic_st7066() override = default; + virtual ~lcd_generic_st7066() = default; - auto init(void) noexcept -> bool override + virtual bool init(void) { port_pin_rs__type::set_pin_low(); port_pin_rw__type::set_pin_low(); port_pin_e___type::set_pin_high(); - P1_set(static_cast(UINT8_C(0))); + P1_set(UINT8_C(0)); port_pin_rs__type::set_direction_output(); port_pin_rw__type::set_direction_output(); @@ -52,62 +66,52 @@ port_pin_e___type::set_pin_low(); - blocking_delay(timer_type::milliseconds(static_cast(UINT8_C(15)))); // Set a timer which is at least 15ms from system start. - command(static_cast(UINT8_C(0x30))); // Command 0x30 = Wake up - blocking_delay(timer_type::milliseconds(static_cast(UINT8_C(7))))); // Must wait 5ms, busy flag not available. - command(static_cast(UINT8_C(0x30))); // Command 0x30 = Wake up 2 - blocking_delay(timer_type::microseconds(static_cast(UINT8_C(200)))); // Must wait 160us, busy flag not available - command(static_cast(UINT8_C(0x30))); // Command 0x30 = Wake up 3 - blocking_delay(timer_type::microseconds(static_cast(UINT8_C(200)))); // Must wait 160us, busy flag not available - command(static_cast(UINT8_C(0x38))); // Function set: 8-bit/2-line - command(static_cast(UINT8_C(0x10))); // Set cursor - command(static_cast(UINT8_C(0x0C))); // Display ON; Cursor ON - command(static_cast(UINT8_C(0x06))); // Entry mode set - - const auto write_clear_lines_is_ok = - ( write(nullptr, static_cast(UINT8_C(0)), static_cast(UINT8_C(0))) - && write(nullptr, static_cast(UINT8_C(0)), static_cast(UINT8_C(1)))); + blocking_delay(timer_type::milliseconds(15U)); // Set a timer which is at least 15ms from system start. + command(UINT8_C(0x30)); // Command 0x30 = Wake up + blocking_delay(timer_type::milliseconds(7U)); // Must wait 5ms, busy flag not available. + command(UINT8_C(0x30)); // Command 0x30 = Wake up 2 + blocking_delay(timer_type::microseconds(200U)); // Must wait 160us, busy flag not available + command(UINT8_C(0x30)); // Command 0x30 = Wake up 3 + blocking_delay(timer_type::microseconds(200U)); // Must wait 160us, busy flag not available + command(UINT8_C(0x38)); // Function set: 8-bit/2-line + command(UINT8_C(0x10)); // Set cursor + command(UINT8_C(0x0C)); // Display ON; Cursor ON + command(UINT8_C(0x06)); // Entry mode set + + const auto write_clear_lines_is_ok = ( write_n(nullptr, 0U, 0U) + && write_n(nullptr, 0U, 1U)); + return write_clear_lines_is_ok; } - auto write(const char* pstr, const std::uint_fast8_t length, const std::uint_fast8_t line_index) noexcept -> bool override + virtual bool write_n(const char* pstr, + std::uint_fast8_t length, + std::uint_fast8_t line_index) { - auto char_index = static_cast(UINT8_C(0)); - - const auto command_byte = - static_cast - ( - static_cast(UINT8_C(0x80)) - + static_cast - ( - (line_index == static_cast(UINT8_C(0))) - ? static_cast(UINT8_C(0x00)) - : static_cast(UINT8_C(0x40)) - ) - ); - - command(command_byte); + std::uint_fast8_t char_index = 0U; + + command(std::uint8_t(0x80U + ((line_index == 0U) ? 0x00U : 0x40U))); if(pstr != nullptr) { // Write the line at line_index. for( ; char_index < (std::min)(lcd_line_width, length); ++char_index) { - write_i(static_cast(pstr[char_index])); + write(std::uint8_t(pstr[char_index])); } } for( ; char_index < lcd_line_width; ++char_index) { - write_i(static_cast(' ')); + write(std::uint8_t(char(' '))); } return true; } private: - auto write_i(const std::uint8_t i) noexcept -> void + void write(const std::uint8_t i) { P1_set(i); // P1 = i; // Put data on the output Port port_pin_rs__type::set_pin_high(); // D_I =1; // D/I=HIGH : send data @@ -117,7 +121,7 @@ port_pin_e___type::set_pin_low(); // E = 0; // Clock enable: falling edge } - auto command(const std::uint8_t i) noexcept -> void + void command(std::uint8_t i) { P1_set(i); // P1 = i; // Put data on output Port port_pin_rs__type::set_pin_low(); // D_I =0; // D/I=LOW : send instruction @@ -128,7 +132,7 @@ blocking_delay(timer_type::microseconds(40U)); // Command execution delay } - auto P1_set(const std::uint8_t c) noexcept -> void + void P1_set(const std::uint8_t c) { std::uint_fast8_t(c & UINT8_C(0x01)) != UINT8_C(0) ? port_pin_db0_type::set_pin_high() : port_pin_db0_type::set_pin_low(); std::uint_fast8_t(c & UINT8_C(0x02)) != UINT8_C(0) ? port_pin_db1_type::set_pin_high() : port_pin_db1_type::set_pin_low(); @@ -140,7 +144,7 @@ std::uint_fast8_t(c & UINT8_C(0x80)) != UINT8_C(0) ? port_pin_db7_type::set_pin_high() : port_pin_db7_type::set_pin_low(); } - static auto P1_set_direction_output() noexcept -> void + static void P1_set_direction_output() { port_pin_db0_type::set_direction_output(); port_pin_db1_type::set_direction_output(); @@ -153,6 +157,11 @@ } }; - } } // namespace mcal::lcd + #if(__cplusplus >= 201703L) + } // namespace mcal::lcd + #else + } // namespace lcd + } // namespace mcal + #endif #endif // MCAL_LCD_GENERIC_ST7066_2020_05_07_H diff --git a/ref_app/src/util/memory/util_n_slot_array_allocator.h b/ref_app/src/util/memory/util_n_slot_array_allocator.h index 3baa60eac..57f562f0f 100644 --- a/ref_app/src/util/memory/util_n_slot_array_allocator.h +++ b/ref_app/src/util/memory/util_n_slot_array_allocator.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 - 2022. +// Copyright Christopher Kormanyos 2020 - 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) @@ -31,10 +31,10 @@ using pointer = value_type*; using const_pointer = const value_type*; - template + template struct rebind { - using other = n_slot_array_allocator; + using other = n_slot_array_allocator; }; }; @@ -47,7 +47,9 @@ static constexpr std::uint_fast32_t slot_width = SlotWidth; static constexpr std::size_t slot_count = SlotCount; - using slot_array_type = std::array; + using slot_array_type = std::array; + using slot_array_memory_type = std::array; + using slot_array_flags_type = std::array; public: using size_type = std::size_t; @@ -61,10 +63,10 @@ constexpr n_slot_array_allocator(const n_slot_array_allocator&) = default; // LCOV_EXCL_LINE - template + template struct rebind { - using other = n_slot_array_allocator; + using other = n_slot_array_allocator; }; constexpr auto max_size() const noexcept -> size_type { return slot_count; } @@ -118,45 +120,42 @@ *p = x; } - // LCOV_EXCL_START - auto destroy(pointer p) -> void - { - static_cast(p); - } - // LCOV_EXCL_STOP + auto destroy(pointer p) const -> void { static_cast(p); } // LCOV_EXCL_LINE auto deallocate(pointer p_slot, size_type sz) -> void { static_cast(sz); - for(std::size_t i = 0U; i < slot_count; ++i) + auto index = static_cast(UINT8_C(0)); + + for(auto& slot_array_memory_entry : slot_array_memory) { - if(p_slot == static_cast(slot_array_memory[i].data())) // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index) + if(p_slot == static_cast(slot_array_memory_entry.data())) { - slot_flags[i] = 0U; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index) + slot_flags[index] = static_cast(UINT8_C(0)); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index) break; } + + ++index; } } private: - static std::array slot_array_memory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) - static std::array slot_flags; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) - static std::size_t slot_max_index; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static slot_array_memory_type slot_array_memory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static slot_array_flags_type slot_flags; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static std::size_t slot_max_index; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) }; template - std::array::slot_array_type, n_slot_array_allocator::slot_count> // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) - n_slot_array_allocator::slot_array_memory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) + typename n_slot_array_allocator::slot_array_memory_type n_slot_array_allocator::slot_array_memory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) template - std::array::slot_count> // NOLINT(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) - n_slot_array_allocator::slot_flags; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) + typename n_slot_array_allocator::slot_array_flags_type n_slot_array_allocator::slot_flags; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) template; // Constructors. - explicit dynamic_array( size_type count = static_cast(UINT8_C(0)), - const_reference v = value_type(), - const allocator_type& a = allocator_type()) - : elem_count(count), - elems (nullptr) + explicit constexpr dynamic_array( size_type count = static_cast(UINT8_C(0)), + const_reference v = value_type(), + const allocator_type& a = allocator_type()) + : elem_count(count) { if(elem_count > static_cast(UINT8_C(0))) { @@ -69,9 +68,8 @@ } } - dynamic_array(const dynamic_array& other) - : elem_count(other.size()), - elems (nullptr) + constexpr dynamic_array(const dynamic_array& other) + : elem_count(other.size()) { allocator_type my_a; @@ -84,11 +82,10 @@ } template - dynamic_array(input_iterator first, - input_iterator last, - const allocator_type& a = allocator_type()) - : elem_count(static_cast(std::distance(first, last))), - elems (nullptr) + constexpr dynamic_array(input_iterator first, + input_iterator last, + const allocator_type& a = allocator_type()) + : elem_count(static_cast(std::distance(first, last))) { allocator_type my_a(a); @@ -100,10 +97,9 @@ std::copy(first, last, elems); } - dynamic_array(std::initializer_list lst, - const allocator_type& a = allocator_type()) - : elem_count(lst.size()), - elems (nullptr) + constexpr dynamic_array(std::initializer_list lst, + const allocator_type& a = allocator_type()) + : elem_count(lst.size()) { allocator_type my_a(a); @@ -116,35 +112,26 @@ } // Move constructor. - dynamic_array(dynamic_array&& other) noexcept : elem_count(other.elem_count), - elems (other.elems) + constexpr dynamic_array(dynamic_array&& other) noexcept : elem_count(other.elem_count), + elems (other.elems) { other.elem_count = static_cast(UINT8_C(0)); other.elems = nullptr; } // Destructor. - virtual ~dynamic_array() + virtual ~dynamic_array() // LCOV_EXCL_LINE { - pointer p = elems; // NOLINT(altera-id-dependent-backward-branch) - using local_allocator_traits_type = std::allocator_traits; allocator_type my_a; - while(p != elems + elem_count) // NOLINT(altera-id-dependent-backward-branch) - { - local_allocator_traits_type::destroy(my_a, p); - - ++p; - } - // Destroy the elements and deallocate the range. local_allocator_traits_type::deallocate(my_a, elems, elem_count); } // Assignment operator. - auto operator=(const dynamic_array& other) -> dynamic_array& + constexpr auto operator=(const dynamic_array& other) -> dynamic_array& { if(this != &other) { @@ -157,7 +144,7 @@ } // Move assignment operator. - auto operator=(dynamic_array&& other) noexcept -> dynamic_array& + constexpr auto operator=(dynamic_array&& other) noexcept -> dynamic_array& { std::swap(elem_count, other.elem_count); std::swap(elems, other.elems); @@ -166,22 +153,22 @@ } // Iterator members: - auto begin () noexcept -> iterator { return elems; } - auto end () noexcept -> iterator { return elems + elem_count; } - auto begin () const noexcept -> const_iterator { return elems; } - auto end () const noexcept -> const_iterator { return elems + elem_count; } - auto cbegin () const noexcept -> const_iterator { return elems; } - auto cend () const noexcept -> const_iterator { return elems + elem_count; } - auto rbegin () noexcept -> reverse_iterator { return reverse_iterator(elems + elem_count); } - auto rend () noexcept -> reverse_iterator { return reverse_iterator(elems); } - auto rbegin () const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } - auto rend () const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems); } - auto crbegin() const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } - auto crend () const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems); } + constexpr auto begin () noexcept -> iterator { return elems; } + constexpr auto end () noexcept -> iterator { return elems + elem_count; } + constexpr auto begin () const noexcept -> const_iterator { return elems; } + constexpr auto end () const noexcept -> const_iterator { return elems + elem_count; } + constexpr auto cbegin () const noexcept -> const_iterator { return elems; } + constexpr auto cend () const noexcept -> const_iterator { return elems + elem_count; } + constexpr auto rbegin () noexcept -> reverse_iterator { return reverse_iterator(elems + elem_count); } + constexpr auto rend () noexcept -> reverse_iterator { return reverse_iterator(elems); } + constexpr auto rbegin () const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } + constexpr auto rend () const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems); } + constexpr auto crbegin() const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } + constexpr auto crend () const noexcept -> const_reverse_iterator { return const_reverse_iterator(elems); } // Raw pointer access. - auto data() noexcept -> pointer { return elems; } - auto data() const noexcept -> const_pointer { return elems; } + constexpr auto data() noexcept -> pointer { return elems; } + constexpr auto data() const noexcept -> const_pointer { return elems; } // Size and capacity. constexpr auto size () const noexcept -> size_type { return elem_count; } @@ -189,25 +176,25 @@ constexpr auto empty () const noexcept -> bool { return (elem_count == static_cast(UINT8_C(0))); } // Element access members. - auto operator[](const size_type i) noexcept -> reference { return elems[i]; } - auto operator[](const size_type i) const noexcept -> const_reference { return elems[i]; } + constexpr auto operator[](const size_type i) noexcept -> reference { return elems[i]; } + constexpr auto operator[](const size_type i) const noexcept -> const_reference { return elems[i]; } - auto front() noexcept -> reference { return elems[static_cast(UINT8_C(0))]; } - auto front() const noexcept -> const_reference { return elems[static_cast(UINT8_C(0))]; } + constexpr auto front() noexcept -> reference { return elems[static_cast(UINT8_C(0))]; } + constexpr auto front() const noexcept -> const_reference { return elems[static_cast(UINT8_C(0))]; } - auto back() noexcept -> reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } - auto back() const noexcept -> const_reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } + constexpr auto back() noexcept -> reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } + constexpr auto back() const noexcept -> const_reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } - auto at(const size_type i) noexcept -> reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } - auto at(const size_type i) const noexcept -> const_reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } + constexpr auto at(const size_type i) noexcept -> reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } + constexpr auto at(const size_type i) const noexcept -> const_reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } // Element manipulation members. - auto fill(const value_type& v) -> void + constexpr auto fill(const value_type& v) -> void { - std::fill_n(begin(), elem_count, v); + std::fill(begin(), begin() + elem_count, v); } - auto swap(dynamic_array& other) noexcept -> void + constexpr auto swap(dynamic_array& other) noexcept -> void { if(this != &other) { @@ -216,17 +203,15 @@ } } - auto swap(dynamic_array&& other) noexcept -> void + constexpr auto swap(dynamic_array&& other) noexcept -> void { - auto tmp = std::move(*this); - - *this = std::move(other); - other = std::move(tmp); + elems = std::move(other.elems); + elem_count = std::move(other.elem_count); } private: - mutable size_type elem_count; // NOLINT(readability-identifier-naming) - pointer elems; // NOLINT(readability-identifier-naming,altera-id-dependent-backward-branch) + size_type elem_count; // NOLINT(readability-identifier-naming) + pointer elems { nullptr }; // NOLINT(readability-identifier-naming,altera-id-dependent-backward-branch) }; template diff --git a/ref_app/src/util/utility/util_noncopyable.h b/ref_app/src/util/utility/util_noncopyable.h index aa8ee027d..f94f82697 100644 --- a/ref_app/src/util/utility/util_noncopyable.h +++ b/ref_app/src/util/utility/util_noncopyable.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2022. +// Copyright Christopher Kormanyos 2007 - 2023. // 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)