50g group photo

Yahoo Groups archive

50g

Index last updated: 2026-04-28 22:38 UTC

Thread

Two argument arctan

Two argument arctan

2008-03-02 by tedwingate

I'm looking for a two argument arctan function that works like the
C++/Matlab/Fortran atan2.  The 50 has a atan2 function, but it doesn't
figure out what quadrant the solution should fall in.

Has anyone done it, or am I going to have to code it myself? (You can
feel my excitement with that prospect can't you?)

EKW

Re: Two argument arctan

2008-03-02 by Juan C.


Your hp 50g does not have a function like that, I suggest a code like this:


« R->C ARG »

or if you want:

« -> x y 'ARG(x+i*y)' ->NUM »

Re: Two argument arctan

2008-03-02 by tedwingate

Yea, the problem is that you get negative rotation that way.  I need
the range to be positive full circle from pi/2.  I think I'm just
going to cascade a series of if statements and modify the result of
atan based on the signs of the arguments.

It will not be pretty.

EKW 



--- In 50g@yahoogroups.com, "Juan C." <jcbuchin@...> wrote:
Show quoted textHide quoted text
>
> 
> 
> Your hp 50g does not have a function like that, I suggest a code like
> this:
> 
> 
> 
> 
> « R->C ARG »
> 
> or if you want:
> 
> « -> x y 'ARG(x+i*y)' ->NUM »
>

Re: Two argument arctan

2008-03-02 by Juan C.


In trigonometry, a counterclockwise rotation is positive and that is the way atan2 works, as you can see in this link: http://en.wikipedia.org/wiki/Atan2 . I guess you can modify the function in the way you want. Try this to see if this solve your problem:


« NEG R->C ARG »

or if you want:

« -> x y 'ARG(x-i*y)' ->NUM »

Re: Two argument arctan

2008-03-06 by Tim Wessman

> It will not be pretty.

No that won't be pretty. Use the MOD command.

360 MOD   or     2 PI * MOD

Depending on your needs.

In sysRPL what you want is extreemly easy.

::
  %REC>POL ( x y -> dist ang )
  SWAPDROP
  1REV
  %MOD
;

I will add in some checking to be sure you have two real numbers.

::
  CK2NOLASTWD
  CKREAL
  xSWAP
  CKREAL
  xSWAP
  %REC>POL ( x y -> dist ang )
  xSWAP
  xDROP
  1REV
  xMOD
;

Now I'll replace with sysevals.  This is a userRPL that does exactly
what you want, and function no matter whether you are set in RADIANS,
DEGREES or GRADS.

<<
  #2629Ch
  SYSEVAL
  #36B7Bh
  SYSEVAL
  SWAP
  #36B7Bh
  SYSEVAL
  SWAP
  #30E79h
  SYSEVAL
  SWAP
  DROP
  #2F180h
  SYSEVAL
  MOD
>>  


TW

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.