Algorithm Math Delphi

Title: How to find true angle of a vector or complex number (Arctan)
function ArcTan2(x, y: Double): Double;
var
retur: Double;
begin
Retur := 0.0;
if ABS(x) 0.000000001 then //Close to zero! We declare it to be zero!
begin //The small margin gives a slight error, but improves reliability.
if y 0 then
begin
Retur := PI / 2; //90 degrees
end
else
begin
Retur := PI / (-2); //-90 degrees
end;
end
else
begin
if x 0 then // 1. or 4. quadrant
begin
Retur := ArcTan(Y / X); // Easy stuff. Normal ArcTan is valid for 1. and 4.
end
else // 2. or 3. quadrant
begin
Retur := PI - ArcTan(-Y / X);
end;
end;
ArcTan2 := Retur;
end;