Post Reply 
ArcTan(x,y)?
04-09-2017, 09:54 PM (This post was last modified: 04-09-2017 09:58 PM by StephenG1CMZ.)
Post: #26
RE: ArcTan(x,y)?
I have put together a little program to illustrate the relative timings of the various methods.
Some of the timings can be improved, but it gives an idea.
The printouts seem to be in duration order, quickest first, although sometimes that can change on the Android (presumably because the phone is taking cycles).

Code:


 LOCAL XY:=0.0001;
 LOCAL II;
 LOCAL KK:=1000;

 
 ATANS(XY)
 BEGIN
  RETURN ATAN(XY/XY);
 END;

 ATANSIMPLECALL(XY)
 BEGIN
  FOR II FROM 1 TO KK DO
   U:=ATANS(XY);
  END;
  RETURN U;
 END;

 ATANYX(YY,XX)
  BEGIN
  IF YY==0 AND XX==0 THEN
   RETURN 0;
  END;
  RETURN ARG(XX+*YY);
  END;
 


 ATANYXCALL(YY,XX)
 BEGIN
  FOR II FROM 1 TO KK DO
   U:=ATANYX(YY,XX);
  END;
  RETURN U;
 END;


arctanxy(x, y)
begin
  local a;
  if x == 0 then
    if y == 0 then
      a := 0;
    else
      a := sign(y) * pi / 2
    end;
  else
    a := atan(y / x);
    if x < 0 then
      if y < 0 then
        a := a - pi;
      else
        a := a + pi;
      end;
    end;
  end;

  return a;

end;
 
 ATANPCALL(XX,YY)
 BEGIN
  FOR II FROM 1 TO KK DO
   U:=arctanxy(XX,YY);
  END;
  RETURN U;
 END;

 ARGZ(XX,YY) 
 BEGIN
  RETURN ARG(XX+*YY);
 END;
 
 ARGZCALL(XX,YY) 
 BEGIN
  FOR II FROM 1 TO KK DO
   U:=ARGZ(XX,YY);
  END;
  RETURN U;
 END;

 PC(XX,YY)
 BEGIN
  RETURN polar_coordinates(XX+YY*);
 END;

 PCCALL(XX,YY)
 BEGIN
  LOCAL TMP;
  FOR II FROM 1 TO KK DO
   TMP:=PC(XX,YY);
  END;
  RETURN TMP[2];
 END;

 EXPORT TN() 
 BEGIN
  LOCAL RR;
  LOCAL SP:="      ";

  PRINT();
  PRINT(KK +" LOOPS");

  //SIMPLE ATAN:QUADRANT IGNORANT
  PRINT("ATAN1: "+TEVAL(RR:=ATANSIMPLECALL(XY))+SP+RR);
  
  //CALL ARG:MAY FAIL IF YOUR COMPILERS ARG DOESNT DO 0
  PRINT("ARG: "+TEVAL(RR:=ARGZCALL(XY,XY))+SP+RR);
 
  //CALL USER ATAN (USING ARG) HANDLING 0
  PRINT("ATAN(ARG):"+TEVAL(RR:=ATANYXCALL(XY,XY))+SP+RR);
  
  //CALL USER ATAN (PORTABLE) HANDLING 0
  //WORKS ON PLATFORMS WITHOUT ARG
  PRINT("ATAN(Portable):"+TEVAL(RR:=ATANPCALL(XY,XY))+SP+RR);

  //CALL coordinates:FAIL IF GLOBAL
  PRINT("polar : "+TEVAL(RR:=PCCALL(XY,XY))+SP+RR); 
  END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
ArcTan(x,y)? - toml_12953 - 04-05-2017, 12:07 PM
RE: ArcTan(x,y)? - Joe Horn - 04-05-2017, 12:20 PM
RE: ArcTan(x,y)? - toml_12953 - 04-05-2017, 12:26 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017, 03:00 PM
RE: ArcTan(x,y)? - toml_12953 - 04-05-2017, 03:39 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017, 06:22 PM
RE: ArcTan(x,y)? - KeithB - 04-05-2017, 07:28 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017, 07:47 PM
RE: ArcTan(x,y)? - KeithB - 04-05-2017, 10:47 PM
RE: ArcTan(x,y)? - DrD - 04-06-2017, 10:27 AM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-06-2017, 03:22 PM
RE: ArcTan(x,y)? - KeithB - 04-05-2017, 07:33 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017, 07:53 PM
RE: ArcTan(x,y)? - KeithB - 04-05-2017, 08:10 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017, 09:17 PM
RE: ArcTan(x,y)? - jte - 04-05-2017, 09:08 PM
RE: ArcTan(x,y)? - KeithB - 04-05-2017, 09:42 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017, 10:38 PM
RE: ArcTan(x,y)? - KeithB - 04-05-2017, 10:41 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-06-2017, 03:30 PM
RE: ArcTan(x,y)? - Han - 04-06-2017, 03:53 PM
RE: ArcTan(x,y)? - JMB - 04-09-2017, 09:50 AM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-09-2017, 03:47 PM
RE: ArcTan(x,y)? - JMB - 04-09-2017, 08:00 PM
RE: ArcTan(x,y)? - KeithB - 04-06-2017, 02:38 PM
RE: ArcTan(x,y)? - StephenG1CMZ - 04-09-2017 09:54 PM



User(s) browsing this thread: 1 Guest(s)