[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Re: Old Question*From*: thompson(at)orpheus.nascom.nasa.gov (William Thompson)*Date*: 15 Dec 1999 16:49:50 GMT*Newsgroups*: comp.lang.idl-pvwave*Organization*: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA*References*: <825pe3$ic9$1@pegasus.csx.cam.ac.uk> <3856FE95.B66C4961@tidewater.net>*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:17744

Ben Tupper <pemaquidriver@tidewater.net> writes: >Jacques Basson wrote: >> Hi all >> >> Sorry, this has got to be an old question, but I can't seem to locate >> the answer. What is the way around the following problem? >> >> IDL> a = -1 >> IDL> print, -1^(1./3) >> -1.00000 >> IDL> print, a^(1./3) >> NaN >> % Program caused arithmetic error: Floating illegal operand >> >> Thanks >> Jacques Um, I don't know if you realize this, but the only reason that the first example DOESN'T fail is because IDL> print, -1^(1./3) is equivalent to IDL> print, -( 1^(1./3)) In other words, the minus sign doesn't come into play until after the exponentiation is applied. If you typed in IDL> print, (-1)^(1./3) you'd get the NaN result, with the error message, as above. Note that you can test this by typing in IDL> print, -1^2, -(1^2), (-1)^2 -1 -1 1 Of course, as is implied by the answer below, the proper way to evaluate your example would be IDL> a = -1 IDL> print, a^complex(1./3, 0) ( 0.500000, 0.866025) William Thompson >Hello, >I now know why it happens. In the documentation I see... >Exponentiation >The caret (^) is the exponentiation operator. A^B is equal to A raised to >the B power. >* If A is a real number and B is of integer type, repeated multiplication >is applied. >* If A is real and B is real (non-integer), the formula A^B = e^(B ln A) >is evaluated. >* If A is complex and B is real, the formula A^B = (re^(iq))^B = r^B * >(cosBq + isinBq) (where r is the real part of A and iq is the imaginary >part) is evaluated. >* B is complex, the formula A^B = e^(B ln A) is evaluated. If A is >also complex, the natural logarithm is computed to be ln(A) = ln(re^(iq)) >= ln(r) + iq (where r is the real part of A and iq is the imaginary >part). >* A^0 is defined as 1. >Your example falls into the second type of operation. I don't know how >to get around that but would like to know also. >Ben >-- >Ben Tupper >Pemaquid River Company >248 Lower Round Pond Road >POB 106 >Bristol, ME 04539 >Tel: (207) 563-1048 >Email: PemaquidRiver@tidewater.net

**Follow-Ups**:**Re: Old Question***From:*Jacques Basson

**References**:**Re: Old Question***From:*Ben Tupper

- Prev by Date:
**Re: Old Question** - Next by Date:
**Re: Another Color Twist** - Prev by thread:
**Re: Old Question** - Next by thread:
**Re: Old Question** - Index(es):