# Strange behavior of BinCounts

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.

• Same result in 9.0.1. Odd behavior indeed; seems hard to justify it as anything other than a bug... Commented May 20, 2014 at 10:25
• Try BinCounts[lst + \$MachineEpsilon, {Range[0, 18]}]... looks bug-like to me. You can use N, or Length /@ BinLists[lst, {Range[0, 18]}] as work-around.
– ciao
Commented May 20, 2014 at 10:26
• same result in OSX v9.0.1
– gpap
Commented May 20, 2014 at 10:36
• But HistogramList[lst, {Range[0, 18]}] works ok. Commented May 20, 2014 at 10:37
• minimal example: BinCounts[{0, 3, Sqrt[2]}, {Range[1, 2]}] -> {0}  Commented May 20, 2014 at 19:58