PROCEDURE Polar(z: ComplexTyp; VAR r, phi: float);
BEGIN
r := ComplexAbs(z);
IF r <> 0 // r > 0 should be enough
THEN IF Abs(Im(z) / r) = 1
THEN phi := Pi / 2 * (Im(z) / r) / Abs(Im(z) / r) // why not just Im(z)/Abs(z) or sign(Im(z))
ELSE phi := ArcTan(Im(z) / Re(z)) //you can stay here even with Re(z) < 0
ELSE
BEGIN
phi := 0;
IF Re(z) < 0 //if you stay here r=0 so how is it possible that Re(z) < 0 ?
THEN
IF Im(z) <> 0 //if you stay here r=0 so how is it possible that Im(z) <> 0 ?
THEN phi := phi + Pi * Abs(Im(z)) / Im(z)
ELSE phi := Pi;
END;
END;