Results from UP-UX Universe 10.1 01 RUN PT TEST VAR1 = 0.26983554628015 VAR2 = 0 VAR3 = 0.73016445371985 VAR4 = 1 Program "TEST": Line 19, Argument domain error in arc-cosine, zero returned.
On 4/13/05, Mike Dallaire <[EMAIL PROTECTED]> wrote: > Adrian, > ACOS is the inverse value of COS. At any point when COS equates to 0, ACOS > will be undefined, as it would be 1/0. When calculating distances (assuming > east-west being your x axis and north-south being your y axis), COS would > always be 0 when there is no east or west vector involved (the distance > traveled east or west is 0, or the sum of the vectors is 0, depending upon > your calculation) > Adding the null character may fool the processor into not seeing the value > as 0, I am not sure. However, anytime you are using trigonometric functions > you need to take into account values where they can be undefined. SIN and > COS are the only functions defined for all values, IIRC. > HTH, > Mike > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Womack, Adrian > Sent: Wednesday, April 13, 2005 4:55 AM > To: u2-users@listserver.u2ug.org > Subject: [U2] [UV] ACOS problem (floating point numbers) > > We have some code that is calculating distances between points, using > SIN(), COS() and ACOS(). > > Occasionally we get the error: "Argument domain error in arc-cosine, > zero returned" > > This seems to be occurring when two floating point numbers are added > together and the result is exactly 1 (or at least seems to be exactly > 1), I assume internally the number is slightly over 1. > > Here's some example code: > > PRECISION 14 > > FROM.LAT = -31.295833333 > FROM.LONG = 119.651944444 > DEST.LAT = -31.295833333 > DEST.LONG = 119.651944444 > > VAR1 = SIN(FROM.LAT) * SIN(DEST.LAT) > VAR2 = (DEST.LONG - FROM.LONG) > VAR3 = COS(FROM.LAT) * COS(DEST.LAT) * COS(VAR2) > > VAR4 = VAR1 + VAR3 > > CRT "VAR1 = ":VAR1 > CRT "VAR2 = ":VAR2 > CRT "VAR3 = ":VAR3 > CRT "VAR4 = ":VAR4 > > TEMP1 = ACOS(VAR4) > TEMP2 = ACOS(VAR4:"") > > VAR4 is displayed as "1", but when TEMP1 is assigned we get the above > error message. > When TEMP2 is assigned we get no error (i.e. the temporary variable > passed to the second ACOS function was a string not a number). > > Maybe concatenating an empty string during the ACOS() call is the fix > for this but it's not really ideal. > > Anyone have any comments on this? And what happens on your machine? > > BTW our widezero config setting is 3dc00000 > > AdrianW > > DISCLAIMER: > Disclaimer. This e-mail is private and confidential. If you are not the > intended recipient, please advise us by return e-mail immediately, and > delete the e-mail and any attachments without using or disclosing the > contents in any way. The views expressed in this e-mail are those of the > author, and do not represent those of this company unless this is clearly > indicated. You should scan this e-mail and any attachments for viruses. This > company accepts no liability for any direct or indirect damage or loss > resulting from the use of any attachments to this e-mail. > ------- > u2-users mailing list > u2-users@listserver.u2ug.org > To unsubscribe please visit http://listserver.u2ug.org/ > ------- > u2-users mailing list > u2-users@listserver.u2ug.org > To unsubscribe please visit http://listserver.u2ug.org/ ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/