How to get the minimum angle between two crossing lines?

I'm not a student, I'm just a programmer trying to solve a problem ... I just need the practical way to calculate the smallest angle between two lines that intersect. The value, of course, must always be less than or equal to 90 º. For ease, imagine the hands of a clock as line segments, starting from a common vertex at its center. At 12 o'clock we have 0° and 360°, at 3 o'clock we have 90, at 6 o'clock we have 180, at 9 am have 270, ie, the angles range from 0 to 360° clockwise ALWAYS. This is my reference.

Each hour is 30 degrees (360/12), so suppose one of hands is in position 1h and the other one is in position 11h. Using my reference, which always starts at zero from 0 hours (or 12 hours, whichever you prefer) we have:

1h Position is equivalent to 30° 11h position is equivalent to 330°

I know, looking at the clock, the result I hope to find is 60°, however I need a mathematical relationship where I tell two angles starting from the same source and I get as result a value that is the smallest angle by two intersecting lines.

OBS.: I really do not need explanations about lines in Cartesian planes or angular coefficient. I really do not have these informations. What I have are only two angles relative to each other to form imaginary lines and I need only calculate the smallest angle between these lines. Thanks for understanding!

-

Given two angles $\alpha$ and $\beta$ in degrees, the required one would be: $$\gamma=min(|\alpha - \beta|, 360-|\alpha-\beta|)$$

Edit: Seems there is a nicer formula $$\gamma=180 - ||\alpha-\beta|-180|$$

-
Hi gev! Thank you for you answer. I suppose it's close :). In fact this expression works for some tests (angles) but, using my example with the angles being 30 and 330 degrees, we have x = (330 - 30 - 180) mod 180 x = (120) mod 180 x = 120 But the correct answer would be 60 degrees. I'm using the windows calc in scientific mode and doing 120 mod 180. I know the mod operator is the remainder of a integer division. Do you have another way to do this? – Carlos Feitoza Filho Mar 26 '13 at 14:37
Hmm, I think I made an error there. Let me review it. – gev Mar 26 '13 at 14:40
Hi gev! Thank you, but, my math skills are very bad today... The vertical pipe means "absolute value"? If so, I will test it soon! – Carlos Feitoza Filho Mar 26 '13 at 20:34
Right, that's absolute value. – gev Mar 26 '13 at 20:45
Hi Gev, everything is tested! Your answer was choosed as the "more beautiful" between the two answers. The another one was from Kamil and his answer was correct too. Thank you both :) – Carlos Feitoza Filho Mar 27 '13 at 2:02

I would say it's: $$\gamma=min((360-\alpha+\beta) mod 180, (360-\beta+\alpha) mod 180)$$ especially when you're a programmer ;) (so am I ;))

-
Hi Kamil, thanks for the answer! I will test it soon... – Carlos Feitoza Filho Mar 26 '13 at 20:35
Hi Kamil! Your answer is correct, thank you! In fact your sollution is more near to me as programmer, however, the answer from Gev is a little bit more compact and you know how this is important, right?! Thank you so much for this ALSO CORRECT ANSWER! – Carlos Feitoza Filho Mar 27 '13 at 2:00