Test coverage improvement

Added a whole bunch of tests, fixed some docs and edge cases.
Does this need to be here at all? It seems like the cost of the comparison and possible jump would be slower than the call to sqrt, and it makes the code more complicated (as evidenced by having the correction).