code: public static Comparable canonicalizeForHashLookup(Comparable value) {
          Class clazz = value.getClass();
          assert value instanceof Number;
  
          Number number = (Number) value;
  
          if (isDoubleRepresentable(clazz)) {
              double doubleValue = number.doubleValue();
              long longValue = number.longValue();
  
              if (equalDoubles(doubleValue, (double) longValue)) {
                  return longValue;
              } else if (clazz == Float.class) {
                  return doubleValue;
              }
          } else if (isLongRepresentableExceptLong(clazz)) {
              return number.longValue();
          }
  
          return value;
      }
docs: Canonicalizes the given {@link Number} value for the purpose of a
  hash-based lookup.
  <p>
  The method accepts a {@link Comparable} instance and returns one because
  query engine acts on comparable values, but {@link Number} is not
  comparable.
  <p>
  Special numeric canonicalization logic is used for {@link Double},
  {@link Long}, {@link Float}, {@link Integer}, {@link Short} and
  {@link Byte}: all whole numbers in the [{@link Long#MIN_VALUE},
  {@link Long#MAX_VALUE}] range are represented as {@link Long}, all other
  whole and non-whole numbers are presented as {@link Double}. That logic
  allows to mix numeric types while performing hash-based lookups, e.g.
  while using one of the standard {@link java.util.Map} implementations.
  
  @param value the {@link Number} to canonicalize.
  @return a canonical representation of the given {@link Number} or
  the original {@link Number} if there is no special canonical
  representation for it.