ID:271451
 
I'm no math wiz. In fact, I barely know anything about maths, and that's why I need help. :-/

How would I go about creating a proc(correct wording?) in which, when given the value 20, would equal 0, and when given anything larger than 20 would equal -(value-20)?

Keep in mind I can't use any if statements here, only plain(aka headache) math.

edit: Uh, sorry if this sounds confusing(it sure did to me!), perhaps I better explain myself in code?

I need to create a proc that returns the same result such as:
proc/a(x)
if(x <= 20) x = (-20+x)
else x = -(x-20)
return x


But without the if()s and else()s.

edit2: see [link]
Ummm... -(x-20)?

-(x-20)=0 for x=20

That expands to 20-x.
In response to Jp
Oh, whoops! Sorry, I rewrote the post and forgot to add that part. Formula should result in -20 when x = 0. So, -(x-20)=0 for x=20, but -(x-20)!=-20 when x=0...
In response to DivineO'peanut
So you have a function f(x) such that:

f(0)=-20
f(20)=0
f(x) = 20-x, x>20


I don't think there's any such function, I'm afraid, short of taking the cheaty route and defining it as the sum of multiple functions that only apply over parts of the domain.

The first part of the function is f(x)=x-20, the second part is 20-x. That means: (x-20)*sgn(20-x) would do, where sgn(x)=-1 if x<0, 0 if x=0, 1 if x>0. But there's no way of doing that without an if. (x/abs(x) fails at x=0).
In response to Jp
Damn, that's a shame. Well, thanks for your help anyway!