Shop OBEX P1 Docs P2 Docs Learn Events
check for "within range" — Parallax Forums

check for "within range"

jcfergusonjcferguson Posts: 86
edited 2007-04-05 04:17 in BASIC Stamp
Hi All,

is there an easy way to check if a variable is within a range of another variable? so for example I want to check to see if x is within 10 of y. Would I use:

if abs (x-y) > 10 then
do something
else
don't do something.

?

Thanks

Carlos Ferguson

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-05 03:54
    You've got it. The only time this won't work is if the values are widely different (more than 15 bits difference) in which case you might run into problems with the limited word size in comparing them. It doesn't sound like this is the case here.
  • jcfergusonjcferguson Posts: 86
    edited 2007-04-05 04:17
    Thanks Mike.

    Carlos
Sign In or Register to comment.