Fix logic errors in `hist`

Reported in
https://groups.google.com/forum/#!topic/julia-users/VPbQgaz3xgs
Make histrange us the extrema function

And add a simple test for hist()
Merge pull request #6462 from ivarne/hist

Fixed some issues with the hist function