Package ch.randelshofer.fastdoubleparser
Class FastDoubleParserFromByteArray
- java.lang.Object
-
- ch.randelshofer.fastdoubleparser.FastDoubleParserFromByteArray
-
public class FastDoubleParserFromByteArray extends java.lang.ObjectThis 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 doubleparseDouble(byte[] str)Convenience method for callingparseDouble(byte[], int, int).static doubleparseDouble(byte[] str, int off, int len)Returns a Double object holding the double value represented by the argument stringstr.
-
-
-
Method Detail
-
parseDouble
public static double parseDouble(byte[] str) throws java.lang.NumberFormatExceptionConvenience method for callingparseDouble(byte[], int, int).- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding- Returns:
- the parsed double value
- Throws:
java.lang.NumberFormatException- if the string can not be parsed
-
parseDouble
public static double parseDouble(byte[] str, int off, int len) throws java.lang.NumberFormatExceptionReturns a Double object holding the double value represented by the argument stringstr.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
strare ignored. Whitespace is removed as if by theString.trim()method; that is, characters in the range [U+0000,U+0020].The rest of
strshould constitute a FloatValue as described by the lexical syntax rules shown below:- FloatValue:
- [Sign]
NaN- [Sign]
Infinity- [Sign] DecimalFloatingPointLiteral
- [Sign] HexFloatingPointLiteral
- SignedInteger
- [Sign]
- HexFloatingPointLiteral:
- HexSignificand BinaryExponent
- HexSignificand:
- HexNumeral
- HexNumeral
.0x[HexDigits].HexDigits0X[HexDigits].HexDigits - HexNumeral
- HexSignificand:
- HexNumeral
- HexNumeral
.0x[HexDigits].HexDigits0X[HexDigits].HexDigits - HexNumeral
- BinaryExponent:
- BinaryExponentIndicator SignedInteger
- BinaryExponentIndicator:
pP
- 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:
0xHexDigits0XHexDigits
- 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, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoff- The index of the first byte to parselen- The number of bytes to parse- Returns:
- the parsed double value
- Throws:
java.lang.NumberFormatException- if the string can not be parsed
-
-