Monday, May 2, 2011

my point is floating

This will be, hopefully, the first of a few more technical blog posts. It's grand detailing the minutia of my life but occasionally I need to think through a problem or two, and the results can be interesting.

I'm currently writing an Android app in my spare time. I'll skip the details of what the app does for now, but I'm working with location information (GPS coordinates) and I'm passing around results from the phone to a database.

While converting from numbers to strings (part of the HTTP POST code) it dawned on me that, as previous experience has shown, trying to keep precision in numerical values while they are represented as strings often has issues. I'm writing out a double to a string in Java - that's all good. I can pull that back into the GAE python code as a double - in python, floats are double precision by default. Next question - what precision does the GeoPt GAE datatype honour? the docs simply say "floating point" - is that single precision or double precision? Assuming it's talking about the python type rather than the java type, hopefully it means double precision.

This might sound nit-picky, but given the range of values for longitude (-180.0 through 0 to +180.0) the precision of the number can make the difference between microns and metres in world space.

For single point values, If you're working around the zero line (at the Greenwich royal observatory) then the most precise value is around 2^-127 - a very small number indeed. in decimal, this is equivalent to 10^-38, so given the required precision in decimal degrees , this is so small there's no named SI prefix for it.

If you're on the other side of the world, however, then you're plus or minus 180 degrees, give or take some precision. this gives us a fixed exponent (2^7) and values for the lowest significant bit of the mantissa in the range of 0.000015, give or take - so if you add a single insignificant bit, you're moving your geo point by around 1.5 metres. That's not insignificant.

Doubles add another whole stack of zeros here -it's safe to say you've got at least 10 zeros before your changed value shows up, which is sub-millimetre accuracy - safely inside the tolerance of any real world geo fix, and probably good enough for any spacial positioning work that's trying to correctly locate physical space. So that's good to know!