Page 1 of 1

Just a little mathematic question

PostPosted: Wed Mar 28, 2012 11:23 am
by lcl
So, is there a simpler way to check if value is between two values than:
Code: Select all
if (value >= -10 && value <= 10)

Where 'value' is the changing value and - 10 and 10 are the limits which I want to check it being in between of.
I'm trying to find a shorter way to write it but I can't come up with anything.

I think there must be some easy solution which I just can't figure out right now.
Thanks in advance! =)

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 3:14 pm
by DST
Code: Select all
if (abs(value)<10)

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 3:41 pm
by SuperSonic
DST beat me to it ^^

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 3:56 pm
by lcl
Oh, thanks, that's way too easy :lol:

But how about when the limiters are not opposite numbers?

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 4:21 pm
by SuperSonic
In that case, I think you'd have to use the long method :)

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 4:39 pm
by lcl
Yeah..maybe
I just think to have seen something similar to what DST offered in a way I need it.
I think it was some code of skydereigns.
But it might be that I remember wrong. :P

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 7:07 pm
by Game A Gogo
SuperSonic wrote:In that case, I think you'd have to use the long method :)


if(abs(value-((max+min)/2)))<=max-((max+min)/2))

so if your max is 10 and minimum is -6

if(abs(value-2)<=8)

Re: Just a little mathematic question

PostPosted: Wed Mar 28, 2012 8:33 pm
by lcl
Thanks GaG! =D