Top Description Fields Constructors Methods
ch.randelshofer.fastdoubleparser

pack-priv abstract Class AbstractJavaFloatingPointBitsFromByteArray

extends AbstractFloatValueParser
Class Inheritance
Known Direct Subclasses
ch.randelshofer.fastdoubleparser.JavaDoubleBitsFromByteArray, ch.randelshofer.fastdoubleparser.JavaFloatBitsFromByteArray

Parses a Java FloatingPointLiteral from a byte 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 Summary

Inherited from ch.randelshofer.fastdoubleparser.AbstractFloatValueParser:
MAX_EXPONENT_NUMBERMAX_INPUT_LENGTHMINIMAL_NINETEEN_DIGIT_INTEGER

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract long

Returns:

a NaN constant in the specialized type wrapped in a long
nan
()

pack-priv abstract long

Returns:

a negative infinity constant in the specialized type wrapped in a long
negativeInfinity
()

private long

Returns:

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
parseDecFloatLiteral
(byte[]
a string
str
,
int
start index inclusive of the DecimalFloatingPointLiteralWithWhiteSpace
index
,
int startIndex, int
end index (exclusive)
endIndex
,
boolean
true if the float value is negative
isNegative
,
boolean
true if we have consumed the optional leading zero
hasLeadingZero
)

Parses a DecimalFloatingPointLiteral production with optional trailing white space until the end of the text.

public long

Returns:

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
parseFloatingPointLiteral
(byte[]
a string containing a FloatingPointLiteralWithWhiteSpace
str
,
int
start offset of FloatingPointLiteralWithWhiteSpace in str
offset
,
int
length of FloatingPointLiteralWithWhiteSpace in str
length
)

Parses a FloatingPointLiteral production with optional leading and trailing white space.

private long

Returns:

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
parseHexFloatingPointLiteral
(byte[]
the input string
str
,
int
index to the first character of RestOfHexFloatingPointLiteral
index
,
int
the start index of the string
startIndex
,
int
the end index of the string
endIndex
,
boolean
if the resulting number is negative
isNegative
)

Parses the following rules (more rules are defined in AbstractFloatValueParser):

RestOfHexFloatingPointLiteral:
RestOfHexSignificand BinaryExponent
private long
parseNaNOrInfinity(byte[] str, int index, int endIndex, boolean isNegative)

pack-priv abstract long

Returns:

a positive infinity constant in the specialized type wrapped in a long
positiveInfinity
()

private static int

Returns:

index after the optional white space
skipWhitespace
(byte[]
a string
str
,
int
start index (inclusive) of the optional white space
index
,
int
end index (exclusive) of the optional white space
endIndex
)

Skips optional white space in the provided string

pack-priv abstract long

Returns:

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.
valueOfFloatLiteral
(byte[]
the string that contains the float literal (and maybe more)
str
,
int
the start index (inclusive) of the float literal inside the string
startIndex
,
int
the end index (exclusive) of the float literal inside the string
endIndex
,
boolean
whether the float value is negative
isNegative
,
long
the significand of the float value (can be truncated)
significand
,
int
the exponent of the float value
exponent
,
boolean
whether the significand is truncated
isSignificandTruncated
,
int
the exponent value of the truncated significand
exponentOfTruncatedSignificand
)

Computes a float value from the given components of a decimal float literal.

pack-priv abstract long

Returns:

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

Computes a float value from the given components of a hexadecimal float literal.

Constructor Detail

AbstractJavaFloatingPointBitsFromByteArrayback to summary
pack-priv AbstractJavaFloatingPointBitsFromByteArray()

Method Detail

nanback to summary
pack-priv abstract long nan()
Returns:long

a NaN constant in the specialized type wrapped in a long

negativeInfinityback to summary
pack-priv abstract long negativeInfinity()
Returns:long

a negative infinity constant in the specialized type wrapped in a long

parseDecFloatLiteralback to summary
private long parseDecFloatLiteral(byte[] str, int index, int startIndex, int endIndex, boolean isNegative, boolean hasLeadingZero)

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:byte[]

a string

index:int

start index inclusive of the DecimalFloatingPointLiteralWithWhiteSpace

endIndex:int

end index (exclusive)

isNegative:boolean

true if the float value is negative

hasLeadingZero:boolean

true if we have consumed the optional leading zero

Returns:long

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.

parseFloatingPointLiteralback to summary
public long parseFloatingPointLiteral(byte[] 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:byte[]

a string containing a FloatingPointLiteralWithWhiteSpace

offset:int

start offset of FloatingPointLiteralWithWhiteSpace in str

length:int

length of FloatingPointLiteralWithWhiteSpace in str

Returns:long

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.

parseHexFloatingPointLiteralback to summary
private long parseHexFloatingPointLiteral(byte[] 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:byte[]

the input string

index:int

index to the first character of RestOfHexFloatingPointLiteral

startIndex:int

the start index of the string

endIndex:int

the end index of the string

isNegative:boolean

if the resulting number is negative

Returns:long

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.

parseNaNOrInfinityback to summary
private long parseNaNOrInfinity(byte[] str, int index, int endIndex, boolean isNegative)
positiveInfinityback to summary
pack-priv abstract long positiveInfinity()
Returns:long

a positive infinity constant in the specialized type wrapped in a long

skipWhitespaceback to summary
private static int skipWhitespace(byte[] str, int index, int endIndex)

Skips optional white space in the provided string

Parameters
str:byte[]

a string

index:int

start index (inclusive) of the optional white space

endIndex:int

end index (exclusive) of the optional white space

Returns:int

index after the optional white space

valueOfFloatLiteralback to summary
pack-priv abstract long valueOfFloatLiteral(byte[] 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:byte[]

the string that contains the float literal (and maybe more)

startIndex:int

the start index (inclusive) of the float literal inside the string

endIndex:int

the end index (exclusive) of the float literal inside the string

isNegative:boolean

whether the float value is negative

significand:long

the significand of the float value (can be truncated)

exponent:int

the exponent of the float value

isSignificandTruncated:boolean

whether the significand is truncated

exponentOfTruncatedSignificand:int

the exponent value of the truncated significand

Returns:long

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.

valueOfHexLiteralback to summary
pack-priv abstract long valueOfHexLiteral(byte[] 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:byte[]

the string that contains the float literal (and maybe more)

startIndex:int

the start index (inclusive) of the float literal inside the string

endIndex:int

the end index (exclusive) of the float literal inside the string

isNegative:boolean

whether the float value is negative

significand:long

the significand of the float value (can be truncated)

exponent:int

the exponent of the float value

isSignificandTruncated:boolean

whether the significand is truncated

exponentOfTruncatedSignificand:int

the exponent value of the truncated significand

Returns:long

the bit pattern of the parsed value, if the input is legal; otherwise, -1L.