avoid sqrt of negative number