Fix rare panic in Sobol sampler.

Due to the undefined behavior of shifting a number by its
bit-width, the Sobol sampler would panic when sample index
`1 << 15` was requested.

This fixes it without introducing any additional checks or
operations.
This commit is contained in:
Nathan Vegdahl 2020-03-19 09:59:19 +09:00
parent 7daa133e15
commit e014df2b1a

View File

@ -92,7 +92,8 @@ fn sobol_u32(dimension: u32, index: u32) -> u32 {
let j = index.trailing_zeros();
result ^= vecs[(i + j) as usize];
i += j + 1;
index >>= j + 1;
index >>= j;
index >>= 1;
}
(result as u32) << 16