Include <limits> and refine comparing.

Include <limits>. I forgot include because Mac OS can compile without include it.