# Weird typo leads to interesting result... what does it mean?

Printable View

• 06-16-2010
pollypocket4eva
Weird typo leads to interesting result... what does it mean?
Hi,
While writing some C++ code, I made a typo, which produced a bizarre but in interesting result in program. However, I completely do not understand what it is doing. Can anyone make sense of this?

Code:

```int a; // This can be any number from 0..255 int b; // This can be any number from 0..255 if(abs(a-b<2))     return true; return false;```
I wrote it as a typo, but it is having an effect I can't otherwise duplicate. Can anyone understand this?
Thanks
• 06-16-2010
MK27
Quote:

Originally Posted by pollypocket4eva
I wrote it as a typo

You wrote what as a typo?

1) that code
2) some part of that code
3) some other part of that code
4) your post
• 06-16-2010
pollypocket4eva
The typo was:
if(abs(a-b<2))
instead of:
if(abs(a-b)<2)

Within the context of a much larger program, it's having a funny effect. But I was just wondering if anyone could help me understand what this line does.
• 06-16-2010
MK27
Quote:

Originally Posted by pollypocket4eva
it's having a funny effect.

This "funny effect" is:

1) ha-ha, ROFL funny
2) kind of strange funny
3) just plain funny!
4) indescribably funny

I'm being serious, BTW. You will get a quicker answer to your questions if you make some attempt to include relevant information.

However, as a clue, this:
Code:

`(a-b<2)`
will yield either 0 or 1, regardless of the value of a & b.
• 06-17-2010
CodeMonkey
Code:

`abs(a-b<2)`
1 if (a-b)<2, 0 otherwise.
Code:

`abs(a-b)<2`
1 if abs(a-b)<2, 0 otherwise.

abs(1) is 1, and abs(0) is 0.