FUNCTION "ATAN2" : Real
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
Y : Real;
X : Real;
END_VAR
VAR_TEMP
Z : Real;
del : Real;
END_VAR
VAR CONSTANT
PI : Real := 3.141593;
END_VAR
BEGIN
IF #X = 0 THEN
#Z := 0;
ELSE
#Z := #Y / #X;
END_IF;
#del := ATAN_REAL(IN := #Z);
IF #X > 0 THEN
#ATAN2 := #del;
ELSIF #Y >= 0 AND #X < 0 THEN
#ATAN2 := #del + #PI;
ELSIF #Y < 0 AND #X < 0 THEN
#ATAN2 := #del - #PI;
ELSIF #Y > 0 AND #X = 0 THEN
#ATAN2 := #PI / 2;
ELSIF #Y < 0 AND #X = 0 THEN
#ATAN2 := -1 * #PI / 2;
ELSE
#ATAN2 := 0;
END_IF;
END_FUNCTION