Mark A Matte
markamatte at hotmail.com
Thu Aug 23 17:07:08 CDT 2012
Thanks All, The problem I am having for these coordinates...is CosArc DOES = 1...or at least says it does when I step through the code...but the IF statement still goes to the ELSE. So...if CosArc says its 1...but really is not...how do I tell what the real value is??? Latitude1 = Radians(41.70900431)Longitude1 = Radians(-83.585444)Latitude2 = Radians(41.7090043053031)Longitude2 = Radians(-83.5854439996183) > From: stuart at lexacorp.com.pg > To: accessd at databaseadvisors.com > Date: Fri, 24 Aug 2012 07:33:09 +1000 > Subject: Re: [AccessD] Weird problem with lat/long distance function > > I agree with Lambert. You need to specify an acceptable "margin of error" > > Consider that each of the four variables in the following calculation is itself the result of > floating poiint calculations using an approximation of PI (how you derive this approximation > and how accurate it is is not shown) > > CosArc = (Sin(Latitude1) * Sin(Latitude2)) + _ > (Cos(Latitude1) * Cos(Latitude2) * Cos(Longitude1 - Longitude2)) > > Because of rounding errors in the multiple floating point calculations involved and the > approximation of PI, it is extremenly unlikely that this will ever return exactly 1. > > Computers can be very precise without being very accurate. > > -- > Stuart > > On 23 Aug 2012 at 14:34, Heenan, Lambert wrote: > > > Random email client sabotage of code caused that I guess. > > > > Mark, > > > > Your problem line is > > > > If Abs(CosArc) = 1 Then > > > > As you state. As we are talking about floating point math here I would immediately thing that the issue is one of precision. > > > > You are checking if the returned value is 1.0, but that is likely never going to be the exact result because its FP math. I think you will need to define a tolerance that is "close enough" to the target value. Something like > > > > CONST Tolerance =0.000000001 > > > > If Abs((Abs(CosArc) - 1)) <= Tolerance Then... > > > > Lambert > > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com