Your suggestion didn't work for me. I too have the same problem. r[9] through r[13] 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.
Thank you for your reply. It's working now. I had to change my square root program a little bit so it could finish the calculation within the given vm steps (1000000) in the MathTest.TST file.
Replying just in case someone comes here with the same issue I had; Try to do a < x + 1 in place of a <= x, you might end up creating an extra overflow problem which was not anticipated...
Note that a <= x is a syntax error in Jack. All operators are single symbols, which may seem limiting, but your compiler implementation would have been a lot more complicated if that weren't the case.
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.