Class AbstractJavaFloatingPointBitsFromCharArray

  • Direct Known Subclasses:
    JavaDoubleBitsFromCharArray, JavaFloatBitsFromCharArray

    abstract class AbstractJavaFloatingPointBitsFromCharArray
    extends AbstractFloatValueParser
    Parses a Java FloatingPointLiteral from a char array.

    This class should have a type parameter for the return value of its parse methods. Unfortunately Java does not support type parameters for primitive types. As a workaround we use long. A long has enough bits to fit a double value or a float value.

    See JavaDoubleParser for the grammar of FloatingPointLiteral.

    • Field Detail

      • CONDITIONAL_COMPILATION_PARSE_EIGHT_HEX_DIGITS

        private static final boolean CONDITIONAL_COMPILATION_PARSE_EIGHT_HEX_DIGITS
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractJavaFloatingPointBitsFromCharArray

        AbstractJavaFloatingPointBitsFromCharArray()
    • Method Detail

      • skipWhitespace

        private static int skipWhitespace​(char[] str,
                                          int index,
                                          int endIndex)
        Skips optional white space in the provided string
        Parameters:
        str - a string
        index - start index (inclusive) of the optional white space
        endIndex - end index (exclusive) of the optional white space
        Returns:
        index after the optional white space
      • nan

        abstract long nan()
        Returns:
        a NaN constant in the specialized type wrapped in a long
      • negativeInfinity

        abstract long negativeInfinity()
        Returns:
        a negative infinity constant in the specialized type wrapped in a long
      • parseDecFloatLiteral

        private long parseDecFloatLiteral​(char[] str,
                                          int index,
                                          int startIndex,
                                          int endIndex,
                                          boolean isNegative)
        Parses a DecimalFloatingPointLiteral production with optional trailing white space until the end of the text. Given that we have already consumed the optional leading zero of the DecSignificand.
        DecimalFloatingPointLiteralWithWhiteSpace:
        DecimalFloatingPointLiteral [WhiteSpace] EOT
        See JavaDoubleParser for the grammar of DecimalFloatingPointLiteral and DecSignificand.
        Parameters:
        str - a string
        index - the current index
        startIndex - start index inclusive of the DecimalFloatingPointLiteralWithWhiteSpace
        endIndex - end index (exclusive)
        isNegative - true if the float value is negative
        Returns:
        the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
      • parseFloatingPointLiteral

        public long parseFloatingPointLiteral​(char[] str,
                                              int offset,
                                              int length)
        Parses a FloatingPointLiteral production with optional leading and trailing white space.
        FloatingPointLiteralWithWhiteSpace:
        [WhiteSpace] FloatingPointLiteral [WhiteSpace]
        See JavaDoubleParser for the grammar of FloatingPointLiteral.
        Parameters:
        str - a string containing a FloatingPointLiteralWithWhiteSpace
        offset - start offset of FloatingPointLiteralWithWhiteSpace in str
        length - length of FloatingPointLiteralWithWhiteSpace in str
        Returns:
        the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
      • parseHexFloatLiteral

        private long parseHexFloatLiteral​(char[] str,
                                          int index,
                                          int startIndex,
                                          int endIndex,
                                          boolean isNegative)
        Parses the following rules (more rules are defined in AbstractFloatValueParser):
        RestOfHexFloatingPointLiteral:
        RestOfHexSignificand BinaryExponent
        RestOfHexSignificand:
        HexDigits
        HexDigits .
        [HexDigits] . HexDigits
        Parameters:
        str - the input string
        index - index to the first character of RestOfHexFloatingPointLiteral
        startIndex - the start index of the string
        endIndex - the end index of the string
        isNegative - if the resulting number is negative
        Returns:
        the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
      • parseNaNOrInfinity

        private long parseNaNOrInfinity​(char[] str,
                                        int index,
                                        int endIndex,
                                        boolean isNegative)
      • positiveInfinity

        abstract long positiveInfinity()
        Returns:
        a positive infinity constant in the specialized type wrapped in a long
      • tryToParseEightHexDigits

        private long tryToParseEightHexDigits​(char[] str,
                                              int offset)
      • valueOfFloatLiteral

        abstract long valueOfFloatLiteral​(char[] str,
                                          int startIndex,
                                          int endIndex,
                                          boolean isNegative,
                                          long significand,
                                          int exponent,
                                          boolean isSignificandTruncated,
                                          int exponentOfTruncatedSignificand)
        Computes a float value from the given components of a decimal float literal.
        Parameters:
        str - the string that contains the float literal (and maybe more)
        startIndex - the start index (inclusive) of the float literal inside the string
        endIndex - the end index (exclusive) of the float literal inside the string
        isNegative - whether the float value is negative
        significand - the significand of the float value (can be truncated)
        exponent - the exponent of the float value
        isSignificandTruncated - whether the significand is truncated
        exponentOfTruncatedSignificand - the exponent value of the truncated significand
        Returns:
        the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
      • valueOfHexLiteral

        abstract long valueOfHexLiteral​(char[] str,
                                        int startIndex,
                                        int endIndex,
                                        boolean isNegative,
                                        long significand,
                                        int exponent,
                                        boolean isSignificandTruncated,
                                        int exponentOfTruncatedSignificand)
        Computes a float value from the given components of a hexadecimal float literal.
        Parameters:
        str - the string that contains the float literal (and maybe more)
        startIndex - the start index (inclusive) of the float literal inside the string
        endIndex - the end index (exclusive) of the float literal inside the string
        isNegative - whether the float value is negative
        significand - the significand of the float value (can be truncated)
        exponent - the exponent of the float value
        isSignificandTruncated - whether the significand is truncated
        exponentOfTruncatedSignificand - the exponent value of the truncated significand
        Returns:
        the bit pattern of the parsed value, if the input is legal; otherwise, -1L.