diff --git a/code_snippets/chapter12/chapter12_07-001_derivative.cpp b/code_snippets/chapter12/chapter12_07-001_derivative.cpp index 72407e651..dd8ad2b6a 100644 --- a/code_snippets/chapter12/chapter12_07-001_derivative.cpp +++ b/code_snippets/chapter12/chapter12_07-001_derivative.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2017 - 2025. +// Copyright Christopher Kormanyos 2017 - 2026. // 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) @@ -13,13 +13,15 @@ #include #include #include +#include #include template -auto derivative(const ValueType x, - const ValueType dx, - FunctionType function) -> ValueType +constexpr auto derivative(ValueType x, + ValueType dx, + FunctionType function) + -> ValueType { using value_type = ValueType; @@ -43,13 +45,13 @@ auto derivative(const ValueType x, return ((fifteen_m1 - six_m2) + m3) / ten_dx1; } -const auto x = static_cast(std::numbers::pi_v / static_cast(3.0L)); +constexpr float xval { static_cast(std::numbers::pi_v / static_cast(3.0L)) }; // Should be very near 0.5. const auto y = - derivative(x, - static_cast(0.01L), - [](const float& x) -> float + derivative(xval, + 0.01F, + [](float x) -> float { return std::sin(x); }); @@ -61,7 +63,7 @@ auto main() -> int std::stringstream strm { }; // 0.500003 - strm << std::setprecision(std::numeric_limits::digits10) << y << '\n'; + strm << std::setprecision(std::numeric_limits::digits10) << std::fixed << y << '\n'; using std::fabs; diff --git a/code_snippets/chapter12/chapter12_07-002_deriv_quadratic.cpp b/code_snippets/chapter12/chapter12_07-002_deriv_quadratic.cpp index 47cb2bcd0..5d9b6b765 100644 --- a/code_snippets/chapter12/chapter12_07-002_deriv_quadratic.cpp +++ b/code_snippets/chapter12/chapter12_07-002_deriv_quadratic.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2017 - 2025. +// Copyright Christopher Kormanyos 2017 - 2026. // 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) @@ -15,9 +15,10 @@ template -auto derivative(const ValueType x, - const ValueType dx, - FunctionType function) -> ValueType +constexpr auto derivative(const ValueType x, + const ValueType dx, + FunctionType function) + -> ValueType { using value_type = ValueType; @@ -49,25 +50,22 @@ class quadratic const T b; const T c; - quadratic(const T& a_, - const T& b_, - const T& c_) : a(a_), - b(b_), - c(c_) { } + explicit constexpr quadratic(T a_, T b_, T c_) + : a(a_), b(b_), c(c_) { } - auto operator()(const T& x) const -> T + constexpr auto operator()(T x) const -> T { return ((a * x + b) * x) + c; } }; -const float x { 0.5F }; +constexpr float xval { 0.5F }; // Should be very near 4.6. -const float y = - derivative(x, +constexpr float y = + derivative(xval, 0.01F, - quadratic(1.2F, 3.4F, 5.6F)); + quadratic(1.2F, 3.4F, 5.6F)); auto main() -> int; @@ -75,8 +73,8 @@ auto main() -> int { std::stringstream strm { }; - // 4.6 - strm << std::setprecision(std::numeric_limits::digits10) << y << '\n'; + // 4.600001 + strm << std::setprecision(std::numeric_limits::digits10) << std::fixed << y << '\n'; using std::fabs; diff --git a/ref_app/tools/AVR/avrdude/avrdude-v8.0-windows-x64/11_07a.bat b/ref_app/tools/AVR/avrdude/avrdude-v8.0-windows-x64/11_07a.bat new file mode 100644 index 000000000..73183b2cd --- /dev/null +++ b/ref_app/tools/AVR/avrdude/avrdude-v8.0-windows-x64/11_07a.bat @@ -0,0 +1,28 @@ +rem /////////////////////////////////////////////////////////////////////////////// +rem // Copyright Christopher Kormanyos 2007 - 2025. +rem // Distributed under the Boost Software License, +rem // Version 1.0. (See accompanying file LICENSE_1_0.txt +rem // or copy at http://www.boost.org/LICENSE_1_0.txt) +rem // + +echo off + +set AVRDUDE=.\avrdude.exe + +set HEX=../../../../../examples/chapter11_07a/bin/chapter11_07a.hex + + +rem Erase the chip. +echo "Erase the chip." +%AVRDUDE% -c avrisp2 -p m328p -P usb -e +echo. + +rem Flash the HEX-file. +echo "Flash the HEX-file." +%AVRDUDE% -c avrisp2 -p m328p -P usb -U flash:w:%HEX%:i +echo. + +rem Verify the flash. +echo "Verify the flash." +%AVRDUDE% -c avrisp2 -p m328p -P usb -U flash:v:%HEX%:i +echo.