Package ch.randelshofer.fastdoubleparser
Class AbstractJavaFloatingPointBitsFromCharArray
- java.lang.Object
-
- ch.randelshofer.fastdoubleparser.AbstractNumberParser
-
- ch.randelshofer.fastdoubleparser.AbstractFloatValueParser
-
- ch.randelshofer.fastdoubleparser.AbstractJavaFloatingPointBitsFromCharArray
-
- Direct Known Subclasses:
JavaDoubleBitsFromCharArray,JavaFloatBitsFromCharArray
abstract class AbstractJavaFloatingPointBitsFromCharArray extends AbstractFloatValueParser
Parses a JavaFloatingPointLiteralfrom achararray.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. Alonghas enough bits to fit adoublevalue or afloatvalue.See
JavaDoubleParserfor the grammar ofFloatingPointLiteral.
-
-
Field Summary
Fields Modifier and Type Field Description private static booleanCONDITIONAL_COMPILATION_PARSE_EIGHT_HEX_DIGITS-
Fields inherited from class ch.randelshofer.fastdoubleparser.AbstractFloatValueParser
MAX_EXPONENT_NUMBER, MAX_INPUT_LENGTH, MINIMAL_NINETEEN_DIGIT_INTEGER
-
Fields 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 Constructor Description AbstractJavaFloatingPointBitsFromCharArray()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract longnan()(package private) abstract longnegativeInfinity()private longparseDecFloatLiteral(char[] str, int index, int startIndex, int endIndex, boolean isNegative)Parses aDecimalFloatingPointLiteralproduction with optional trailing white space until the end of the text.longparseFloatingPointLiteral(char[] str, int offset, int length)Parses aFloatingPointLiteralproduction with optional leading and trailing white space.private longparseHexFloatLiteral(char[] 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(char[] str, int index, int endIndex, boolean isNegative)(package private) abstract longpositiveInfinity()private static intskipWhitespace(char[] str, int index, int endIndex)Skips optional white space in the provided stringprivate longtryToParseEightHexDigits(char[] str, int offset)(package private) abstract longvalueOfFloatLiteral(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.(package private) abstract longvalueOfHexLiteral(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.-
Methods inherited from class ch.randelshofer.fastdoubleparser.AbstractNumberParser
charAt, charAt, charAt, checkBounds, checkBounds, lookupHex, lookupHex
-
-
-
-
Field Detail
-
CONDITIONAL_COMPILATION_PARSE_EIGHT_HEX_DIGITS
private static final boolean CONDITIONAL_COMPILATION_PARSE_EIGHT_HEX_DIGITS
- See Also:
- Constant Field Values
-
-
Method Detail
-
skipWhitespace
private static int skipWhitespace(char[] str, int index, int endIndex)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(char[] 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
public long parseFloatingPointLiteral(char[] str, int offset, int length)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(char[] 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
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 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(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 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.
-
-