Bug introduced in 8.0 and fixed in 10.0.0
Just try this example:
lst = {0, 1, 1, Sqrt[2], Sqrt[5], 2 Sqrt[2], 2, Sqrt[13], Sqrt[5], Sqrt[6], Sqrt[11],
Sqrt[14], Sqrt[11], Sqrt[10], 3 Sqrt[2], Sqrt[17], Sqrt[13], 2 Sqrt[5], Sqrt[29],
2 Sqrt[2]};
ex1 = BinCounts[lst, {Range[0, 18]}]
ex2 = BinCounts[lst, {Range[0, 19]}]
ex3 = BinCounts[N@lst, {Range[0, 18]}]
{1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} {1, 3, 6, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} {1, 3, 6, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Seems that BinCounts
failed to notice the irrational numbers in ex1
:
Select[lst, IntegerQ]
(* This result is consistent with ex1. *) {0, 1, 1, 2}
Is it a bug? I'm using Mathematica 8.0.4, Windows Vista 32bit.
BinCounts[lst + $MachineEpsilon, {Range[0, 18]}]
... looks bug-like to me. You can useN
, orLength /@ BinLists[lst, {Range[0, 18]}]
as work-around. $\endgroup$HistogramList[lst, {Range[0, 18]}]
works ok. $\endgroup$BinCounts[{0, 3, Sqrt[2]}, {Range[1, 2]}] -> {0}
$\endgroup$