emantos / simplelatlng

Automatically exported from code.google.com/p/simplelatlng
0 stars 0 forks source link

Biased loss of precision on internal lat lng representation #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
GeoConfig - doubleToLong: long cast will always floor the result leading to 
potentially unbounded cumulative errors.

Suggestion: use Math.round() instead

Original issue reported on code.google.com by mark.c.s...@gmail.com on 3 Mar 2015 at 9:27

GoogleCodeExporter commented 8 years ago
Given that floating point numbers are lossy by design, I'm not yet convinced 
that performing a round in the doubleToLong conversion will do much to protect 
users from cumulative errors. Gaining more control over the possibility of 
numerical errors would, I believe, necessitate using BigDecimal for internal 
representation. I did try that implementation once but found it to be a massive 
trade-off both in terms of memory storage and in execution speed of common 
calculations.

In short: SimpleLatLng knowingly sacrifices mathematical accuracy for speed.

With that said, I would love to consider an example case, if you could please 
provide one, which demonstrates the unbounded cumulative errors you're worried 
about.

Original comment by TylerCo...@gmail.com on 5 Mar 2015 at 6:19