LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 1997, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 3 Mar 1997 14:47:40 -0500
Reply-To:     "Zuckier, Gerald" <Zuckier@CHIME.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         "Zuckier, Gerald" <Zuckier@CHIME.ORG>
Subject:      Re: Negative Cubic Roots
Content-Type: text/plain; charset="us-ascii"

Oops, that last one got away from me. Sorry. Anyway, didn't this come up on SAS-L a few months ago, or something similar? In general, a number raised to the 1/x will have x roots, equally spaced rotationally around the real and imaginary number axes. The easy thing to do is just require the operand to be a positive real number and throw away all the roots except the one that also falls on the positive real number axis, but that's not really correct. If you know you are going to use an odd root (1/3, 1/5, etc.) you can kluge around it slightly by separating the sign and the absolute value, i.e. >cuberoot = sign(cube)*(abs(cube)) ** (1/3); You still are only getting one root, so it's not really correct, but at least it won't crash and will give you an answer. That's probably what most people are looking for, most of the time, rather than some complex root.

>---------- >From: Mark Covello[SMTP:Mark.Covello@BARRA.COM] >Sent: Monday, March 03, 1997 11:13 AM >To: Multiple recipients of list SAS-L >Subject: Negative Cubic Roots > >---------------------- Information from the mail header >----------------------- >Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> >Poster: Mark Covello <Mark.Covello@BARRA.COM> >Organization: Barra >Subject: Negative Cubic Roots >------------------------------------------------------------------------ >------- > >I was surprised by the following this weekend: > > >145 DATA _NULL_; >146 cube = -27; >147 cuberoot = cube ** (1/3); >148 PUT _ALL_; >149 RUN; > >NOTE: Invalid argument(s) to the exponential >operator "**" at line 147 column 17. >CUBE=-27 CUBEROOT=. _ERROR_=1 _N_=1 >CUBE=-27 CUBEROOT=. _ERROR_=1 _N_=1 >NOTE: Mathematical operations could not be >performed at the following places. The results of >the operations have been set to > missing values. > >I checked the SAS language reference to see if it >mentioned that negative numbers could not be raised >to fractional exponents, but found nothing. > >I tried the same thing on my WIN3.1 version of >MS Excel and got an error as well. Today I tried >it on the NT version of Excel and it resolved to >-3. > >Can someone explain to me the algorithm that >creates this error. > >Does Microsoft overwrite the error for >specific values of the exponent? > > >I would also be interested to know how most >people handle this in their code. something like: > > IF cube < 0 THEN mult = -1; > else mult = 1; > cuberoot = mult * ((mult*cube) ** (1/3)); > >??? > >I was really amazed that I don't remember ever >running into this (seemingly basic) problem before. > > >Thanks for your input, > >Mark > > > > >-- >*************************************************** >***** >Mark S. Covello >Programming Consultant >current assigment: > Barra > Berkeley, California > >The views expressed in this post do not necessarily >represent the views of Barra. > >"If one (member of Congress) had been there when > the deity was on the point of saying, > 'Let there be light,' > we never would have had it." > > Mark Twain > >*************************************************** >***** >


Back to: Top of message | Previous page | Main SAS-L page