Functions min, max, atan2, step
In some cases, a circuit simulator or computer language lacks a function for the minimum or maximum of two numbers. If there is no "if statement" conditional available, the following formulas have been helpful.
MIN( a, b ) = 0.5* ( a + b ) - 0.5* abs( a - b )
MAX( a, b ) = 0.5* ( a + b ) + 0.5* abs( a - b )
Similarly, when the arctangent function alone is insufficient, and the two arguement function atan2 is desired the following formula is helpful.
Atan2( y, x ) = 2* atan( y / ( x + sqrt( x*x + y*y ) ) )
The above Atan2 formula is based on the half-angle identity: tan ( theta /2 ) = sin( theta ) / ( 1 + cos( theta ) ). The formula fails for theta = pi where the denominator is zero.
Wikipedia on Atan2 here .