Skip to content

Commit 41be1a3

Browse files
authored
Merge pull request #461 from RayTracing/1d-mc-integration
Fix error in one dimensional MC integration
2 parents 06b33f6 + b7a2b0f commit 41be1a3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Change Log -- Ray Tracing in One Weekend
1717
- Fix: Introduce `u`,`v` surface coordinates to `hit_record` (#441)
1818
- Fix: Add highlight to new `hittable::bounding_box()` method (#442)
1919

20+
### _The Rest of Your Life_
21+
- Fix: unitialized variable in first version of `integrate_x_sq.cc`
22+
- Fix: remove unreferenced variables in several sample programs
23+
- Fix: correct program computation of the integral of x^2 (#438)
24+
2025

2126
----------------------------------------------------------------------------------------------------
2227
# v3.0.1 (2020-03-31)

books/RayTracingTheRestOfYourLife.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,14 @@
221221
#include <stdlib.h>
222222

223223
int main() {
224-
int inside_circle = 0;
225-
int inside_circle_stratified = 0;
226224
int N = 1000000;
227-
double sum;
225+
auto sum = 0.0;
228226
for (int i = 0; i < N; i++) {
229227
auto x = random_double(0,2);
230228
sum += x*x;
231229
}
232230
std::cout << std::fixed << std::setprecision(12);
233-
std::cout << "I = " << sum/N << '\n';
231+
std::cout << "I = " << 2 * sum/N << '\n';
234232
}
235233
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
236234
[Listing [integ-xsq-1]: <kbd>[integrate_x_sq.cc]</kbd> Integrating $x^2$]
@@ -406,8 +404,6 @@
406404
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
407405

408406
int main() {
409-
int inside_circle = 0;
410-
int inside_circle_stratified = 0;
411407
int N = 1000000;
412408
auto sum = 0.0;
413409
for (int i = 0; i < N; i++) {
@@ -439,8 +435,6 @@
439435
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
440436

441437
int main() {
442-
int inside_circle = 0;
443-
int inside_circle_stratified = 0;
444438
int N = 1000000;
445439
auto sum = 0.0;
446440
for (int i = 0; i < N; i++) {
@@ -484,8 +478,6 @@
484478
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
485479

486480
int main() {
487-
int inside_circle = 0;
488-
int inside_circle_stratified = 0;
489481
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
490482
int N = 1;
491483
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++

0 commit comments

Comments
 (0)