expr atan / cartopol

Roman Thilenius's icon

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

Bas van der Graaff's icon
Roman Thilenius's icon

nope. :)

499.110.cartopol
cartopol
andrea agostini's icon

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

Roman Thilenius's icon

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 :)

Bas van der Graaff's icon

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!