### Question:
Numbers { @Contract(value = "!null -> !null; null -> null", pure = true) public static Number convertNumberSmartly(final BigDecimal decimal) { if (decimal == null) return null; if (decimal.equals(Numbers.DECIMAL_ZERO)) return BYTE_ZERO; final int precision = decimal.precision(); final int scale = decimal.scale(); Number num; if (scale == 0) { try { if (precision <= 19 && decimal.compareTo(Numbers.DECIMAL_MIN_LONG) >= 0 && decimal.compareTo(Numbers.DECIMAL_MAX_LONG) <= 0) { long v = decimal.longValueExact(); if (-128 <= v && v <= 127) num = (byte) v; else if (-32768 <= v && v <= 32767) num = (short) v; else if (Integer.MIN_VALUE <= v && v <= Integer.MAX_VALUE) num = (int) v; else num = v; } else { num = decimal.toBigIntegerExact(); } } catch (ArithmeticException ae) { num = decimal; } } else { if (precision <= 6) { num = decimal.floatValue(); } else if (precision <= 15) { num = decimal.doubleValue(); } else { num = decimal; } } return num; }  static boolean valuesAreEqual(@Nullable final Number x, @Nullable final Number y); @SuppressWarnings("unchecked") @Contract(value = "_,!null -> !null; _,null -> null", pure = true) static N convertNumber(final Class<N> numberClass, final Number number); @Contract(value = "!null -> !null; null -> null", pure = true) static Number convertNumberSmartly(final BigDecimal decimal); static int parseIntSafe(@Nullable final String str); static long parseLongSafe(@Nullable final String str); static final Byte BYTE_ZERO; static final BigDecimal DECIMAL_ZERO; static final BigDecimal DECIMAL_MIN_LONG; static final BigDecimal DECIMAL_MAX_LONG; }### Answer:
@TestWithParams(params = "CONVERT_SMART_CASES") public void convertNumberSmartly_basic(Number origin) { BigDecimal d = new BigDecimal(origin.toString()); Number num = convertNumberSmartly(d); assertThat(num).isEqualTo(origin); }