reinterpret_cast to safer static_cast
better precision in evaluation of log weight, one fewer multiply per iteration
if statement to improve timing for linear weighting case