Class FastDoubleParser


  • public class FastDoubleParser
    extends java.lang.Object
    This is a C++ to Java port of Daniel Lemire's fast_double_parser.

    The code has been changed, so that it parses the same syntax as Double.parseDouble(String).

    References:

    Daniel Lemire, fast_double_parser, 4x faster than strtod. Apache License 2.0 or Boost Software License.
    github.com
    Daniel Lemire, fast_float number parsing library: 4x faster than strtod. Apache License 2.0.
    github.com
    Daniel Lemire, Number Parsing at a Gigabyte per Second. arXiv.2101.11408v3 [cs.DS] 24 Feb 2021
    arxiv.org
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double parseDouble​(java.lang.CharSequence str)
      Returns a Double object holding the double value represented by the argument string str.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • parseDouble

        public static double parseDouble​(java.lang.CharSequence str)
                                  throws java.lang.NumberFormatException
        Returns a Double object holding the double value represented by the argument string str.

        This method can be used as a drop in for method Double.valueOf(String). (Assuming that the API of this method has not changed since Java SE 16).

        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 FloatValue as described by the lexical syntax rules shown below:

        FloatValue:
        [Sign] NaN
        [Sign] Infinity
        [Sign] DecimalFloatingPointLiteral
        [Sign] HexFloatingPointLiteral
        SignedInteger
        HexFloatingPointLiteral:
        HexSignificand BinaryExponent
        HexSignificand:
        HexNumeral
        HexNumeral .
        0x [HexDigits] . HexDigits
        0X [HexDigits] . HexDigits
        HexSignificand:
        HexNumeral
        HexNumeral .
        0x [HexDigits] . HexDigits
        0X [HexDigits] . HexDigits
        BinaryExponent:
        BinaryExponentIndicator SignedInteger
        BinaryExponentIndicator:
        p
        P
        DecimalFloatingPointLiteral:
        Digits . [Digits] [ExponentPart]
        . Digits [ExponentPart]
        Digits ExponentPart
        ExponentPart:
        ExponentIndicator SignedInteger
        ExponentIndicator:
        (one of)
        e E
        SignedInteger:
        [Sign] Digits
        Sign:
        (one of)
        + -
        Digits:
        Digit {Digit}
        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
        Parameters:
        str - the string to be parsed
        Returns:
        the parsed double value
        Throws:
        java.lang.NumberFormatException - if the string can not be parsed