- for Long values, the conversion from long to double can lead to loss of precision. Eg.

```
SELECT  CAST(ROUND(922337203685477580) AS LONG) as a
```

returns

```
922337203685477632
```

- for floating point values, when the two numbers passed to ROUND() funciton are too big, the values are truncated to Long.MAX_VALUE and hence wrongly rounded. Eg.

```
SELECT  ROUND(100000000000.0, 8) as a
```

returns

```
9.223372036854776E10
```
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/math/BinaryOptionalMathProcessor.java
public enum BinaryOptionalMathOperation implements BiFunction<Number, Number, Number> {
        ROUND((l, r) -> {
            double tenAtScale = Math.pow(10., r.longValue());
            double middleResult = l.doubleValue() * tenAtScale;
            int sign = middleResult > 0 ? 1 : -1;
            return Math.round(Math.abs(middleResult)) / tenAtScale * sign;
        }),
        TRUNCATE((l, r) -> {
            double tenAtScale = Math.pow(10., r.longValue());
            double g = l.doubleValue() * tenAtScale;
            return (((l.doubleValue() < 0) ? Math.ceil(g) : Math.floor(g)) / tenAtScale);
        });
        private final BiFunction<Number, Number, Number> process;
        BinaryOptionalMathOperation(BiFunction<Number, Number, Number> process) {
            this.process = process;
        }
        @Override
        public final Number apply(Number left, Number right) {
            if (left == null) {
                return null;
            }