Your suggestion didn't work for me. I too have the same problem. r through r are zero. I can run the square root function by itself and get the correct answer 181 but when I try the math class I get the error Comparison failure at line 2.
Yeah, I figured! That's why I tried a < (x + 1) instead, but as x was initialized as 32767, it ended up causing an overflow for me. I ended up going with (a - 1) < x instead. Not sure if it's the best solution given that it can underflow also, but it was good enough to pass the tests anyway.