What is the approximate resolution of a single point floating point number when it is around zero

I store a lot of longitude and latitude as doubles , I wonder if I can leave by saving them as floats .

To answer this question, I need to know the approximate single-precision floating-point resolution when the stored values ​​are longitude / latitude (-180 to +180).

+7
source share
4 answers

There may be several interpretations in your question.

If it's just for corners and for storage on disk or on a device, I suggest you store your values ​​using a completely different technique: store as a 32-bit integer.

 int encodedAngle = (int)(value * (0x7FFFFFFF / 180.0)); 

To restore it, do the opposite.

 double angle = (encodedAngle / (0x7FFFFFFF / 180.0)); 

So you have full 31-bit resolution for 180 degrees and 1 bit for sign.

You can use this method to save your values ​​in ram, the cost of this coversion is higher than working directly with doubling, but if you want your memory to be low but with high resolution, this can work very well. The cost is not so high, just converting to / from an integer from / to double and multiplying, modern processors will do this in a very short time, and since the available memory is less, if the list contains a lot of value, your code will be more friendly with the processor cache .

Your resolution will be 180 / ((2^31) - 1) = 8.38190318 Γ— 10^-8 degrees, not bad :)

+12
source

The resolution that you can count on with swimming with one precision is about 360 / (2 ^ 23) or 4 * 10 ^ -5.

More precisely, the largest floating single-point limit is strictly below 360. (which accurately seems to be accurate) is about 359.999969 . For the entire range -360. .. 360 -360. .. 360 you can imagine the differences, at least as small as the difference between the two numbers.

+5
source

Typically, floats are 4 bytes (32 bits), and doubles are double. However, accurate precision, if you do the calculations, is the implementation (and the hardware). On some systems, all floats will be stored as doubles, just to add to the confusion.

+1
source

Depends, but rather not.

32-bit float stores 7 significant digits. This is usually too small to hold the correct longitude / latitude resolution. For example, openstreetmap.org uses six decimal places, so a minimum of eight, a maximum of only ten digits.

In short, use float64.

0
source

All Articles