[PATCH] Fix roundToOsmPrecision() accuracy
|Reported by:||mrwojo||Owned by:||team|
Currently, LatLon.roundToOsmPrecision(double) fails to pass checks in LatLonTest.roundingTest() due to rounding issues noted in roundToOsmPrecision(). This patch should address the accuracy issues by simply inverting the operations (multiply by 1e7 instead of divide by 1e-7 etc.). Errors creep in when dividing and multiplying by 1e-7 because that value cannot be represented accurately in standard floating point.
This should make roundToOsmPrecision(double) pass all the tests in LatLonTest.roundingTest() without affecting performance. It even passes tests with small input values, like:
assertEquals(LatLon.roundToOsmPrecision(0.02345678), 0.0234568, 0);
(roundToOsmPrecisionStrict(double) leaves more than 7 digits of precision in near-zero values.)
Since it passes the rounding tests (and more), it could make roundToOsmPrecisionStrict(double) redundant.