That formula comes from the trigonometric identity
tan(A-B) = (tan(A)-tan(B))/(1+tan(A)*tan(B))
Note: You have the sign wrong in atand((m1-m2)/(1-m1*m2))
It should be understood that taking the arctangent (atand) of your expression corresponds to rotating the line with slope m2 in both a counterclockwise and a clockwise direction around the intersection point until first encountering the line with slope m1. Going counterclockwise counts as a positive angle and clockwise is considered negative. Therefore your answer will lie between +90 and -90.