title: proper/best type for storing latitude and longitude
body: <p>In a system level programming language like C, C++ or D, what is the best type/encoding for storing latitude and longitude?</p>
  
  <p>The options I see are:</p>
  
  <ul>
  <li>IEEE-754 FP as degrees or radians</li>
  <li>degrees or radians stored as a fixed point value in an 32 or 64 bit int</li>
  <li>mapping of an integer range to the degree range: -> <code>deg = (360/2^32)*val</code></li>
  <li>degrees, minutes, seconds and fractional seconds stored as bit fields in an int</li>
  <li>a struct of some kind.</li>
  </ul>
  
  <p>The easy solution (FP) has the major down side that it has highly non uniform resolution (somewhere in England it can measure in microns, over in Japan, it can't). Also this has all the issues of FP comparison and whatnot. The other options require extra effort in different parts of the data's life cycle. (generation, presentation, calculations etc.)</p>
  
  <p>One interesting option is a floating precision type that where as the Latitude increase it gets more bits and the Longitude gets less (as they get closer together towards the poles).</p>
  
  <p>Related questions that don't quite cover this:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/159255/">What is the ideal data type to use when storing latitude / longitudes in a MySQL</a></li>
  <li><a href="https://stackoverflow.com/questions/120283/">Working with latitude/longitude values in Java</a></li>
  </ul>
  
  <hr>
  
  <p>BTW: 32 bits gives you an E/W resolution at the equator of about 0.3 in. This is close to the scale that high grade GPS setups can work at (IIRC they can get down to about 0.5 in in some modes).</p>
  
  <p>OTOH if the 32 bits is uniformly distributed over the earth's surface, you can index squares of about 344m on a side, 5 Bytes give 21m, 6B->1.3m and 8B->5mm.</p>
  
  <p>I don't have a specific use in mind right now but have worked with this kind of thing before and expect to again, at some point.</p>