Encoder Logic Q

I’m using this encoder library and started with one of the samples:

http://www.pjrc.com/teensy/td_libs_Encoder.html

After moving my encoder to pins without interrupt and setting no interrupts, the following logic failed:

newPosition = myEnc.read();
  if (newPosition != oldPosition) {
...

However, the following works instead:

newPosition = myEnc.read();
  if (newPosition > oldPosition || newPosition < oldPosition) {
...

Don’t those two conditions mean the same thing?

No they don't mean the same thing use paper and pen to work out the difference.

Mark

The variables are longs

Under what condition will they not evaluate the same?

old = 1
new = 2

2 != 1
true

2 > 1 or 2 < 1
true

old = 2
new = 1

1 != 2
true

1 > 2 or 1 < 2
true

My pen and paper skills might be rusty because I still cannot figure it out.

I can at least print the values of new and old positions to get a clue.

And it seems if (newPosition != oldPosition) is not true, then (newPosition == oldPosition) must be true.