PDA

View Full Version : magnitude from complex



hcrisp
09-01-2010, 12:36 PM
I am converting variable data types and trying to be consistent. I noticed that the ABS() function always returns a DOUBLE for complex data even when the input is COMPLEX, not DOUBLE COMPLEX. This is explicitly stated in the help. I am just curious -- what is the reason why?



WAVE> info, ABS(FLOAT(-2.))
<Expression> FLOAT = 2.00000
WAVE> info, ABS(DOUBLE(-2.))
<Expression> DOUBLE = 2.0000000
WAVE> info, ABS(COMPLEX(-2.,3.))
<Expression> DOUBLE = 3.6055513
; I would have expected a FLOAT!
WAVE> info, ABS(DCOMPLEX(-2.,3.))
<Expression> DOUBLE = 3.6055513

rwagner
09-03-2010, 04:00 PM
Hcrisp, My understanding of why we chose to implement the ABS function this way is that it involves some processing (roots and exponents which benefit from the greater precision of the double datatype) as opposed to just stripping the sign off the input variable. It should be easy enough to cast the output back to a float if you need to.-Ryan

hcrisp
09-08-2010, 08:03 PM
I guess that makes sense, though the fact that the result wasn't automatically downcast to Float by ABS before it was returned made me wonder if there was a reason it should not be. Thanks for the help.