Re: fractional powers of negative numbers? [message #8809] |
Mon, 28 April 1997 00:00 |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
Jack Saba <jsaba@magus.stx.com> writes:
> IDL is computing -(5.^1.51) in your example. If you try (-5.)^1.51, you
> will get an error.
> Med Bennett wrote:
>>
>> Can someone explain this to me? Is it possible to compute the fractional
>> power of a negative number? IDL does it on single negative values but
>> not on arrays containing negative values.
>>
>> IDL> print,findgen(11)-5
>> -5.00000 -4.00000 -3.00000 -2.00000
>> -1.00000 0.000000 1.00000 2.00000
>> 3.00000 4.00000 5.00000
>> IDL> print,(findgen(11)-5)^1.51
>> -1.#IND0 -1.#IND0 -1.#IND0 -1.#IND0
>> -1.#IND0 0.000000 1.00000 2.84810
>> 5.25355 8.11168 11.3617
>> % Program caused arithmetic error: Floating illegal operand
>> IDL> print,-2.^1.51
>> -2.84810
>> IDL> print,-5.^1.51
>> -11.3617
The only way to compute the fractional power of a negative number is to use
complex arithmetic, e.g.
IDL> print,complex(findgen(11)-5,fltarr(11))
( -5.00000, 0.00000)( -4.00000, 0.00000)
( -3.00000, 0.00000)( -2.00000, 0.00000)
( -1.00000, 0.00000)( 0.00000, 0.00000)
( 1.00000, 0.00000)( 2.00000, 0.00000)
( 3.00000, 0.00000)( 4.00000, 0.00000)
( 5.00000, 0.00000)
IDL> print,(complex(findgen(11)-5,fltarr(11)))^1.51
% Program caused arithmetic error: Floating overflow
% Detected at $MAIN$
% Program caused arithmetic error: Floating illegal operand
% Detected at $MAIN$
% Program caused arithmetic error: Floating illegal operand
% Detected at $MAIN$
( 0.356881, -11.3561)( 0.254794, -8.10767)
( 0.165018, -5.25096)( 0.0894611, -2.84669)
( 0.0314108, -0.999507)( NaNQ, NaNQ)
( 1.00000, 0.00000)( 2.84810, 0.00000)
( 5.25355, 0.00000)( 8.11168, 0.00000)
( 11.3617, 0.00000)
Interestingly enough, here it complains about taking (0,0) to a fractional
power. I would have said that (0,0) to any power was still (0,0).
Bill Thompson
|
|
|
Re: fractional powers of negative numbers? [message #8810 is a reply to message #8809] |
Mon, 28 April 1997 00:00  |
Jack Saba
Messages: 30 Registered: January 1996
|
Member |
|
|
IDL is computing -(5.^1.51) in your example. If you try (-5.)^1.51, you
will get an error.
Med Bennett wrote:
>
> Can someone explain this to me? Is it possible to compute the fractional
> power of a negative number? IDL does it on single negative values but
> not on arrays containing negative values.
>
> IDL> print,findgen(11)-5
> -5.00000 -4.00000 -3.00000 -2.00000
> -1.00000 0.000000 1.00000 2.00000
> 3.00000 4.00000 5.00000
> IDL> print,(findgen(11)-5)^1.51
> -1.#IND0 -1.#IND0 -1.#IND0 -1.#IND0
> -1.#IND0 0.000000 1.00000 2.84810
> 5.25355 8.11168 11.3617
> % Program caused arithmetic error: Floating illegal operand
> IDL> print,-2.^1.51
> -2.84810
> IDL> print,-5.^1.51
> -11.3617
>
> Med Bennett
> bennettm@boulder.pti-enviro.com
|
|
|
|