public static Number downCast(double value) {
    Number retVal;

    if (value % 1 == 0) {
      retVal = downCast((long) value);
    } else {
      if (value <= Float.MAX_VALUE && value >= Float.MIN_VALUE) {
        retVal = (float) value;
      } else {
        retVal = value;
      }
    }

    return retVal;
  }
Abstract Aggregator class providing support for down casting the result.
geode-core/src/main/java/org/apache/geode/cache/query/internal/aggregate/AbstractAggregator.java