From 1933f1f87c8034b74ce5ec093e61da35a2e4abb0 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Sat, 18 Nov 2023 11:38:40 +0100 Subject: [PATCH 1/3] Update STL and wide-math --- .../app_benchmark_cnl_scaled_integer.cpp | 1 - ref_app/src/math/softfloat/soft_double.h | 2 +- ref_app/src/math/wide_decimal/decwide_t.h | 446 +++++++++--------- .../src/math/wide_decimal/decwide_t_detail.h | 20 +- .../wide_decimal/decwide_t_detail_namespace.h | 2 +- ref_app/src/math/wide_integer/uintwide_t.h | 79 ++-- ref_app/src/util/STL/cmath | 29 ++ ref_app/src/util/STL/functional | 10 + ref_app/src/util/STL/tuple | 410 ++++++++-------- ref_app/src/util/STL/type_traits | 31 +- 10 files changed, 566 insertions(+), 464 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_cnl_scaled_integer.cpp b/ref_app/src/app/benchmark/app_benchmark_cnl_scaled_integer.cpp index 84ff1999a..c451b65bb 100644 --- a/ref_app/src/app/benchmark/app_benchmark_cnl_scaled_integer.cpp +++ b/ref_app/src/app/benchmark/app_benchmark_cnl_scaled_integer.cpp @@ -98,7 +98,6 @@ fixed_point_dec_type c_dec(fixed_point_dec_type(56) / 10); fixed_point_dec_type x_dec(fixed_point_dec_type( 1) / 2); fixed_point_dec_type r_dec(fixed_point_dec_type(76) / 10); - #if defined(APP_BENCHMARK_STANDALONE_MAIN) constexpr auto app_benchmark_standalone_foodcafe = static_cast(UINT32_C(0xF00DCAFE)); diff --git a/ref_app/src/math/softfloat/soft_double.h b/ref_app/src/math/softfloat/soft_double.h index 493c91414..83dfb80ac 100644 --- a/ref_app/src/math/softfloat/soft_double.h +++ b/ref_app/src/math/softfloat/soft_double.h @@ -2102,7 +2102,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. { auto result = soft_double { }; - if (n < static_cast(INT8_C(0))) { result = soft_double::my_value_one() / pow(x, static_cast::type>(-n)); } + if (n < static_cast(INT8_C(0))) { result = soft_double::my_value_one() / pow(x, static_cast>(-n)); } else if(n == static_cast(INT8_C(0))) { result = soft_double::my_value_one(); } else if(n == static_cast(INT8_C(1))) { result = x; } else if(n == static_cast(INT8_C(2))) { result = x * x; } diff --git a/ref_app/src/math/wide_decimal/decwide_t.h b/ref_app/src/math/wide_decimal/decwide_t.h index 405ab7a52..da4e1a625 100644 --- a/ref_app/src/math/wide_decimal/decwide_t.h +++ b/ref_app/src/math/wide_decimal/decwide_t.h @@ -593,7 +593,7 @@ using signed_limb_type = typename std::make_signed::type; - using unsigned_exponent_type = typename std::make_unsigned::type; + using unsigned_exponent_type = std::make_unsigned_t; // TBD: Consider supporting more floating-point classes. // In particular, support for NaN is already being @@ -2450,7 +2450,7 @@ (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::type; + using local_unsigned_exponent_type = std::make_unsigned_t; constexpr auto ldbl_max_width_for_exp = static_cast(std::numeric_limits::digits10); @@ -3149,7 +3149,7 @@ { // Use Karatsuba multiplication. - // Sloanes's A029750: Numbers of the form 2^k times 1, 3, 5 or 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::a029750_as_runtime_value(static_cast(prec_elems_for_multiply)); @@ -3645,7 +3645,11 @@ ); // Bring one single digit into the mantissa and adjust exponent accordingly. - str.erase(str.cbegin(), it_non_zero); + str.erase + ( + static_cast(UINT8_C(0U)), + static_cast(std::distance(str.cbegin(), it_non_zero)) + ); str.insert(static_cast(UINT8_C(1)), static_cast(UINT8_C(1)), '.'); @@ -4698,28 +4702,28 @@ pfn_callback_to_report_digits10(static_cast(UINT8_C(0))); // LCOV_EXCL_LINE } - using floating_point_type = + using local_wide_decimal_type = decwide_t; - floating_point_type val_pi; + local_wide_decimal_type val_pi; - floating_point_type a(static_cast(UINT8_C(1))); + local_wide_decimal_type a(static_cast(UINT8_C(1))); // Initialize bB to 0.5. - floating_point_type bB(half()); // NOLINT(readability-identifier-naming) + local_wide_decimal_type bB(half()); // NOLINT(readability-identifier-naming) // Initialize t to 0.375. - floating_point_type + local_wide_decimal_type t ( - static_cast + static_cast ( static_cast(UINT8_C(3)) ) / static_cast(UINT8_C(8)) ); - floating_point_type s(bB); + local_wide_decimal_type s(bB); // This loop is designed for a maximum of several million // decimal digits of pi. The index k should reach no higher @@ -4729,8 +4733,8 @@ const auto digits10_iteration_goal = static_cast ( - static_cast(std::numeric_limits::digits10 / 2) - + (std::max)(static_cast(floating_point_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(std::numeric_limits::digits10 / 2) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(UINT8_C(9))) ); @@ -4746,7 +4750,7 @@ ( static_cast ( - 1000.0F * log(static_cast(std::numeric_limits::radix)) + 1000.0F * log(static_cast(std::numeric_limits::radix)) ) / log(10.0F) ) @@ -4767,7 +4771,7 @@ bB -= t; bB *= static_cast(UINT8_C(2)); - floating_point_type iterate_term(bB); + local_wide_decimal_type iterate_term(bB); iterate_term -= val_pi; iterate_term *= static_cast(1ULL << (k + static_cast(UINT8_C(1)))); // NOLINT(google-runtime-int) @@ -4817,7 +4821,7 @@ if(pfn_callback_to_report_digits10 != nullptr) { - pfn_callback_to_report_digits10(static_cast(std::numeric_limits::digits10)); // LCOV_EXCL_LINE + pfn_callback_to_report_digits10(static_cast(std::numeric_limits::digits10)); // LCOV_EXCL_LINE } return val_pi; @@ -4840,13 +4844,13 @@ static_cast(pfn_callback_to_report_digits10); - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT8_C( 3)), @@ -4877,13 +4881,13 @@ static_cast(pfn_callback_to_report_digits10); - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT16_C( 3)), @@ -4914,13 +4918,13 @@ static_cast(pfn_callback_to_report_digits10); - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT32_C( 3)), @@ -4937,19 +4941,19 @@ template auto calc_ln_two() -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type { - using floating_point_type = decwide_t; + using local_wide_decimal_type = decwide_t; // Use an AGM method to compute log(2). // Set a0 = 1 // Set b0 = 1 / (2^(m-2)) - floating_point_type ak(static_cast(UINT8_C(1))); + local_wide_decimal_type ak(static_cast(UINT8_C(1))); constexpr auto n_times_factor = static_cast ( - static_cast(std::numeric_limits::digits10) * 1.67F + static_cast(std::numeric_limits::digits10) * 1.67F ); // Ensure that the resulting power is non-negative. @@ -4961,14 +4965,14 @@ static_cast(3) ); - floating_point_type bk = + local_wide_decimal_type bk = ldexp(one(), static_cast(2 - m)); const auto digits10_iteration_goal = static_cast ( - static_cast(std::numeric_limits::digits10 / 2) - + (std::max)(static_cast(floating_point_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(std::numeric_limits::digits10 / 2) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(UINT8_C(9))) ); @@ -4984,7 +4988,7 @@ ( static_cast ( - 1000.0F * log(static_cast(std::numeric_limits::radix)) + 1000.0F * log(static_cast(std::numeric_limits::radix)) ) / log(10.0F) ) @@ -5012,7 +5016,7 @@ / static_cast(UINT16_C(1000)) ); - const auto ak_tmp = floating_point_type { ak }; + const auto ak_tmp = local_wide_decimal_type { ak }; ak += bk; @@ -5046,13 +5050,13 @@ // N[Log[2], 121] // 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857337 - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT8_C(69)), static_cast(UINT8_C(31)), static_cast(UINT8_C(47)), static_cast(UINT8_C(18)), @@ -5063,7 +5067,7 @@ static_cast(UINT8_C(96)), static_cast(UINT8_C(96)), static_cast(UINT8_C(94)), static_cast(UINT8_C(71)), static_cast(UINT8_C(56)), static_cast(UINT8_C( 5)), static_cast(UINT8_C(86)), static_cast(UINT8_C(33)), static_cast(UINT8_C(26)), static_cast(UINT8_C(99)), static_cast(UINT8_C(64)), static_cast(UINT8_C(18)), static_cast(UINT8_C(68)), static_cast(UINT8_C(75)), static_cast(UINT8_C(42)), static_cast(UINT8_C( 0)), }, - static_cast(INT8_C(-2)) + static_cast(INT8_C(-2)) ); } @@ -5073,13 +5077,13 @@ // N[Log[2], 121] // 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857337 - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT16_C(6931)), static_cast(UINT16_C(4718)), @@ -5090,7 +5094,7 @@ static_cast(UINT16_C(9696)), static_cast(UINT16_C(9471)), static_cast(UINT16_C(5605)), static_cast(UINT16_C(8633)), static_cast(UINT16_C(2699)), static_cast(UINT16_C(6418)), static_cast(UINT16_C(6875)), static_cast(UINT16_C(4200)), }, - static_cast(INT8_C(-4)) + static_cast(INT8_C(-4)) ); } @@ -5100,13 +5104,13 @@ // N[Log[2], 121] // 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857337 - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT32_C(69314718)), @@ -5117,7 +5121,7 @@ static_cast(UINT32_C(96969471)), static_cast(UINT32_C(56058633)), static_cast(UINT32_C(26996418)), static_cast(UINT32_C(68754200)), }, - static_cast(INT8_C(-8)) + static_cast(INT8_C(-8)) ); } @@ -5127,13 +5131,13 @@ // N[Log[10], 121] // 2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286248633 - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT8_C( 2)), @@ -5153,13 +5157,13 @@ // N[Log[10], 121] // 2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286248633 - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT16_C( 2)), @@ -5179,13 +5183,13 @@ // N[Log[10], 121] // 2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286248633 - using floating_point_type = + using local_wide_decimal_type = decwide_t; - using local_limb_type = typename floating_point_type::limb_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; return - floating_point_type::from_lst + local_wide_decimal_type::from_lst ( { static_cast(UINT32_C( 2)), @@ -5240,14 +5244,14 @@ #endif // Global unary operators of decwide_t reference. - template auto operator+(const decwide_t& self) -> decwide_t { return decwide_t(self); } - template auto operator-(const decwide_t& self) -> decwide_t { decwide_t tmp(self); return tmp.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&. - templateauto operator+(const decwide_t& u, const decwide_t& v) -> decwide_t { return decwide_t(u) += v; } - templateauto operator-(const decwide_t& u, const decwide_t& v) -> decwide_t { return decwide_t(u) -= v; } - templateauto operator*(const decwide_t& u, const decwide_t& v) -> decwide_t { return decwide_t(u) *= v; } - templateauto operator/(const decwide_t& u, const decwide_t& v) -> decwide_t { return decwide_t(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 @@ -5256,7 +5260,9 @@ && (!std::is_unsigned::value), decwide_t>::type { - return decwide_t(u).add_signed_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).add_signed_long_long(n); } template @@ -5265,7 +5271,9 @@ && std::is_unsigned::value, decwide_t>::type { - return decwide_t(u).add_unsigned_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).add_unsigned_long_long(n); } template @@ -5273,7 +5281,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(u) += decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u) += decwide_t(f); } template @@ -5282,7 +5292,9 @@ && (!std::is_unsigned::value), decwide_t>::type { - return decwide_t(u).sub_signed_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).sub_signed_long_long(n); } template @@ -5291,7 +5303,9 @@ && std::is_unsigned::value, decwide_t>::type { - return decwide_t(u).sub_unsigned_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).sub_unsigned_long_long(n); } // LCOV_EXCL_START @@ -5300,7 +5314,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(u) -= decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u) -= decwide_t(f); } // LCOV_EXCL_STOP @@ -5310,7 +5326,9 @@ && (!std::is_unsigned::value), decwide_t>::type { - return decwide_t(u).mul_signed_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).mul_signed_long_long(n); } template @@ -5319,7 +5337,9 @@ && std::is_unsigned::value, decwide_t>::type { - return decwide_t(u).mul_unsigned_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).mul_unsigned_long_long(n); } template @@ -5327,7 +5347,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(u) *= decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u) *= decwide_t(f); } template @@ -5336,7 +5358,9 @@ && (!std::is_unsigned::value), decwide_t>::type { - return decwide_t(u).div_signed_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).div_signed_long_long(n); } template @@ -5345,7 +5369,9 @@ && std::is_unsigned::value, decwide_t>::type { - return decwide_t(u).div_unsigned_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).div_unsigned_long_long(n); } template @@ -5353,7 +5379,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(u) /= decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u) /= decwide_t(f); } // Global add/sub/mul/div of all built-in types with const decwide_t&. @@ -5363,7 +5391,9 @@ && (!std::is_unsigned::value), decwide_t>::type { - return decwide_t(u).add_signed_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).add_signed_long_long(n); } template @@ -5372,7 +5402,9 @@ && std::is_unsigned::value, decwide_t>::type { - return decwide_t(u).add_unsigned_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).add_unsigned_long_long(n); } template @@ -5380,7 +5412,9 @@ const decwide_t& u) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(f) += u; + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(f) += u; } template @@ -5388,7 +5422,9 @@ const decwide_t& u) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(n) -= u; + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(n) -= u; } template @@ -5397,7 +5433,9 @@ && (!std::is_unsigned::value), decwide_t>::type { - return decwide_t(u).mul_signed_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).mul_signed_long_long(n); } template @@ -5406,7 +5444,9 @@ && std::is_unsigned::value, decwide_t>::type { - return decwide_t(u).mul_unsigned_long_long(n); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(u).mul_unsigned_long_long(n); } template @@ -5414,7 +5454,9 @@ const decwide_t& u) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(f) *= u; + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(f) *= u; } template @@ -5422,7 +5464,9 @@ const decwide_t& u) -> typename std::enable_if::value, decwide_t>::type { - return decwide_t(n) /= u; + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(n) /= u; } // Global self add/sub/mul/div of decwide_t& with all built-in types. @@ -5450,7 +5494,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return u += decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return u += local_wide_decimal_type(f); } template @@ -5476,7 +5522,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return u -= decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return u -= local_wide_decimal_type(f); } template @@ -5502,7 +5550,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return u *= decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return u *= local_wide_decimal_type(f); } // LCOV_EXCL_STOP @@ -5529,7 +5579,9 @@ FloatingPointType f) -> typename std::enable_if::value, decwide_t>::type { - return u /= decwide_t(f); + using local_wide_decimal_type = decwide_t; + + return u /= local_wide_decimal_type(f); } // Global comparison operators of const decwide_t& with const decwide_t&. @@ -5678,56 +5730,48 @@ auto pow(const decwide_t& x, const decwide_t& a) -> decwide_t { - decwide_t pow_result; - - if(a.iszero()) - { - pow_result = one(); - } - else - { - pow_result = exp(a * log(x)); - } - - return pow_result; + return + (a.iszero()) ? one() + : exp(a * log(x)); } template auto ldexp(const decwide_t& v, int e) -> decwide_t { - decwide_t ldexp_result(v); - - if((e > static_cast(INT8_C(0))) && (e < static_cast(INT8_C(64)))) // NOLINT(,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + if(e == static_cast(INT8_C(0))) { - ldexp_result *= static_cast(1ULL << static_cast(e)); + return v; } - else if((e > static_cast(INT8_C(-64))) && (e < static_cast(INT8_C(0)))) // NOLINT(,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + else // NOLINT(llvm-else-after-return,readability-else-after-return) { - ldexp_result /= static_cast(1ULL << static_cast(-e)); - } - else if(e != static_cast(INT8_C(0))) - { - ldexp_result *= pow(two(), e); - } + using local_wide_decimal_type = decwide_t; - return ldexp_result; + local_wide_decimal_type result(v); + + return + (e <= static_cast(INT8_C(-64))) + ? result /= pow(two(), -e) + : (e >= static_cast(INT8_C(64))) + ? result *= pow(two(), e) + : (e < static_cast(INT8_C(0))) ? result /= static_cast(1ULL << static_cast(-e)) + : result *= static_cast(1ULL << static_cast(e)); + } } template auto frexp(const decwide_t& v, int* expon) -> decwide_t { - using local_wide_decimal_type = - decwide_t; + using local_wide_decimal_type = decwide_t; using local_exponent_type = typename local_wide_decimal_type::exponent_type; local_wide_decimal_type result; - local_exponent_type e; + local_exponent_type my_e; - local_wide_decimal_type::calculate_frexp(result, v, &e); + local_wide_decimal_type::calculate_frexp(result, v, &my_e); - *expon = static_cast(e); + *expon = static_cast(my_e); return result; } @@ -5736,19 +5780,19 @@ auto fmod(const decwide_t& v1, const decwide_t& v2) -> decwide_t { - const decwide_t n = ((v1 < 0) ? ceil(v1 / v2) : floor(v1 / v2)); + using local_wide_decimal_type = decwide_t; + + const local_wide_decimal_type nv = (v1.isneg() ? ceil(v1 / v2) : floor(v1 / v2)); - return v1 - (n * v2); + return v1 - (nv * v2); } template auto sqrt(const decwide_t& x) -> decwide_t { - return - decwide_t - ( - x - ).calculate_sqrt(); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(x).calculate_sqrt(); } template @@ -5760,7 +5804,9 @@ template auto rootn(const decwide_t& x, std::int32_t p) -> decwide_t // NOLINT(misc-no-recursion) { - decwide_t rtn; + using local_wide_decimal_type = decwide_t; + + local_wide_decimal_type rtn; if(p < static_cast(INT8_C(0))) { @@ -5777,27 +5823,19 @@ } else if(p == static_cast(INT8_C(2))) { - using std::sqrt; - rtn = sqrt(x); } else if(p == static_cast(INT8_C(3))) { const auto b_neg = (x < 0); - using std::fabs; - - rtn = fabs(x).calculate_rootn_inv(3).calculate_inv(); + rtn = (fabs(x).calculate_rootn_inv(3)).calculate_inv(); if(b_neg) { static_cast(rtn.negate()); } } else { - rtn = - decwide_t - ( - x - ).calculate_rootn_inv(p).calculate_inv(); + rtn = (local_wide_decimal_type(x).calculate_rootn_inv(p)).calculate_inv(); } return rtn; @@ -5807,31 +5845,25 @@ auto rootn_inv(const decwide_t& x, std::int32_t p) -> decwide_t { - return - decwide_t - ( - x - ).calculate_rootn_inv(p); + using local_wide_decimal_type = decwide_t; + + return local_wide_decimal_type(x).calculate_rootn_inv(p); } template auto log(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT8_C(51))), decwide_t>::type // NOLINT(misc-no-recursion) { - using floating_point_type = decwide_t; + using local_wide_decimal_type = decwide_t; - floating_point_type result { }; + local_wide_decimal_type result { }; if(x < one()) { - floating_point_type xx(x); - - static_cast(xx.calculate_inv()); - - result = -log(xx); + result = -log(local_wide_decimal_type(x).calculate_inv()); } else if(x > one()) { - const auto precision_of_x = floating_point_type::get_precision(x); + const auto precision_of_x = local_wide_decimal_type::get_precision(x); // Use an AGM method to compute the logarithm of x. // Set a0 = 1 @@ -5843,7 +5875,7 @@ const auto n_times_factor = static_cast ( - static_cast(static_cast(std::numeric_limits::digits10)) * 1.67F + static_cast(static_cast(std::numeric_limits::digits10)) * 1.67F ); // Extract lg_xx = Log[mantissa * radix^ib] @@ -5851,19 +5883,16 @@ // where the logarithm of the mantissa is simply neglected // in the approximation. - using std::ilogb; - - using local_exponent_type = typename floating_point_type::exponent_type; - - auto ilogb_of_x = static_cast(ilogb(x)); + using local_exponent_type = typename local_wide_decimal_type::exponent_type; + using std::ilogb; using std::log; const auto lg_x_approx = static_cast ( - static_cast(ilogb_of_x) - * log(static_cast(std::numeric_limits::radix)) + static_cast(static_cast(ilogb(x))) + * log(static_cast(std::numeric_limits::radix)) ); const auto lg_x_over_lg2 = static_cast(lg_x_approx / log(2.0F)); @@ -5873,7 +5902,7 @@ const auto m = (std::max)(static_cast(n_times_factor - lg_x_over_lg2), static_cast(3)); - floating_point_type bk = + local_wide_decimal_type bk = one(); bk.precision(precision_of_x); @@ -5886,8 +5915,8 @@ const auto digits10_iteration_goal_a = static_cast ( - static_cast(std::numeric_limits::digits10 / 2) - + (std::max)(static_cast(floating_point_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(std::numeric_limits::digits10 / 2) + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(UINT8_C(9))) ); @@ -5895,7 +5924,7 @@ static_cast ( static_cast(precision_of_x / 2) - + (std::max)(static_cast(floating_point_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + + (std::max)(static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(UINT8_C(9))) ); @@ -5915,7 +5944,7 @@ static_cast ( 1000.0F - * log(static_cast(std::numeric_limits::radix)) + * log(static_cast(std::numeric_limits::radix)) ) / log(10.0F) ) @@ -5940,7 +5969,7 @@ static_cast(static_cast(ilogb_of_ak_minus_bk) * digits10_scale) / UINT32_C(1000) ); - const floating_point_type ak_tmp(result); + const local_wide_decimal_type ak_tmp(result); result += bk; @@ -5949,10 +5978,10 @@ break; } - using std::sqrt; - result /= 2; + bk *= ak_tmp; + static_cast(bk.calculate_sqrt()); } @@ -5976,13 +6005,13 @@ template auto log(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen <= static_cast(INT8_C(51))), decwide_t>::type // NOLINT(misc-no-recursion) { - using floating_point_type = decwide_t; + using local_wide_decimal_type = decwide_t; - floating_point_type result { }; + local_wide_decimal_type result { }; if(x < one()) { - result = -log(floating_point_type(x).calculate_inv()); + result = -log(local_wide_decimal_type(x).calculate_inv()); } else if(x > one()) { @@ -5993,34 +6022,32 @@ // Subsequently define y = x_scaled - 1 and use // the Taylor series for log(y) evalueated at 1. - using local_exponent_type = typename floating_point_type::exponent_type; - using local_limb_type = typename floating_point_type::limb_type; - - using std::ilogb; + using local_exponent_type = typename local_wide_decimal_type::exponent_type; + using local_limb_type = typename local_wide_decimal_type::limb_type; auto n = ilogb(x); // Create a wide decimal scale_factor which is intended to scale // the input argument to a value in the approximate range 1 ... 10. - floating_point_type scale_factor = - floating_point_type::from_lst + local_wide_decimal_type scale_factor = + local_wide_decimal_type::from_lst ( { static_cast ( - detail::pow10_maker_as_runtime_value(static_cast(n % static_cast(floating_point_type::decwide_t_elem_digits10))) + detail::pow10_maker_as_runtime_value(static_cast(n % static_cast(local_wide_decimal_type::decwide_t_elem_digits10))) ) }, static_cast ( - (n / static_cast(floating_point_type::decwide_t_elem_digits10)) * static_cast(floating_point_type::decwide_t_elem_digits10) + (n / static_cast(local_wide_decimal_type::decwide_t_elem_digits10)) * static_cast(local_wide_decimal_type::decwide_t_elem_digits10) ) ); auto x_scaled = x / scale_factor; - if(x_scaled > static_cast(1.8F)) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + if(x_scaled > static_cast(1.8F)) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) { // Scale the argument by an additional factor of ten if // it exceeds an empirical limit designed to optimize @@ -6035,7 +6062,7 @@ const auto digits10_series_goal = static_cast ( - static_cast(std::numeric_limits::digits10) + static_cast(std::numeric_limits::digits10) + static_cast(INT8_C(5)) ); @@ -6092,14 +6119,13 @@ template auto exp(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen > static_cast(INT32_C(2000))), decwide_t>::type { - using floating_point_type = - decwide_t; + using local_wide_decimal_type = decwide_t; - floating_point_type exp_result; + local_wide_decimal_type exp_result; if(x.isneg()) { - exp_result = exp(floating_point_type(x).negate()).calculate_inv(); + exp_result = exp(local_wide_decimal_type(x).negate()).calculate_inv(); } else if(!x.iszero()) { @@ -6128,14 +6154,14 @@ } else { - const auto precision_of_x = floating_point_type::get_precision(x); + const auto precision_of_x = local_wide_decimal_type::get_precision(x); // Setup the iteration. // Use the original value of x for iteration below. - floating_point_type original_x(x); + local_wide_decimal_type original_x(x); - floating_point_type iterate_term; + local_wide_decimal_type iterate_term; using std::exp; @@ -6153,7 +6179,7 @@ const auto min_elem_digits10_plus_one = (std::min) ( - static_cast(floating_point_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), + static_cast(local_wide_decimal_type::decwide_t_elem_digits10 + static_cast(INT8_C(1))), static_cast(INT8_C(9)) ); @@ -6190,15 +6216,15 @@ template auto exp(const decwide_t& x) -> typename std::enable_if<(ParamDigitsBaseTen <= static_cast(INT32_C(2000))), decwide_t>::type { - using floating_point_type = decwide_t; + using local_wide_decimal_type = decwide_t; const auto b_neg = x.isneg(); - floating_point_type exp_result; + local_wide_decimal_type exp_result; if(b_neg || (x > 0)) { - const floating_point_type xx = ((!b_neg) ? x : -x); + const local_wide_decimal_type xx = ((!b_neg) ? x : -x); // The algorithm for exp has been taken from MPFUN. // exp(t) = [ (1 + r + r^2/2! + r^3/3! + r^4/4! ...)^p2 ] * 2^n @@ -6210,9 +6236,9 @@ // Get (compute beforehad) ln2 as a constant or constant reference value. #if !defined(WIDE_DECIMAL_DISABLE_CACHED_CONSTANTS) - const floating_point_type& ln2 = ln_two(); + const local_wide_decimal_type& ln2 = ln_two(); #else - const floating_point_type ln2 = ln_two(); // LCOV_EXCL_LINE + const local_wide_decimal_type ln2 = ln_two(); // LCOV_EXCL_LINE #endif const auto nf = static_cast(xx / ln2); @@ -6225,15 +6251,15 @@ // http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric0F0/06/01/ // There are no checks on input range or parameter boundaries. - const auto precision_of_x = floating_point_type::get_precision(x); + const auto precision_of_x = local_wide_decimal_type::get_precision(x); - floating_point_type xh((xx - static_cast(nf * ln2)) / p2); + local_wide_decimal_type xh((xx - static_cast(nf * ln2)) / p2); xh.precision(precision_of_x); - floating_point_type x_pow_n_div_n_fact(xh); + local_wide_decimal_type x_pow_n_div_n_fact(xh); - floating_point_type + local_wide_decimal_type h0f0 ( one() @@ -6242,13 +6268,13 @@ h0f0.precision(precision_of_x); - using local_exponent_type = typename floating_point_type::exponent_type; + using local_exponent_type = typename local_wide_decimal_type::exponent_type; using std::ilogb; const auto iteration_goal_ilobg = (std::max)(static_cast(INT8_C(0)), - static_cast(-ilogb(std::numeric_limits::epsilon()))); + static_cast(-ilogb(std::numeric_limits::epsilon()))); const auto iteration_goal_prec = static_cast(precision_of_x); @@ -6284,8 +6310,6 @@ h0f0 += x_pow_n_div_n_fact; } - using std::pow; - exp_result = pow(h0f0, p2); if(nf != static_cast(UINT8_C(0))) @@ -6311,35 +6335,33 @@ template auto sinh(const decwide_t& x) -> decwide_t { - using floating_point_type = - decwide_t; - const auto ep = exp(x); - return (ep - floating_point_type(ep).calculate_inv()) / static_cast(UINT8_C(2)); + using local_wide_decimal_type = decwide_t; + + return (ep - local_wide_decimal_type(ep).calculate_inv()) /= static_cast(UINT8_C(2)); } template auto cosh(const decwide_t& x) -> decwide_t { - using floating_point_type = - decwide_t; - const auto ep = exp(x); - return (ep + floating_point_type(ep).calculate_inv()) / static_cast(UINT8_C(2)); + using local_wide_decimal_type = decwide_t; + + return (ep + local_wide_decimal_type(ep).calculate_inv()) /= static_cast(UINT8_C(2)); } template auto tanh(const decwide_t& x) -> decwide_t { - using floating_point_type = - decwide_t; - const auto ep = exp(x); - const auto em(floating_point_type(ep).calculate_inv()); - return (ep - em) / (ep + em); + using local_wide_decimal_type = decwide_t; + + const auto em(local_wide_decimal_type(ep).calculate_inv()); + + return (ep - em) /= (ep + em); } template @@ -6347,21 +6369,21 @@ { // Calculate (b ^ p). - using floating_point_type = decwide_t; + using local_wide_decimal_type = decwide_t; - floating_point_type result; + local_wide_decimal_type result; if (p < static_cast(INT8_C(0))) { result = pow(b, -p).calculate_inv(); } - else if(p == static_cast(INT8_C(0))) { result = floating_point_type(static_cast(UINT8_C(1))); } + else if(p == static_cast(INT8_C(0))) { result = local_wide_decimal_type(static_cast(UINT8_C(1))); } else if(p == static_cast(INT8_C(1))) { result = b; } else if(p == static_cast(INT8_C(2))) { result = b; result *= b; } else if(p == static_cast(INT8_C(3))) { result = b; result *= b; result *= b; } else if(p == static_cast(INT8_C(4))) { result = b; result *= b; result *= result; } else { - result = floating_point_type(static_cast(UINT8_C(1))); + result = local_wide_decimal_type(static_cast(UINT8_C(1))); - floating_point_type y(b); + local_wide_decimal_type y(b); auto p_local = static_cast(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 072bdf66e..5ad9a6233 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail.h @@ -155,7 +155,7 @@ { using local_array_type = std::array; // NOLINT(,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - // Sloane's A029750 List of numbers of the form 2^k times 1, 3, 5 or 7. + // 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 = {{ @@ -188,7 +188,7 @@ { static constexpr auto a000079_as_constexpr(const std::uint32_t value) noexcept -> std::uint32_t // NOLINT(readability-function-cognitive-complexity) { - // Sloane's A000079 List of numbers of powers of 2. + // 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)) : @@ -303,8 +303,8 @@ : (std::is_same::value ? static_cast(INT8_C(4)) : static_cast(INT8_C(2)))); - static constexpr auto elem_mask = static_cast(pow10_maker(static_cast(elem_digits10))); - static constexpr auto elem_mask_half = static_cast(pow10_maker(static_cast(elem_digits10 / 2))); + static constexpr std::int32_t elem_mask = static_cast(pow10_maker(static_cast(elem_digits10))); + static constexpr std::int32_t elem_mask_half = static_cast(pow10_maker(static_cast(elem_digits10 / 2))); static constexpr auto digit_at_pos_in_limb(local_limb_type u, unsigned pos) noexcept -> std::uint8_t { @@ -332,13 +332,13 @@ using base_class_type = decwide_t_helper_base; public: - static constexpr auto digits10 = ParamDigitsBaseTen; - static constexpr auto digits = digits10; - static constexpr auto max_digits10 = static_cast(digits10 + static_cast(INT32_C(4))); - static constexpr auto radix = static_cast(INT32_C(10)); + static constexpr std::int32_t digits10 = ParamDigitsBaseTen; + static constexpr std::int32_t digits = digits10; + static constexpr std::int32_t max_digits10 = static_cast(digits10 + static_cast(INT32_C(4))); + static constexpr std::int32_t radix = static_cast(INT32_C(10)); - static constexpr auto elem_number_extra = static_cast(INT32_C(3)); - static constexpr auto elem_number = static_cast(((digits10 / base_class_type::elem_digits10) + (((digits10 % base_class_type::elem_digits10) != 0) ? 1 : 0)) + elem_number_extra); + static constexpr std::int32_t elem_number_extra = static_cast(INT32_C(3)); + static constexpr std::int32_t elem_number = static_cast(((digits10 / base_class_type::elem_digits10) + (((digits10 % base_class_type::elem_digits10) != 0) ? 1 : 0)) + elem_number_extra); }; template constexpr std::int32_t decwide_t_helper::digits10; // NOLINT(readability-redundant-declaration,hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix) diff --git a/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h b/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h index 1ef2d8c78..270b67ec6 100644 --- a/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h +++ b/ref_app/src/math/wide_decimal/decwide_t_detail_namespace.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2022 2023. // +// Copyright Christopher Kormanyos 2022 - 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) // diff --git a/ref_app/src/math/wide_integer/uintwide_t.h b/ref_app/src/math/wide_integer/uintwide_t.h index bbb5d05dc..3c92db2fb 100644 --- a/ref_app/src/math/wide_integer/uintwide_t.h +++ b/ref_app/src/math/wide_integer/uintwide_t.h @@ -151,10 +151,17 @@ namespace math { namespace wide_integer { namespace detail { // NOLINT(modernize-concat-nested-namespaces) #endif + // Use a local, constexpr, unsafe implementation of the abs-function. + template + WIDE_INTEGER_CONSTEXPR auto abs_unsafe(ArithmeticType val) -> ArithmeticType + { + return ((val > static_cast(INT8_C(0))) ? val : -val); + } + // Use a local, constexpr, unsafe implementation of the fill-function. template - inline WIDE_INTEGER_CONSTEXPR auto fill_unsafe(DestinationIterator first, DestinationIterator last, ValueType val) -> void + WIDE_INTEGER_CONSTEXPR auto fill_unsafe(DestinationIterator first, DestinationIterator last, ValueType val) -> void { while(first != last) { @@ -167,7 +174,7 @@ // Use a local, constexpr, unsafe implementation of the copy-function. template - inline WIDE_INTEGER_CONSTEXPR auto copy_unsafe(InputIterator first, InputIterator last, DestinationIterator dest) -> DestinationIterator + WIDE_INTEGER_CONSTEXPR auto copy_unsafe(InputIterator first, InputIterator last, DestinationIterator dest) -> DestinationIterator { while(first != last) { @@ -191,11 +198,11 @@ { using local_unsigned_integral_type = UnsignedIntegralType; - auto yy = static_cast(UINT8_C(0)); + auto yy_val = static_cast(UINT8_C(0)); - auto nn = static_cast(std::numeric_limits::digits); + auto nn_val = static_cast(std::numeric_limits::digits); - auto cc = // NOLINT(altera-id-dependent-backward-branch) + auto cc_val = // NOLINT(altera-id-dependent-backward-branch) static_cast ( std::numeric_limits::digits / static_cast(INT8_C(2)) @@ -203,23 +210,23 @@ do { - yy = static_cast(v >> cc); + yy_val = static_cast(v >> cc_val); - if(yy != static_cast(UINT8_C(0))) + if(yy_val != static_cast(UINT8_C(0))) { - nn -= cc; + nn_val -= cc_val; - v = yy; + v = yy_val; } - cc >>= static_cast(UINT8_C(1)); + cc_val >>= static_cast(UINT8_C(1)); } - while(cc != static_cast(UINT8_C(0))); // NOLINT(altera-id-dependent-backward-branch) + while(cc_val != static_cast(UINT8_C(0))); // NOLINT(altera-id-dependent-backward-branch) return static_cast ( - static_cast(nn) - static_cast(v) + static_cast(nn_val) - static_cast(v) ); } @@ -495,7 +502,7 @@ WIDE_INTEGER_CONSTEXPR auto swap(dynamic_array&& other) noexcept -> void { - auto tmp = std::move(*this); + const auto tmp = std::move(*this); *this = std::move(other); other = std::move(tmp); @@ -5738,11 +5745,7 @@ : static_cast(1U + static_cast((msb_pos + static_cast(UINT8_C(1))) / 2U))) ); - local_wide_integer_type - u - ( - local_wide_integer_type(static_cast(1U)) << left_shift_amount - ); + auto u = static_cast(static_cast(UINT8_C(1))) << left_shift_amount; // Perform the iteration for the square root. // See Algorithm 1.13 SqrtInt, Sect. 1.5.1 @@ -5799,7 +5802,7 @@ : static_cast(static_cast(UINT8_C(1)) + static_cast(static_cast(msb_pos + static_cast(static_cast(UINT8_C(3)) - msb_pos_mod_3)) / 3U)) ); - local_wide_integer_type u(local_wide_integer_type(static_cast(1U)) << left_shift_amount); + auto u = static_cast(static_cast(UINT8_C(1))) << left_shift_amount; // Perform the iteration for the k'th root. // See Algorithm 1.14 RootInt, Sect. 1.5.2 @@ -5880,7 +5883,7 @@ : static_cast(UINT8_C(1)) + static_cast(static_cast(msb_pos + static_cast(k - msb_pos_mod_k)) / k)) ); - local_wide_integer_type u(local_wide_integer_type(static_cast(1U)) << left_shift_amount); + auto u = static_cast(static_cast(UINT8_C(1))) << left_shift_amount; // Perform the iteration for the k'th root. // See Algorithm 1.14 RootInt, Sect. 1.5.2 @@ -5933,11 +5936,11 @@ { result = local_wide_integer_type(static_cast(UINT8_C(1))); } - else if((p0 == static_cast(UINT8_C(1))) && (p == static_cast(1))) + else if((p0 == static_cast(UINT8_C(1))) && (p == static_cast(UINT8_C(1)))) { result = b; } - else if((p0 == static_cast(UINT8_C(2))) && (p == static_cast(2))) + else if((p0 == static_cast(UINT8_C(2))) && (p == static_cast(UINT8_C(2)))) { result = b; result *= b; @@ -6072,12 +6075,12 @@ // This handles cases having (u = v) and also (u = v = 0). result = u; // LCOV_EXCL_LINE } - else if((static_cast(v) == static_cast(UINT8_C(0))) && (v == 0U)) + else if((static_cast(v) == static_cast(UINT8_C(0))) && (v == static_cast(UINT8_C(0)))) { // This handles cases having (v = 0) with (u != 0). result = u; // LCOV_EXCL_LINE } - else if((static_cast(u) == static_cast(UINT8_C(0))) && (u == 0U)) + else if((static_cast(u) == static_cast(UINT8_C(0))) && (u == static_cast(UINT8_C(0)))) { // This handles cases having (u = 0) with (v != 0). result = v; @@ -6126,7 +6129,7 @@ const auto my_v_hi = static_cast ( - (v.crepresentation().size() >= static_cast(2U)) + (v.crepresentation().size() >= static_cast(UINT8_C(2))) ? static_cast(*detail::advance_and_point(v.crepresentation().cbegin(), static_cast(UINT8_C(1)))) : static_cast(UINT8_C(0)) ); @@ -6134,7 +6137,7 @@ const auto my_u_hi = static_cast ( - (u.crepresentation().size() >= static_cast(2U)) + (u.crepresentation().size() >= static_cast(UINT8_C(2))) ? static_cast(*detail::advance_and_point(u.crepresentation().cbegin(), static_cast(UINT8_C(1)))) : static_cast(UINT8_C(0)) ); @@ -6172,10 +6175,8 @@ { using local_integer_type = IntegerType; - using std::abs; - - const local_integer_type ap = abs(a); - const local_integer_type bp = abs(b); + const local_integer_type ap = detail::abs_unsafe(a); + const local_integer_type bp = detail::abs_unsafe(b); const auto a_is_greater_than_b = (ap > bp); @@ -6270,7 +6271,7 @@ } else { - const auto division_is_exact = (ur == 0); + const auto division_is_exact = (ur == static_cast(UINT8_C(0))); if(!division_is_exact) { ++ua; } @@ -6468,17 +6469,15 @@ value = input_generator(); } - const auto next_byte = - static_cast + const auto right_shift_amount = + static_cast ( - value - >> static_cast - ( - static_cast(j % digits_gtor_ratio) - * static_cast(UINT8_C(8)) - ) + static_cast(j % digits_gtor_ratio) + * static_cast(UINT8_C(8)) ); + const auto next_byte = static_cast(value >> right_shift_amount); + *it = static_cast ( @@ -6497,7 +6496,7 @@ || (input_params.get_b() != (std::numeric_limits::max)())) { // Note that this restricts the range r to: - // r = {[input_generator() % ((b - a) + 1)] + a} + // r = { [input_generator() % ((b - a) + 1)] + a } result_type range(input_params.get_b() - input_params.get_a()); diff --git a/ref_app/src/util/STL/cmath b/ref_app/src/util/STL/cmath index 835d2ef57..e6da49ecf 100644 --- a/ref_app/src/util/STL/cmath +++ b/ref_app/src/util/STL/cmath @@ -15,6 +15,35 @@ #if defined(__GNUC__) && defined(__AVR__) #include + #ifndef _HUGE_ENUF + #define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow + #endif + + #if !defined(INFINITY) + #define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF)) + #endif + #define HUGE_VAL ((double)INFINITY) + #define HUGE_VALF ((float)INFINITY) + #define HUGE_VALL ((long double)INFINITY) + #if !defined(NAN) + #define NAN (-(float)(INFINITY * 0.0F)) + #endif + + #define _DENORM (-2) + #define _FINITE (-1) + #define _INFCODE 1 + #define _NANCODE 2 + + #define FP_INFINITE _INFCODE + #define FP_NAN _NANCODE + #define FP_NORMAL _FINITE + #define FP_SUBNORMAL _DENORM + #define FP_ZERO 0 + + #define _C2 1 // 0 if not 2's complement + #define FP_ILOGB0 (-0x7fffffff - _C2) + #define FP_ILOGBNAN 0x7fffffff + static_assert(__SIZEOF_LONG_DOUBLE__ >= __SIZEOF_DOUBLE__, "Error: Configuration error regarding 64-bit double/long-double for AVR"); diff --git a/ref_app/src/util/STL/functional b/ref_app/src/util/STL/functional index 6579110f5..a2ecd2c8f 100644 --- a/ref_app/src/util/STL/functional +++ b/ref_app/src/util/STL/functional @@ -14,6 +14,16 @@ namespace std { + template + struct hash + { + // Since the underlying type is a std::uint64_t we will rely on its hash function from the STL + auto operator()(const T&) const noexcept -> std::size_t + { + return std::size_t { }; + } + }; + namespace xfunctional_impl { template constexpr T& func_ref_or_moveref(T& t) noexcept { return t; } diff --git a/ref_app/src/util/STL/tuple b/ref_app/src/util/STL/tuple index a6a48f6ef..316f14e31 100644 --- a/ref_app/src/util/STL/tuple +++ b/ref_app/src/util/STL/tuple @@ -32,18 +32,20 @@ struct xnothing final { - xnothing() { } - xnothing(const xnothing&) { } - ~xnothing() { } - xnothing& operator=(const xnothing&) { return *this; } + constexpr xnothing() = default; + constexpr xnothing(const xnothing&) = default; + constexpr xnothing(xnothing&&) noexcept = default; + ~xnothing() = default; + constexpr xnothing& operator=(const xnothing&) { return *this; } + constexpr xnothing& operator=(xnothing&&) noexcept { return *this; } }; - inline bool operator==(const xnothing&, const xnothing&) { return true; } - inline bool operator!=(const xnothing&, const xnothing&) { return false; } - inline bool operator< (const xnothing&, const xnothing&) { return false; } - inline bool operator<=(const xnothing&, const xnothing&) { return false; } - inline bool operator> (const xnothing&, const xnothing&) { return false; } - inline bool operator>=(const xnothing&, const xnothing&) { return false; } + inline constexpr bool operator==(const xnothing&, const xnothing&) { return true; } + inline constexpr bool operator!=(const xnothing&, const xnothing&) { return false; } + inline constexpr bool operator< (const xnothing&, const xnothing&) { return false; } + inline constexpr bool operator<=(const xnothing&, const xnothing&) { return false; } + inline constexpr bool operator> (const xnothing&, const xnothing&) { return false; } + inline constexpr bool operator>=(const xnothing&, const xnothing&) { return false; } } namespace std @@ -79,59 +81,72 @@ tuple() { } - explicit tuple(const T0& p0, - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 (), - const T7& p7 = T7 (), - const T8& p8 = T8 (), - const T9& p9 = T9 (), - const T10& p10 = T10(), - const T11& p11 = T11()) : t0 (p0), - t1 (p1), - t2 (p2), - t3 (p3), - t4 (p4), - t5 (p5), - t6 (p6), - t7 (p7), - t8 (p8), - t9 (p9), - t10(p10), - t11(p11){ } - - tuple(const tuple_type& t) : t0 (t.t0), - t1 (t.t1), - t2 (t.t2), - t3 (t.t3), - t4 (t.t4), - t5 (t.t5), - t6 (t.t6), - t7 (t.t7), - t8 (t.t8), - t9 (t.t9), - t10(t.t10), - t11(t.t11){ } + constexpr tuple(const T0& p0, + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 (), + const T7& p7 = T7 (), + const T8& p8 = T8 (), + const T9& p9 = T9 (), + const T10& p10 = T10(), + const T11& p11 = T11()) : t0 (p0), + t1 (p1), + t2 (p2), + t3 (p3), + t4 (p4), + t5 (p5), + t6 (p6), + t7 (p7), + t8 (p8), + t9 (p9), + t10(p10), + t11(p11) { } + + constexpr tuple(const tuple_type& t) : t0 (t.t0), + t1 (t.t1), + t2 (t.t2), + t3 (t.t3), + t4 (t.t4), + t5 (t.t5), + t6 (t.t6), + t7 (t.t7), + t8 (t.t8), + t9 (t.t9), + t10(t.t10), + t11(t.t11) { } + + constexpr tuple(tuple_type&& t) : t0 (t.t0), + t1 (t.t1), + t2 (t.t2), + t3 (t.t3), + t4 (t.t4), + t5 (t.t5), + t6 (t.t6), + t7 (t.t7), + t8 (t.t8), + t9 (t.t9), + t10(t.t10), + t11(t.t11) { } template - tuple(const std::pair& p) : t0 (p.first), - t1 (p.second), - t2 (T2 ()), - t3 (T3 ()), - t4 (T4 ()), - t5 (T5 ()), - t6 (T6 ()), - t7 (T7 ()), - t8 (T8 ()), - t9 (T9 ()), - t10(T10()), - t11(T11()){ } - - ~tuple() { } + constexpr tuple(const std::pair& p) : t0 (p.first), + t1 (p.second), + t2 (T2 ()), + t3 (T3 ()), + t4 (T4 ()), + t5 (T5 ()), + t6 (T6 ()), + t7 (T7 ()), + t8 (T8 ()), + t9 (T9 ()), + t10(T10()), + t11(T11()){ } + + ~tuple() = default; template - tuple& operator=(const tuple& t) + constexpr tuple& operator=(const tuple& t) { - t0 = T0 (t.t0); - t1 = T1 (t.t1); - t2 = T2 (t.t2); - t3 = T3 (t.t3); - t4 = T4 (t.t4); - t5 = T5 (t.t5); - t6 = T6 (t.t6); - t7 = T7 (t.t7); - t8 = T8 (t.t8); - t9 = T9 (t.t9); - t10 = T10(t.t10); - t11 = T11(t.t11); + if(this != &t) + { + t0 = T0 (t.t0); + t1 = T1 (t.t1); + t2 = T2 (t.t2); + t3 = T3 (t.t3); + t4 = T4 (t.t4); + t5 = T5 (t.t5); + t6 = T6 (t.t6); + t7 = T7 (t.t7); + t8 = T8 (t.t8); + t9 = T9 (t.t9); + t10 = T10(t.t10); + t11 = T11(t.t11); + } return *this; } + constexpr tuple& operator=(tuple&& t) = default; + template - tuple& operator=(const std::pair& p) + constexpr tuple& operator=(const std::pair& p) { t0 = T0 (p.first); t1 = T1 (p.second); @@ -183,7 +203,7 @@ return *this; } - void swap(tuple& other) + constexpr void swap(tuple& other) { if(this != &other) { @@ -202,6 +222,22 @@ } } + constexpr void swap(tuple&& other) + { + const type0 tmp0 (t0 ); t0 = other.t0 ; other.t0 = tmp0 ; + const type1 tmp1 (t1 ); t1 = other.t1 ; other.t1 = tmp1 ; + const type2 tmp2 (t2 ); t2 = other.t2 ; other.t2 = tmp2 ; + const type3 tmp3 (t3 ); t3 = other.t3 ; other.t3 = tmp3 ; + const type4 tmp4 (t4 ); t4 = other.t4 ; other.t4 = tmp4 ; + const type5 tmp5 (t5 ); t5 = other.t5 ; other.t5 = tmp5 ; + const type6 tmp6 (t6 ); t6 = other.t6 ; other.t6 = tmp6 ; + const type7 tmp7 (t7 ); t7 = other.t7 ; other.t7 = tmp7 ; + const type8 tmp8 (t8 ); t8 = other.t8 ; other.t8 = tmp8 ; + const type9 tmp9 (t9 ); t9 = other.t9 ; other.t9 = tmp9 ; + const type10 tmp10(t10); t10 = other.t10; other.t10 = tmp10; + const type11 tmp11(t11); t11 = other.t11; other.t11 = tmp11; + } + private: T0 t0; T1 t1; @@ -236,14 +272,14 @@ template class xget { }; - #define MAKE_XTUPLE_GET_HELPER(NUM) \ - template class xget<(NUM), xtuple_type> \ - { \ - public: \ - typedef typename xtuple_type::type##NUM xelem_type; \ - static xelem_type& get ( xtuple_type& t) { return t.t##NUM ; } \ - static const xelem_type& get_const(const xtuple_type& t) { return t.t##NUM ; } \ - } \ + #define MAKE_XTUPLE_GET_HELPER(NUM) \ + template class xget<(NUM), xtuple_type> \ + { \ + public: \ + typedef typename xtuple_type::type##NUM xelem_type; \ + static constexpr xelem_type& get ( xtuple_type& t) { return t.t##NUM ; } \ + static constexpr const xelem_type& get_const(const xtuple_type& t) { return t.t##NUM ; } \ + } MAKE_XTUPLE_GET_HELPER(0); MAKE_XTUPLE_GET_HELPER(1); @@ -283,58 +319,58 @@ namespace std { template - typename xtuple_helper::xget >::xelem_type& get(tuple<>& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple<>& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } + constexpr typename xtuple_helper::xget >::xelem_type& get(tuple& t) { return xtuple_helper::xget >::get(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple<>& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple<>& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template - const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } + constexpr const typename xtuple_helper::xget >::xelem_type& get(const tuple& t) { return xtuple_helper::xget >::get_const(t); } template @@ -385,31 +421,31 @@ class tuple_size : public std::integral_constant::value> { }; template - tuple make_tuple(const T0& p0 = T0 ()) + constexpr tuple make_tuple(const T0& p0 = T0 ()) { return tuple(p0); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 ()) { return tuple(p0, p1); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 ()) { return tuple(p0, p1, p2); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 ()) { return tuple(p0, p1, p2, p3); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 ()) { return tuple(p0, p1, p2, p3, p4); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 ()) { return tuple(p0, p1, p2, p3, p4, p5); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 ()) { return tuple(p0, p1, p2, p3, p4, p5, p6); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 (), - const T7& p7 = T7 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 (), + const T7& p7 = T7 ()) { return tuple(p0, p1, p2, p3, p4, p5, p6, p7); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 (), - const T7& p7 = T7 (), - const T8& p8 = T8 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 (), + const T7& p7 = T7 (), + const T8& p8 = T8 ()) { return tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 (), - const T7& p7 = T7 (), - const T8& p8 = T8 (), - const T9& p9 = T9 ()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 (), + const T7& p7 = T7 (), + const T8& p8 = T8 (), + const T9& p9 = T9 ()) { return tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 (), - const T7& p7 = T7 (), - const T8& p8 = T8 (), - const T9& p9 = T9 (), - const T10& p10 = T10()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 (), + const T7& p7 = T7 (), + const T8& p8 = T8 (), + const T9& p9 = T9 (), + const T10& p10 = T10()) { return tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } template - tuple make_tuple(const T0& p0 = T0 (), - const T1& p1 = T1 (), - const T2& p2 = T2 (), - const T3& p3 = T3 (), - const T4& p4 = T4 (), - const T5& p5 = T5 (), - const T6& p6 = T6 (), - const T7& p7 = T7 (), - const T8& p8 = T8 (), - const T9& p9 = T9 (), - const T10& p10 = T10(), - const T11& p11 = T11()) + constexpr tuple make_tuple(const T0& p0 = T0 (), + const T1& p1 = T1 (), + const T2& p2 = T2 (), + const T3& p3 = T3 (), + const T4& p4 = T4 (), + const T5& p5 = T5 (), + const T6& p6 = T6 (), + const T7& p7 = T7 (), + const T8& p8 = T8 (), + const T9& p9 = T9 (), + const T10& p10 = T10(), + const T11& p11 = T11()) { return tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); } } diff --git a/ref_app/src/util/STL/type_traits b/ref_app/src/util/STL/type_traits index ea7d2bb3c..e63b24528 100644 --- a/ref_app/src/util/STL/type_traits +++ b/ref_app/src/util/STL/type_traits @@ -9,6 +9,7 @@ #define TYPE_TRAITS_2013_09_01_ #include + #include // Implement some of for compilers that do not yet support it. @@ -172,22 +173,28 @@ namespace std { template - struct make_unsigned { }; + struct make_unsigned + { + using type = typename std::conditional<(sizeof(T) > 4U), std::uint64_t, + typename std::conditional<(sizeof(T) > 2U), std::uint32_t, + typename std::conditional<(sizeof(T) > 1U), std::uint16_t, + std::uint8_t>::type>::type>::type; + }; - template<> struct make_unsigned { using type = unsigned char; }; - template<> struct make_unsigned { using type = unsigned short; }; - template<> struct make_unsigned { using type = unsigned int; }; - template<> struct make_unsigned { using type = unsigned long; }; - template<> struct make_unsigned { using type = unsigned long long; }; + template + struct make_signed + { + using type = typename std::conditional<(sizeof(T) > 4U), std::int64_t, + typename std::conditional<(sizeof(T) > 2U), std::int32_t, + typename std::conditional<(sizeof(T) > 1U), std::int16_t, + std::int8_t>::type>::type>::type; + }; template - struct make_signed { }; + using make_unsigned_t = typename std::make_unsigned::type; - template<> struct make_signed { using type = signed char; }; - template<> struct make_signed { using type = signed short; }; - template<> struct make_signed { using type = signed int; }; - template<> struct make_signed { using type = signed long; }; - template<> struct make_signed { using type = signed long long; }; + template + using make_signed_t = typename std::make_signed::type; } namespace traits_helper From da5598f5e0ffe90dd8247b8d18bcdff32182c884 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Sat, 18 Nov 2023 11:54:48 +0100 Subject: [PATCH 2/3] Try repair tuple --- ref_app/src/util/STL/tuple | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ref_app/src/util/STL/tuple b/ref_app/src/util/STL/tuple index 316f14e31..a768b0a93 100644 --- a/ref_app/src/util/STL/tuple +++ b/ref_app/src/util/STL/tuple @@ -36,16 +36,16 @@ constexpr xnothing(const xnothing&) = default; constexpr xnothing(xnothing&&) noexcept = default; ~xnothing() = default; - constexpr xnothing& operator=(const xnothing&) { return *this; } - constexpr xnothing& operator=(xnothing&&) noexcept { return *this; } + constexpr auto operator=(const xnothing&) -> xnothing& = default; + constexpr auto operator=(xnothing&&) noexcept -> xnothing& = default; }; - inline constexpr bool operator==(const xnothing&, const xnothing&) { return true; } - inline constexpr bool operator!=(const xnothing&, const xnothing&) { return false; } - inline constexpr bool operator< (const xnothing&, const xnothing&) { return false; } - inline constexpr bool operator<=(const xnothing&, const xnothing&) { return false; } - inline constexpr bool operator> (const xnothing&, const xnothing&) { return false; } - inline constexpr bool operator>=(const xnothing&, const xnothing&) { return false; } + inline constexpr auto operator==(const xnothing&, const xnothing&) noexcept -> bool { return true; } + inline constexpr auto operator!=(const xnothing&, const xnothing&) noexcept -> bool { return false; } + inline constexpr auto operator< (const xnothing&, const xnothing&) noexcept -> bool { return false; } + inline constexpr auto operator<=(const xnothing&, const xnothing&) noexcept -> bool { return false; } + inline constexpr auto operator> (const xnothing&, const xnothing&) noexcept -> bool { return false; } + inline constexpr auto operator>=(const xnothing&, const xnothing&) noexcept -> bool { return false; } } namespace std From 46c1ed2ed99864776b3749bc4c0013c64f3b0e12 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Sat, 18 Nov 2023 12:03:38 +0100 Subject: [PATCH 3/3] Remove faulty default assignment ops --- ref_app/src/util/STL/tuple | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ref_app/src/util/STL/tuple b/ref_app/src/util/STL/tuple index a768b0a93..ce2585345 100644 --- a/ref_app/src/util/STL/tuple +++ b/ref_app/src/util/STL/tuple @@ -33,11 +33,7 @@ struct xnothing final { constexpr xnothing() = default; - constexpr xnothing(const xnothing&) = default; - constexpr xnothing(xnothing&&) noexcept = default; ~xnothing() = default; - constexpr auto operator=(const xnothing&) -> xnothing& = default; - constexpr auto operator=(xnothing&&) noexcept -> xnothing& = default; }; inline constexpr auto operator==(const xnothing&, const xnothing&) noexcept -> bool { return true; }