From b7a2b0f01604ba86ca48b16b1981e72824bdd499 Mon Sep 17 00:00:00 2001 From: Steve Hollasch Date: Wed, 8 Apr 2020 13:02:11 -0700 Subject: [PATCH] Fix error in one dimensional MC integration Also: - fixes uninitialized sum - removes unreferenced variables Resolves #438 --- CHANGELOG.md | 5 +++++ books/RayTracingTheRestOfYourLife.html | 12 ++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd55363..3a7a43b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ Change Log -- Ray Tracing in One Weekend - Fix: Introduce `u`,`v` surface coordinates to `hit_record` (#441) - Fix: Add highlight to new `hittable::bounding_box()` method (#442) +### _The Rest of Your Life_ +- Fix: unitialized variable in first version of `integrate_x_sq.cc` +- Fix: remove unreferenced variables in several sample programs +- Fix: correct program computation of the integral of x^2 (#438) + ---------------------------------------------------------------------------------------------------- # v3.0.1 (2020-03-31) diff --git a/books/RayTracingTheRestOfYourLife.html b/books/RayTracingTheRestOfYourLife.html index f4293cf7..304b2ba3 100644 --- a/books/RayTracingTheRestOfYourLife.html +++ b/books/RayTracingTheRestOfYourLife.html @@ -221,16 +221,14 @@ #include int main() { - int inside_circle = 0; - int inside_circle_stratified = 0; int N = 1000000; - double sum; + auto sum = 0.0; for (int i = 0; i < N; i++) { auto x = random_double(0,2); sum += x*x; } std::cout << std::fixed << std::setprecision(12); - std::cout << "I = " << sum/N << '\n'; + std::cout << "I = " << 2 * sum/N << '\n'; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [integ-xsq-1]: [integrate_x_sq.cc] Integrating $x^2$] @@ -406,8 +404,6 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ int main() { - int inside_circle = 0; - int inside_circle_stratified = 0; int N = 1000000; auto sum = 0.0; for (int i = 0; i < N; i++) { @@ -439,8 +435,6 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ int main() { - int inside_circle = 0; - int inside_circle_stratified = 0; int N = 1000000; auto sum = 0.0; for (int i = 0; i < N; i++) { @@ -484,8 +478,6 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ int main() { - int inside_circle = 0; - int inside_circle_stratified = 0; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight int N = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++