Hi Faeries - A Stats issue
-
- Posts: 180
- Joined: 09 December 04 3:30 pm
- Location: Wyoming
Hi Faeries - A Stats issue
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.
Thanks in advance.
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.
Thanks in advance.
- caughtatwork
- Posts: 17017
- Joined: 17 May 04 12:11 pm
- Location: Melbourne
- Contact:
Re: Hi Faeries - A Stats issue
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!
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!
Re: Hi Faeries - A Stats issue
It was fun translating that sentence.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!
... Except I now think that maybe I didn't ...
- caughtatwork
- Posts: 17017
- Joined: 17 May 04 12:11 pm
- Location: Melbourne
- Contact:
Re: Hi Faeries - A Stats issue
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:
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
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;
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
-
- Posts: 180
- Joined: 09 December 04 3:30 pm
- Location: Wyoming
Re: Hi Faeries - A Stats issue
Thanks for the prompt response. Only another (about) half to go.
Re: Hi Faeries - A Stats issue
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
Cheers
Captain (barely Lance Corporal currently) Numbers