Change in ATAN Behavior
QUESTION: Yikes! Did the behavior of ATAN change recently? In IDL 5.4 I could do this:
IDL> Print, ATAN(Complex(4,4)) 0.785398
When I try this in IDL 5.6, I get this:
IDL> Print, ATAN(Complex(4,4)) (1.44452, 0.123674)
To make it print correctly, I have to use the new Phase keyword in IDL 5.6:
IDL> Print, ATAN(Complex(4,4), /Phase) 0.785398
That's not exactly backward compatible, is it? How do I handle this in my code so that it can work in multiple versions of IDL?
ANSWER: Oh, dear. This behavior actually changed in IDL 5.5, where you have this result:
IDL> Print, ATAN(Complex(4,4)) (1.44452, 0.123674) IDL> Print, ATAN(Complex(4,4), /Phase) % Keyword PHASE not allowed in call to: ATAN IDL> Print, ATAN(4,4) 0.785398
In practice, this means that you have to write three different ATAN calls for the three different versions of IDL to get the same results.
You might have to write something like this to keep things compatible.
FUNCTION ATAN_COMPLEX_WRAPPER, complexNum On_Error, 2 ; Argument must be complex or double complex. s = Size(complexNum) numType = s(s(0) + 1) CASE numType OF 6L: BEGIN realpart = Float(complexNum) imgpart = Imaginary(complexNum) END 9L: BEGIN realpart = Double(complexNum) imgpart = Imaginary(complexNum) END ELSE: Message, 'Argument must be a complex number.' ENDCASE ; For versions 5.5 and lower, use two-value ATAN call. Have to ; execute 5.6 version to get it to compile in IDL 5.4 and lower. returnValue = 0.0 version = Float(!VERSION.Release) IF(version LE 5.5) THEN returnValue = ATAN(imgpart, realpart) $ ELSE returnValue = Call_Function('ATAN', complexNum, /Phase) RETURN, returnValue END
Copyright © 1997-2003 David W. Fanning
Last Updated 27 February 2003