# Comparison failure at line 2

13 messages
Open this post in threaded view
|

## Comparison failure at line 2

 This post was updated on . I cannot figure out what could go wrong with the comparison in the following lines of Jack code : var int i; let i = 0; while (i < 16) {     ....     let i = i + 1; } However I get "Comparison failure at line 2" ???????
Open this post in threaded view
|

## Re: Comparison failure at line 2

 Administrator You've given virtually nothing to go on. What did YOUR output produce? Where did it fail to match the comparison file? You have 14 tests, which ones did it pass and which ones did it fail? We are NOT mind readers!
Open this post in threaded view
|

## Re: Comparison failure at line 2

 I have only tested the first module: Math. This is the MathTest.out : |RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]| |       6 |    -180 |  -18000 |  -18000 |       0 |       3 |   -3000 |       0 |       3 |       0 |       0 |       0 |       0 |       0 | and this is MathTest.cmp : |RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]| |       6 |    -180 |  -18000 |  -18000 |       0 |       3 |   -3000 |       0 |       3 |     181 |     123 |     123 |      27 |   32767 |
Open this post in threaded view
|

## Re: Comparison failure at line 2

 Administrator So you can see that your code is putting zero in locations 8009 through 8013 (i.e., r[9] through r[13]). Looking at the Main.jack code, we can see that these lines are:         let r[9] = Math.sqrt(32767);       // 181                 let r[10] = Math.min(345, 123);    // 123         let r[11] = Math.max(123, -345);   // 123         let r[12] = Math.abs(27);          // 27         let r[13] = Math.abs(-32767);      // 32767   It's a bit interesting that it's the last five that are wrong, especially since you got r[8], Math.sqrt(9), correct. I'd recommending first just moving the last five lines up in the .jack file to just after where r is set to 8000 and see if you get the same results.
Open this post in threaded view
|

## Re: Comparison failure at line 2

 Ok : solved .Thanks for the help   I had indeed to be more careful about the edge case sqrt(32767).
Open this post in threaded view
|

## Re: Comparison failure at line 2

 In reply to this post by WBahn 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.
Open this post in threaded view
|

## Re: Comparison failure at line 2

 Administrator As was the case above, I'm not a mind reader. Please post the relevant portion of your .cmp and .out files and let's see what they tell us.
Open this post in threaded view
|

## Re: 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.
Open this post in threaded view
|

## Re: Comparison failure at line 2

 Administrator Sure thing. When you get it changed that might make your problem go away. If not, post the contents of those files and we'll take a look.
Open this post in threaded view
|

## Re: Comparison failure at line 2

 In reply to this post by jfmolderez 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...
Open this post in threaded view
|

## Re: Comparison failure at line 2

 Administrator 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.