about summary refs log tree commit diff
path: root/src/rt/sync/rust_thread.cpp
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-10-31 23:27:26 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2013-10-31 23:49:39 +1100
commit1e2283de433f6a3dff85b8d16ad741f37651eb81 (patch)
tree86068d1c1c29a2d59a0b1f98b5f5383bdacdd0e2 /src/rt/sync/rust_thread.cpp
parenta0e6e0e9b7bc468b9e31d22c6f82a391ad7ba90a (diff)
downloadrust-1e2283de433f6a3dff85b8d16ad741f37651eb81.tar.gz
rust-1e2283de433f6a3dff85b8d16ad741f37651eb81.zip
std::rand: correct an off-by-one in the Ziggurat code.
The code was using (in the notation of Doornik 2005) `f(x_{i+1}) -
f(x_{i+2})` rather than `f(x_i) - f(x_{i+1})`. This corrects that, and
removes the F_DIFF tables which caused this problem in the first place.

They `F_DIFF` tables are a micro-optimisation (in theory, they could
easily be a micro-pessimisation): that `if` gets hit about 1% of the
time for Exp/Normal, and the rest of the condition involves RNG calls
and a floating point `exp`, so it is unlikely that saving a single FP
subtraction will be very useful (especially as more tables means more
memory reads and higher cache pressure, as well as taking up space in
the binary (although only ~2k in this case)).

Closes #10084. Notably, unlike that issue suggests, this wasn't a
problem with the Exp tables. It affected Normal too, but since it is
symmetric, there was no bias in the mean (as the bias was equal on the
positive and negative sides and so cancelled out) but it was visible as
a variance slightly lower than it should be.
Diffstat (limited to 'src/rt/sync/rust_thread.cpp')
0 files changed, 0 insertions, 0 deletions