besides the ASM code, in the pascal version of arctan2 (here shown) I think is not well written, but I can be wrong
function arctan2(y,x : float) : float;
begin
if (x=0) then
begin
if y=0 then
arctan2:=0.0
else if y>0 then
arctan2:=pi/2
else if y<0 then <- this "if" it is uncessary, already checked Y=0 and Y>0
arctan2:=-pi/2;
end
else
ArcTan2:=ArcTan(y/x);
if x<0.0 then <- this part of code is excuted also on the result of "if X=0 then".. that is not necessary, it should be only in the else part within a "Begin..End"
ArcTan2:=ArcTan2+pi;
if ArcTan2>pi then
ArcTan2:=ArcTan2-2*pi;
end;
here my version
function MyArcTan2(Y, X : double) : double;
begin
if (X = 0) then begin
if (Y = 0) then
Result:=0
else
if (Y > 0) then
Result:=0.5*pi
else
Result:=-0.5*pi
end
else begin
Result:=ArcTan(Y/X);
if (X < 0) then
if (Y < 0) then
Result:=Result-pi
else
Result:=Result+pi
end;
end;
@Kays: yes the ASM code I showed works ! useful or not I have still to check...
@BobDog : not tested... but at least in the fragment of your code below, I can say that you never reach the row n.5 in case y=0 being filtered by row n.1 (PS: you make me crazy having swapped X<->Y as usually intended...)
If (y=0) Then exit (Sgn(x)*pi/2);
k:=1;
If ((Sgn(y)=1) Or (Sgn(y)=0)) Then k:=0 ;
k:=k*Sgn(x) ;
If ((x=0) And (y=0)) Then exit(0.0);
@PascalDragon
sorry for my ignorance by why the code below compile
function PartArcTan2(Y, X: double): double;
begin
{$ASMMODE intel}
asm
movq [rsp-8], xmm0
movq [rsp-16], xmm1
fld qword ptr [rsp-8]
fld qword ptr [rsp-16]
fpatan
fwait
fstp qword ptr [rsp-8]
movq xmm0, [rsp-8]
end;
end;
..and the code from Kays and Winni does not compile (compiler message "un reconignized op code FLDT or FLD", in my ASM version I have FLD op code !)
thanks for the help to everybody