elasticsearch/elasticsearch — comment on commit 779dc4309bfb03fe0f1335d5c9e3b06e802ebc70
File:  line 0
By ofavre:

Glad you fixed the bug on `index.mapper.geo.GeoPointFieldMapper` causing infinite loops for lng = -360-180 = -540 (among other) because of the while test comparison being non strict.
However -180 and 180 can still be returned, they should instead be equal to the same value. Idem for -0.0 and 0.0.
Moreover, this implementation can be **very slow** for huge positive or negative values.

I suggest using Java's floating point modulus operation (see [the JLS](http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.17.3))

```java
// Definition: floatingpointModulusCentered(x,d) = y such as y is in ] -d/2 ; d/2 ] and -0.0 becomes 0.0
// Note that -inf, +inf and NaN will yield NaN
// IMPORTANT: divisor is supposed to be a positive value. (A negative won't mess the modulus but will mess with the rest).
public static double floatingpointModulusCentered(double dividend, double divisor) {
double rtn = dividend % divisor; // yield a value between 0 and dividend (or -dividend and 0)
if (rtn <= 0) // get rid of the negative range for the positive one
rtn += divisor;
if (rtn > divisor/2) // transform the positive range to a 0-centered one
rtn -= divisor;
return rtn;
}
```