Hi Faeries - A Stats issue

Discussion about the Geocaching Australia web site
Post Reply
Wyoming Wombats
Posts: 180
Joined: 09 December 04 3:30 pm
Location: Wyoming

Hi Faeries - A Stats issue

Post by Wyoming Wombats » 12 December 11 4:53 pm

Having recently come back from a short European trip, I was interested to see how far I had got towards the moon. It appears that my finds have all been for nought as:-
My average distance between attempted caches is 0.
My total distance between attempted caches is 0.

Any idea what has happened as other stats appear to be OK (furthest west, north,etc).
Just a question for when the faeries are bored and with nothing else to do. :mrgreen: :mrgreen:

Thanks in advance.

User avatar
caughtatwork
Posts: 17017
Joined: 17 May 04 12:11 pm
Location: Melbourne
Contact:

Re: Hi Faeries - A Stats issue

Post by caughtatwork » 12 December 11 5:48 pm

Your faerie had nothing to do before dinner so all is now fixed.
http://geocaching.com.au/cacher/statist ... ts/general
http://geocaching.com.au/cacher/Wyoming ... th_to_moon

Weirdness, just weirdness was happening in the distance calculations where we ended up with an acos(1) which is NaN. So I've put in a fix. Well done, you're the first one to hit that bug in, oh, for eva!

User avatar
SamCarter
1400 or more caches found
1400 or more caches found
Posts: 650
Joined: 13 March 07 10:32 am
Location: Hobart

Re: Hi Faeries - A Stats issue

Post by SamCarter » 12 December 11 11:35 pm

caughtatwork wrote: Weirdness, just weirdness was happening in the distance calculations where we ended up with an acos(1) which is NaN. So I've put in a fix. Well done, you're the first one to hit that bug in, oh, for eva!
It was fun translating that sentence.

... Except I now think that maybe I didn't ... :-k

User avatar
caughtatwork
Posts: 17017
Joined: 17 May 04 12:11 pm
Location: Melbourne
Contact:

Re: Hi Faeries - A Stats issue

Post by caughtatwork » 13 December 11 8:39 am

Hello Captain Numbers.

Let me explain a little more.
In order to calculate distance we do a great circle arc calculation based on the lat/lon of one cache to the lat/lon of another cache.

This is the forumla we use:

Code: Select all

acos(cos($lat1)*cos($lon1)*cos($lat2)*cos($lon2) + 
				 cos($lat1)*sin($lon1)*cos($lat2)*sin($lon2) +
				 sin($lat1)*sin($lat2)
		 		) * $earth_radius;
As you know (of all people), an acos (arccosine) can only be used on a value between -1 and 1 which will return a value between 0 and pi(). (I hope I got that right).

For a reason not to be explored too deeply, the calculation which is being used to determine the value input to the acos() function was showing up as 1 when I display it, but the acos() function was returning NaN. NaN is geek terminology for Not a Number.

I have a sneaking suspicion that there is a floating point error with the length on the decimals in use in the calculation so it was attempting to acos() a value that looked like 1, but was probably somewhat, only, marginally larger than 1.

So when the final acos() function was called, it failed due to the 1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 (or some such weirdness).

So when in doubt, handle the exception. I now check for the acos() function to determine whether it has returned a valid number or NaN. If it's NaN I assume it to be 0 and the function now happily continues on its way.

In all the years of the distance calculator being used at GCA, this has never happened before, so it's a rarity (and therefore weird).

Thank you for your attention. We now return you to the non geek portion of the show.
c@w

Wyoming Wombats
Posts: 180
Joined: 09 December 04 3:30 pm
Location: Wyoming

Re: Hi Faeries - A Stats issue

Post by Wyoming Wombats » 13 December 11 8:58 am

Thanks for the prompt response. Only another (about) half to go.

User avatar
SamCarter
1400 or more caches found
1400 or more caches found
Posts: 650
Joined: 13 March 07 10:32 am
Location: Hobart

Re: Hi Faeries - A Stats issue

Post by SamCarter » 13 December 11 9:26 am

Thanks c@w. I'd successfully hypothesised the meaning of NaN before going back to think more carefully about acos(1). Since my brain is total mush at the moment, it took me a moment or two to realise that acos(1) really IS okay and shouldn't have been NaN which then made me doubt my translation of NaN ... and/or my interpretation of acos ... and/or my general sanity. In my heart of hearts I am a pure mathematician, so 1 should always be 1, even when lost in the bowels of a computer, but I WILL concede that some really froopy maths is involved with numerical approximations. (Sorry for rehijacking the thread).

Cheers
Captain (barely Lance Corporal currently) Numbers

Post Reply