ch.randelshofer.fastdoubleparser.JavaDoubleBitsFromCharArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastdoubleparser Show documentation
Show all versions of fastdoubleparser Show documentation
A Java port of Daniel Lemire's fast_float project.
/*
* @(#)JavaDoubleBitsFromCharArray.java
* Copyright © 2023 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;
/**
* Parses a {@code double} from a {@code char} array.
*/
final class JavaDoubleBitsFromCharArray extends AbstractJavaFloatingPointBitsFromCharArray {
/**
* Creates a new instance.
*/
public JavaDoubleBitsFromCharArray() {
}
@Override
long nan() {
return Double.doubleToRawLongBits(Double.NaN);
}
@Override
long negativeInfinity() {
return Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY);
}
@Override
long positiveInfinity() {
return Double.doubleToRawLongBits(Double.POSITIVE_INFINITY);
}
@Override
long valueOfFloatLiteral(char[] str, int startIndex, int endIndex, boolean isNegative,
long significand, int exponent, boolean isSignificandTruncated,
int exponentOfTruncatedSignificand) {
double d = FastDoubleMath.tryDecFloatToDoubleTruncated(isNegative, significand, exponent, isSignificandTruncated,
exponentOfTruncatedSignificand);
return Double.doubleToRawLongBits(Double.isNaN(d) ? Double.parseDouble(new String(str, startIndex, endIndex - startIndex)) : d);
}
@Override
long valueOfHexLiteral(
char[] str, int startIndex, int endIndex, boolean isNegative, long significand, int exponent,
boolean isSignificandTruncated, int exponentOfTruncatedSignificand) {
double d = FastDoubleMath.tryHexFloatToDoubleTruncated(isNegative, significand, exponent, isSignificandTruncated,
exponentOfTruncatedSignificand);
return Double.doubleToRawLongBits(Double.isNaN(d) ? Double.parseDouble(new String(str, startIndex, endIndex - startIndex)) : d);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy