diff --git a/examples/chapter11_07/chapter11_07.vcxproj b/examples/chapter11_07/chapter11_07.vcxproj index 226a4b3a6..f47a45678 100644 --- a/examples/chapter11_07/chapter11_07.vcxproj +++ b/examples/chapter11_07/chapter11_07.vcxproj @@ -287,8 +287,8 @@ - - + + diff --git a/examples/chapter11_07/chapter11_07.vcxproj.filters b/examples/chapter11_07/chapter11_07.vcxproj.filters index 6ba8795bc..b701821dd 100644 --- a/examples/chapter11_07/chapter11_07.vcxproj.filters +++ b/examples/chapter11_07/chapter11_07.vcxproj.filters @@ -290,12 +290,6 @@ src\mcal\host - - src\mcal - - - src\mcal - src\os\FreeRTOS\Source\include @@ -449,6 +443,12 @@ src\math\checksums\crc + + src\mcal + + + src\mcal + diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only/FreeRTOSConfig.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only/FreeRTOSConfig.h index 6125de55c..7dfdfe278 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only/FreeRTOSConfig.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only/FreeRTOSConfig.h @@ -56,8 +56,8 @@ configTOTAL_HEAP_SIZE is not defined. */ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ (( unsigned long) 16000000ULL) -#define configTICK_RATE_HZ (( TickType_t) 1000ULL) +#define configCPU_CLOCK_HZ ((unsigned long) 16000000ULL) +#define configTICK_RATE_HZ ((TickType_t) 1000ULL) #define configMAX_PRIORITIES (4) #define configMINIMAL_STACK_SIZE ((unsigned short) 96) #define configMAX_TASK_NAME_LEN (32) diff --git a/examples/chapter16_08/chapter16_08.vcxproj b/examples/chapter16_08/chapter16_08.vcxproj index 0a07f5c90..5a4c75792 100644 --- a/examples/chapter16_08/chapter16_08.vcxproj +++ b/examples/chapter16_08/chapter16_08.vcxproj @@ -54,12 +54,12 @@ - $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_86_0;$(IncludePath) + $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_87_0;$(IncludePath) $(SolutionDir)$(Configuration)\ $(Configuration)\ - $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_86_0;$(IncludePath) + $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_87_0;$(IncludePath) $(SolutionDir)$(Configuration)\ $(Configuration)\ @@ -78,6 +78,7 @@ $(SolutionDir)$(Configuration)\$(ProjectName).exe true Console + $(ProjectDir)src\math\test\wstp64i4.lib;%(AdditionalDependencies) @@ -95,6 +96,7 @@ Console true true + $(ProjectDir)src\math\test\wstp64i4.lib;%(AdditionalDependencies) diff --git a/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h b/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h index 86a7e48f2..02c47614d 100644 --- a/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h +++ b/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 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) // -#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_BASE_2020_07_16_H_ - #define MATH_TEST_INDEPENDENT_TEST_SYSTEM_BASE_2020_07_16_H_ +#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_BASE_2020_07_16_H + #define MATH_TEST_INDEPENDENT_TEST_SYSTEM_BASE_2020_07_16_H #include @@ -17,7 +17,7 @@ public: virtual ~independent_test_system_base() noexcept = default; - virtual bool is_prime(const char* const pstr_prime_candidate) const = 0; + virtual auto is_prime(const char* const pstr_prime_candidate) const -> bool = 0; protected: independent_test_system_base() noexcept = default; @@ -27,4 +27,4 @@ } // namespace math } // namespace WIDE_INTEGER_NAMESPACE -#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_BASE_2020_07_16_H_ +#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_BASE_2020_07_16_H diff --git a/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h b/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h index 6e463bae7..e751a9ae6 100644 --- a/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h +++ b/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.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) diff --git a/examples/chapter16_08/src/math/test/math_test_independent_test_system_mathlink.h b/examples/chapter16_08/src/math/test/math_test_independent_test_system_mathlink.h index 41ab96887..388e1fcc5 100644 --- a/examples/chapter16_08/src/math/test/math_test_independent_test_system_mathlink.h +++ b/examples/chapter16_08/src/math/test/math_test_independent_test_system_mathlink.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 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) // -#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_MATHLINK_2019_12_29_H_ - #define MATH_TEST_INDEPENDENT_TEST_SYSTEM_MATHLINK_2019_12_29_H_ +#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_MATHLINK_2019_12_29_H + #define MATH_TEST_INDEPENDENT_TEST_SYSTEM_MATHLINK_2019_12_29_H #include #include @@ -40,7 +40,7 @@ namespace detail { - inline constexpr char* strcpy_unsafe(char* dst, const char* src) + inline constexpr auto strcpy_unsafe(char* dst, const char* src) -> char* { // Use a local implementation of string copy. while((*dst++ = *src++) != char('\0')) { ; } @@ -48,7 +48,7 @@ return dst; } - inline constexpr std::uint_fast32_t strlen_unsafe(const char* pstr) + inline constexpr auto strlen_unsafe(const char* pstr) -> std::uint_fast32_t { // Use a local implementation of string length. std::uint_fast32_t u = 0U; @@ -65,13 +65,12 @@ } // namespace detail template - class independent_test_system_mathlink - : public math::test::independent_test_system_base + class independent_test_system_mathlink : public math::test::independent_test_system_base { private: - static constexpr int RETURNPKT = 3; + static constexpr int RETURNPKT { 3 }; - static constexpr int return_packet_id() { return RETURNPKT; } + static constexpr auto return_packet_id() noexcept -> int { return RETURNPKT; } public: // This is the computer_algebra_system_mathlink class. @@ -89,7 +88,7 @@ static_cast(close_is_ok); } - virtual bool is_prime(const char* const pstr_prime_candidate) const override + auto is_prime(const char* const pstr_prime_candidate) const -> bool override { // Test with, for eample, // PrimeQ[FromDigits["A6BAC43FEE73E832401B1E32417BD0AF",16]] @@ -101,14 +100,14 @@ return (send_command(str_cmd, &str_rsp) && (str_rsp == "True")); } - static constexpr bool get_valid() noexcept { return my_valid; } + static constexpr auto get_valid() noexcept -> bool { return my_valid; } private: static bool my_valid; static WSENV env_ptr; static WSLINK lnk_ptr; - static bool send_command(const std::string& str_cmd, std::string* str_rsp) + static auto send_command(const std::string& str_cmd, std::string* str_rsp) -> bool { const bool suppress_output = (str_rsp == nullptr); @@ -162,17 +161,17 @@ return result_is_ok; } - static constexpr WSENV& global_env_ptr() noexcept { return env_ptr; } - static constexpr WSLINK& global_lnk_ptr() noexcept { return lnk_ptr; } + static constexpr auto global_env_ptr() noexcept -> WSENV& { return env_ptr; } + static constexpr auto global_lnk_ptr() noexcept -> WSLINK& { return lnk_ptr; } - static int next_packet () noexcept { return ::WSNextPacket (global_lnk_ptr()); } - static int new_packet () noexcept { return ::WSNewPacket (global_lnk_ptr()); } - static bool put_function(const std::string& str, int argc) noexcept { return (::WSPutFunction(global_lnk_ptr(), str.c_str(), argc) != 0); } - static bool put_string (const std::string& str) noexcept { return (::WSPutString (global_lnk_ptr(), str.c_str()) != 0); } - static bool end_packet () noexcept { return (::WSEndPacket (global_lnk_ptr()) != 0); } - static int error () noexcept { return ::WSError (global_lnk_ptr()); } + static auto next_packet () noexcept -> int { return ::WSNextPacket (global_lnk_ptr()); } + static auto new_packet () noexcept -> int { return ::WSNewPacket (global_lnk_ptr()); } + static auto put_function(const std::string& str, int argc) noexcept -> bool { return (::WSPutFunction(global_lnk_ptr(), str.c_str(), argc) != 0); } + static auto put_string (const std::string& str) noexcept -> bool { return (::WSPutString (global_lnk_ptr(), str.c_str()) != 0); } + static auto end_packet () noexcept -> bool { return (::WSEndPacket (global_lnk_ptr()) != 0); } + static auto error () noexcept -> int { return ::WSError (global_lnk_ptr()); } - static bool get_string(std::string* str_rsp) + static auto get_string(std::string* str_rsp) -> bool { const char* s = nullptr; @@ -190,13 +189,13 @@ return get_string_is_ok; } - static constexpr bool is_open() noexcept + static constexpr auto is_open() noexcept -> bool { return ( (global_env_ptr() != nullptr) && (global_lnk_ptr() != nullptr)); } - static bool open(const char* str_location_math_kernel_user = PtrStrLocationMathLinkKernel) noexcept + static auto open(const char* str_location_math_kernel_user = PtrStrLocationMathLinkKernel) noexcept -> bool { // Initialize the mathlink kernel. global_env_ptr() = ::WSInitialize(nullptr); @@ -212,8 +211,10 @@ // TBD: What about supporting non-Win* platforms like *nix? - constexpr char str_location_math_kernel_default[] = - "\"C:\\Program Files\\Wolfram Research\\Mathematica\\12.0\\MathKernel.exe\""; + constexpr char str_location_math_kernel_default[] + { + "\"C:\\Program Files\\Wolfram Research\\Mathematica\\14.0\\MathKernel.exe\"" + }; // Create a list of constant arguments for opening the mathlink kernel. using const_args_strings_type = std::array; @@ -258,7 +259,7 @@ return is_open(); } - static bool close() noexcept + static auto close() noexcept -> bool { const bool close_is_ok = is_open(); @@ -280,12 +281,12 @@ } }; - template bool math::test::independent_test_system_mathlink::my_valid = false; - template WSENV math::test::independent_test_system_mathlink::env_ptr = nullptr; - template WSLINK math::test::independent_test_system_mathlink::lnk_ptr = nullptr; + template bool math::test::independent_test_system_mathlink::my_valid { false }; + template WSENV math::test::independent_test_system_mathlink::env_ptr { nullptr }; + template WSLINK math::test::independent_test_system_mathlink::lnk_ptr { nullptr }; } // namespace test } // namespace math } // namespace WIDE_INTEGER_NAMESPACE -#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_MATHLINK_2019_12_29_H_ +#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_MATHLINK_2019_12_29_H diff --git a/examples/chapter16_08/src/math/test/math_test_independent_test_system_none.h b/examples/chapter16_08/src/math/test/math_test_independent_test_system_none.h index 2eade0e1b..d5fe614c4 100644 --- a/examples/chapter16_08/src/math/test/math_test_independent_test_system_none.h +++ b/examples/chapter16_08/src/math/test/math_test_independent_test_system_none.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 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) // -#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_NONE_2020_07_15_H_ - #define MATH_TEST_INDEPENDENT_TEST_SYSTEM_NONE_2020_07_15_H_ +#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_NONE_2020_07_15_H + #define MATH_TEST_INDEPENDENT_TEST_SYSTEM_NONE_2020_07_15_H #include @@ -19,7 +19,7 @@ virtual ~independent_test_system_none() noexcept = default; - virtual bool is_prime(const char* const pstr_prime_candidate) const override + auto is_prime(const char* const pstr_prime_candidate) const -> bool override { static_cast(pstr_prime_candidate); @@ -31,4 +31,4 @@ } // namespace math } // namespace WIDE_INTEGER_NAMESPACE -#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_NONE_2020_07_15_H_ +#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_NONE_2020_07_15_H diff --git a/examples/chapter16_08/src/math/test/wstp64i4.lib b/examples/chapter16_08/src/math/test/wstp64i4.lib new file mode 100644 index 000000000..f53f9c9b5 Binary files /dev/null and b/examples/chapter16_08/src/math/test/wstp64i4.lib differ diff --git a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h index cb15ecd0d..524dd38fe 100644 --- a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h +++ b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h @@ -89,38 +89,74 @@ { const limb_type lo_limb = my_n_trial.crepresentation().front(); - const std::uint8_t lo_bit = std::uint8_t(std::uint8_t(lo_limb) & 1U); + const std::uint8_t + lo_bit + { + static_cast + ( + static_cast(lo_limb) & std::uint8_t { UINT8_C(1) } + ) + }; // Remove all even candidates since they are non-prime. - if(lo_bit != 0U) + if(lo_bit != std::uint8_t { UINT8_C(0) }) { - const std::uint8_t lo_digit10 = std::uint8_t(my_n_trial % std::uint8_t(10U)); + const std::uint8_t + lo_digit10 + { + static_cast(my_n_trial % std::uint8_t { UINT8_C(10) }) + }; // Continue by removing candidates having trailing digit 5. // The result is all candidates have trailing digit 1,3,7,9 - if(lo_digit10 != 5U) + + if(lo_digit10 != std::uint8_t { UINT8_C(5) }) { // Now remove candidates having digital root 3, 6 or 9 // because these are divisible by 3 and thus non-prime. // To compute the digital root of n dr(n), use // dr(n) = 1 + (n - 1) % 9. - wide_integer_type n_minus_one(my_n_trial); + wide_integer_type n_minus_one { my_n_trial }; --n_minus_one; - const std::uint8_t dr = - std::uint8_t(UINT8_C(1) + (std::uint8_t(n_minus_one % std::uint8_t(9U)))); - - if((dr != UINT8_C(3)) && (dr != UINT8_C(6)) && (dr != UINT8_C(9))) + const std::uint8_t + digital_root + { + static_cast + ( + std::uint8_t { UINT8_C(1) } + + static_cast(n_minus_one % std::uint8_t { UINT8_C(9) }) + ) + }; + + const bool + has_digital_root_of_3_6_or_9 + { + (digital_root == std::uint8_t { UINT8_C(3) }) + || (digital_root == std::uint8_t { UINT8_C(6) }) + || (digital_root == std::uint8_t { UINT8_C(9) }) + }; + + if(!has_digital_root_of_3_6_or_9) { + // We have found a viable prime candidate. Use this prime + // candidate to start a new Miller-Rabin primality test. + set_n_is_ok = true; + // Reset the prime-search variables. + my_n_trial_is_probably_prime = false; my_n = my_n_trial; my_n_is_probably_prime = false; - my_n_total_mul_10 += 10U; + my_n_total_mul_10 = + static_cast + ( + my_n_total_mul_10 + std::uint_fast8_t { UINT8_C(10) } + ); } } } diff --git a/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp b/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp index 56e17b7a5..696fe18ba 100644 --- a/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp +++ b/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 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) @@ -19,8 +19,10 @@ namespace { // Use the default mathlink 12.1 kernel location on Win*. - static const char independent_test_system_mathlink_location[] = - "\"C:\\Program Files\\Wolfram Research\\Mathematica\\12.1\\MathKernel.exe\""; + constexpr char independent_test_system_mathlink_location[] + { + "\"C:\\Program Files\\Wolfram Research\\Mathematica\\14.0\\MathKernel.exe\"" + }; } #endif diff --git a/examples/chapter16_08/wstp64i4.dll b/examples/chapter16_08/wstp64i4.dll new file mode 100644 index 000000000..aa64d1350 Binary files /dev/null and b/examples/chapter16_08/wstp64i4.dll differ diff --git a/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h b/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h index 0f6241eb9..63e5f47e2 100644 --- a/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h +++ b/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h @@ -31,6 +31,8 @@ explicit vacuum_fluorescent_display_nec_fm20x2kb(util::communication_base& ser) : my_serial(ser) { } + vacuum_fluorescent_display_nec_fm20x2kb() = delete; + ~vacuum_fluorescent_display_nec_fm20x2kb() override = default; auto init() -> bool override