Class JavaDoubleParser

java.lang.Object
ch.randelshofer.fastdoubleparser.JavaDoubleParser

public class JavaDoubleParser extends Object
Parses a double value; the supported syntax is compatible with Double.valueOf(String).

Syntax

Leading and trailing whitespace characters in str are ignored. Whitespace is removed as if by the String.trim() method; that is, characters in the range [U+0000,U+0020].

The rest of str should constitute a Java FloatingPointLiteral as described by the lexical syntax rules shown below:

FloatingPointLiteral:
[Sign] NaN
[Sign] Infinity
[Sign] DecimalFloatingPointLiteral
[Sign] HexFloatingPointLiteral
SignedInteger
HexFloatingPointLiteral:
HexSignificand BinaryExponent [FloatTypeSuffix]
HexSignificand:
HexNumeral
HexNumeral .
0x [HexDigits] . HexDigits
0X [HexDigits] . HexDigits
BinaryExponent:
BinaryExponentIndicator SignedInteger
BinaryExponentIndicator:
p
P
DecimalFloatingPointLiteral:
DecSignificand [DecExponent] [FloatTypeSuffix]
DecSignificand:
IntegerPart . [FractionPart]
. FractionPart
IntegerPart
IntegerPart:
Digits
FractionPart:
Digits
DecExponent:
ExponentIndicator SignedInteger
ExponentIndicator:
e
E
SignedInteger:
[Sign] Digits
Sign:
+
-
Digits:
Digit {Digit}
Digit:
(one of)
0 1 2 3 4 5 6 7 8 9
HexNumeral:
0 x HexDigits
0 X HexDigits
HexDigits:
HexDigit {HexDigit}
HexDigit:
(one of)
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
FloatTypeSuffix:
(one of)
f F d D

Expected character lengths for values produced by Double.toString(double):

  • DecSignificand (IntegerPart + FractionPart): 1 to 17 digits
  • IntegerPart: 1 to 7 digits
  • FractionPart: 1 to 16 digits
  • SignedInteger in exponent: 1 to 3 digits
  • FloatingPointLiteral: 1 to 24 characters, e.g. "-1.2345678901234568E-300"
Maximal input length supported by this parser:
  • FloatingPointLiteral with or without white space around it: Integer.MAX_VALUE - 4 = 2,147,483,643 characters.

References:

The Java® Language Specification, Java SE 18 Edition, Chapter 3. Lexical Structure, 3.10.2. Floating-Point Literals
docs.oracle.com