public static int formatFloatFast(float value, int maxFractionDigits, byte[] asciiBuffer)
    {
        if (Float.isNaN(value) ||
                Float.isInfinite(value) ||
                value > Long.MAX_VALUE ||
                value <= Long.MIN_VALUE ||
                maxFractionDigits > MAX_FRACTION_DIGITS)
        {
            return -1;
        }

        int offset = 0;
        long integerPart = (long) value;

        //handle sign
        if (value < 0)
        {
            asciiBuffer[offset++] = '-';
            integerPart = -integerPart;
        }
        
        //extract fraction part 
        long fractionPart = (long) ((Math.abs((double)value) - integerPart) * POWER_OF_TENS[maxFractionDigits] + 0.5d);
        
        //Check for rounding to next integer
        if (fractionPart >= POWER_OF_TENS[maxFractionDigits]) {
            integerPart++;
            fractionPart -= POWER_OF_TENS[maxFractionDigits];
        }

        //format integer part
        offset = formatPositiveNumber(integerPart, getExponent(integerPart), false, asciiBuffer, offset);
        
        if (fractionPart > 0 && maxFractionDigits > 0)
        {
            asciiBuffer[offset++] = '.';
            offset = formatPositiveNumber(fractionPart, maxFractionDigits - 1, true, asciiBuffer, offset);
        }

        return offset;
    }
@Test
    void testFormatOfRealValuesReturnsMinusOneIfItCannotBeFormatted()
    {
        assertEquals(-1, NumberFormatUtil.formatFloatFast(Float.NaN, 5, buffer),
                "NaN should not be formattable");
        assertEquals(-1, NumberFormatUtil.formatFloatFast(Float.POSITIVE_INFINITY, 5, buffer),
                "+Infinity should not be formattable");
        assertEquals(-1, NumberFormatUtil.formatFloatFast(Float.NEGATIVE_INFINITY, 5, buffer),
                "-Infinity should not be formattable");
        assertEquals(-1, NumberFormatUtil.formatFloatFast(((float) Long.MAX_VALUE) + 1000000000000f,
                5, buffer), "Too big number should not be formattable");
        assertEquals(-1, NumberFormatUtil.formatFloatFast(Long.MIN_VALUE, 5, buffer),
                "Too big negative number should not be formattable");
    }