Add some println's to debug and see what might be negative - this should lead you back to the culprit. You will see one of your variables becomes negative as it gets larger, and the following is a...