Package ch.randelshofer.fastdoubleparser
Class AbstractJavaFloatingPointBitsFromCharSequence
java.lang.Object
ch.randelshofer.fastdoubleparser.AbstractNumberParser
ch.randelshofer.fastdoubleparser.AbstractFloatValueParser
ch.randelshofer.fastdoubleparser.AbstractJavaFloatingPointBitsFromCharSequence
- Direct Known Subclasses:
JavaDoubleBitsFromCharSequence,JavaFloatBitsFromCharSequence
Parses a Java
FloatingPointLiteral from a CharSequence.
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 Summary
Fields inherited from class ch.randelshofer.fastdoubleparser.AbstractFloatValueParser
MAX_EXPONENT_NUMBER, MAX_INPUT_LENGTH, MINIMAL_NINETEEN_DIGIT_INTEGERFields inherited from class ch.randelshofer.fastdoubleparser.AbstractNumberParser
CHAR_TO_HEX_MAP, DECIMAL_POINT_CLASS, ILLEGAL_OFFSET_OR_ILLEGAL_LENGTH, OTHER_CLASS, SYNTAX_ERROR, SYNTAX_ERROR_BITS, VALUE_EXCEEDS_LIMITS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) abstract longnan()(package private) abstract longprivate longparseDecFloatLiteral(CharSequence str, int index, int startIndex, int endIndex, boolean isNegative) Parses aDecimalFloatingPointLiteralproduction with optional trailing white space until the end of the text.final longparseFloatingPointLiteral(CharSequence str, int offset, int length) Parses aFloatingPointLiteralproduction with optional leading and trailing white space.private longparseHexFloatLiteral(CharSequence str, int index, int startIndex, int endIndex, boolean isNegative) Parses the following rules (more rules are defined inAbstractFloatValueParser): RestOfHexFloatingPointLiteral: RestOfHexSignificand BinaryExponent RestOfHexSignificand: HexDigits HexDigits.[HexDigits].HexDigitsprivate longparseNaNOrInfinity(CharSequence str, int index, int endIndex, boolean isNegative) (package private) abstract longprivate static intskipWhitespace(CharSequence str, int index, int endIndex) Skips optional white space in the provided string(package private) abstract longvalueOfFloatLiteral(CharSequence 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.(package private) abstract longvalueOfHexLiteral(CharSequence 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.Methods inherited from class ch.randelshofer.fastdoubleparser.AbstractNumberParser
charAt, charAt, charAt, checkBounds, checkBounds, lookupHex, lookupHex
-
Constructor Details
-
AbstractJavaFloatingPointBitsFromCharSequence
AbstractJavaFloatingPointBitsFromCharSequence()
-
-
Method Details
-
skipWhitespace
Skips optional white space in the provided string- Parameters:
str- a stringindex- start index (inclusive) of the optional white spaceendIndex- 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(CharSequence str, int index, int startIndex, int endIndex, boolean isNegative) Parses aDecimalFloatingPointLiteralproduction with optional trailing white space until the end of the text. Given that we have already consumed the optional leading zero of theDecSignificand.
See- DecimalFloatingPointLiteralWithWhiteSpace:
- DecimalFloatingPointLiteral [WhiteSpace] EOT
JavaDoubleParserfor the grammar ofDecimalFloatingPointLiteralandDecSignificand.- Parameters:
str- a stringindex- the current indexstartIndex- start index inclusive of theDecimalFloatingPointLiteralWithWhiteSpaceendIndex- 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
Parses aFloatingPointLiteralproduction with optional leading and trailing white space.
See- FloatingPointLiteralWithWhiteSpace:
- [WhiteSpace] FloatingPointLiteral [WhiteSpace]
JavaDoubleParserfor the grammar ofFloatingPointLiteral.- Parameters:
str- a string containing aFloatingPointLiteralWithWhiteSpaceoffset- start offset ofFloatingPointLiteralWithWhiteSpaceinstrlength- length ofFloatingPointLiteralWithWhiteSpaceinstr- Returns:
- the bit pattern of the parsed value, if the input is legal;
otherwise,
-1L.
-
parseHexFloatLiteral
private long parseHexFloatLiteral(CharSequence str, int index, int startIndex, int endIndex, boolean isNegative) Parses the following rules (more rules are defined inAbstractFloatValueParser):- RestOfHexFloatingPointLiteral:
- RestOfHexSignificand BinaryExponent
- RestOfHexSignificand:
- HexDigits
- HexDigits
.- [HexDigits]
.HexDigits - HexDigits
- Parameters:
str- the input stringindex- index to the first character of RestOfHexFloatingPointLiteralstartIndex- the start index of the stringendIndex- the end index of the stringisNegative- if the resulting number is negative- Returns:
- the bit pattern of the parsed value, if the input is legal;
otherwise,
-1L.
-
parseNaNOrInfinity
-
positiveInfinity
abstract long positiveInfinity()- Returns:
- a positive infinity constant in the specialized type wrapped in a
long
-
valueOfFloatLiteral
abstract long valueOfFloatLiteral(CharSequence 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 stringendIndex- the end index (exclusive) of the float literal inside the stringisNegative- whether the float value is negativesignificand- the significand of the float value (can be truncated)exponent- the exponent of the float valueisSignificandTruncated- whether the significand is truncatedexponentOfTruncatedSignificand- 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(CharSequence 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 stringendIndex- the end index (exclusive) of the float literal inside the stringisNegative- whether the float value is negativesignificand- the significand of the float value (can be truncated)exponent- the exponent of the float valueisSignificandTruncated- whether the significand is truncatedexponentOfTruncatedSignificand- the exponent value of the truncated significand- Returns:
- the bit pattern of the parsed value, if the input is legal;
otherwise,
-1L.
-