expr atan / cartopol

May 3, 2010 at 2:27pm

expr atan / cartopol

guten morgen,

i am trying to replace [cartopol] with [expr sqrt(($f1*$f1)+($f2*$f2))] and [expr atan($f2/$f1)]

when the real input is negative and the imaginary input is 0 (i.e. no argument to cartopol)
it should give pi, but it gives -0.

wtf? did i use the atan function wrong somehow?

-110

#50149
May 3, 2010 at 2:48pm
#180051
May 3, 2010 at 3:08pm

nope. :)

Attachments:
  1. 110.cartopol
#180052
May 3, 2010 at 3:16pm

if $f2 is 0, in principle atan has no way to know if $f1 is > or < 0.

to achieve what you’re looking for, you should either set up some conditions to manage signs and 0s, or use atan2 instead.

aa

#180053
May 4, 2010 at 4:47am

ok will try both .. i am not really sure what atan2() actually does …

managing signs … i have no idea … .. abs() wont help much to get the
same output than from cartopol :)

#180054
May 4, 2010 at 9:11am

I had to look up what atan2 actually does too…but that’s awesome, never knew it was so common. That would have saved me some stupid ifs in Java as well. Works like a charm, thanks!

#180055

You must be logged in to reply to this topic.