Apress / ray-tracing-gems

Source Code for "Ray Tracing Gems: High-Quality and Real-Time Rendering with DXR and Other APIs" by Eric Haines and Tomas Akenine-Möller

Home Page:https://www.apress.com/us/book/9781484244265

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 15.3 code for sample variance equation - possible bug

fstrugar opened this issue · comments

Hi, very minor thing but I'm looking at http://raytracinggems.com/unofficial_RayTracingGems_v1.7.pdf and the last line code for estimate_sample_variance() seems incorrect.

The code is:

1 float estimate_sample_variance(float samples[], int n) {
2     float sum = 0, sum_sq = 0;
3     for (int i = 0; i < n; ++i) {
4         sum += samples[i];
5         sum_sq += samples[i] * samples[i];
6     }
7     return sum_sq / (n * (n - 1))) -
8     sum * sum / ((n - 1) * n * n);
9 }

in lines 7 & 8 there is an additional ')' but the formula also appears wrong - it should be return sum_sq / (n - 1) - sum * sum / ((n - 1) * n); ( or return (sum_sq - sum * sum / n) / (n - 1); )? (or I might be missing something :) )

Thanks, and we just got the OK to fix this - sorry for the delay. It is now fixed in the repo and will get fixed in the downloadable PDF sometime soon. I've also credited you on the errata page.