class NumberUtils {

    public static boolean isLikelyDouble(long value) {
        // Check for some common named double values
        // We don't check for Double.MIN_VALUE, which has a long representation of 1
        if (value == canonicalDoubleNaN ||
                value == maxDouble ||
                value == piDouble ||
                value == eDouble) {
            return true;
        }

        // Check for some named long values
        if (value == Long.MAX_VALUE || value == Long.MIN_VALUE) {
            return false;
        }

        // a non-canocical NaN is more likely to be an long
        double doubleValue = Double.longBitsToDouble(value);
        if (Double.isNaN(doubleValue)) {
            return false;
        }

        // Otherwise, whichever has a shorter scientific notation representation is more likely.
        // Long wins the tie
        String asLong = format.format(value);
        String asDouble = format.format(doubleValue);

        // try to strip off any small imprecision near the end of the mantissa
        int decimalPoint = asDouble.indexOf('.');
        int exponent = asDouble.indexOf("E");
        int zeros = asDouble.indexOf("000");
        if (zeros > decimalPoint && zeros < exponent) {
            asDouble = asDouble.substring(0, zeros) + asDouble.substring(exponent);
        } else {
            int nines = asDouble.indexOf("999");
            if (nines > decimalPoint && nines < exponent) {
                asDouble = asDouble.substring(0, nines) + asDouble.substring(exponent);
            }
        }

        return asDouble.length() < asLong.length();
    }

}