sumOfLog2s

Compute the sum of binary logarithms of the input range r. The error of this method is much smaller than with a naive sum of log2.

Unqual!(DeepElementType!Range)
sumOfLog2s
(
Range
)
(
Range r
)
if (
isFloatingPoint!(DeepElementType!Range)
)

Examples

alias isNaN = x => x != x;

assert(sumOfLog2s(new double[0]) == 0);
assert(sumOfLog2s([0.0L]) == -real.infinity);
assert(sumOfLog2s([-0.0L]) == -real.infinity);
assert(sumOfLog2s([2.0L]) == 1);
assert(isNaN(sumOfLog2s([-2.0L])));
assert(isNaN(sumOfLog2s([real.nan])));
assert(isNaN(sumOfLog2s([-real.nan])));
assert(sumOfLog2s([real.infinity]) == real.infinity);
assert(isNaN(sumOfLog2s([-real.infinity])));
assert(sumOfLog2s([ 0.25, 0.25, 0.25, 0.125 ]) == -9);

Meta