Top Description Fields Constructors Methods
ch.randelshofer.fastdoubleparser

pack-priv Class FastFloatMath

extends Object
Class Inheritance
Static Imports
ch.randelshofer.fastdoubleparser.FastDoubleMath.DOUBLE_MIN_EXPONENT_POWER_OF_TEN, .FastDoubleMath.MANTISSA_64, .FastIntegerMath.fullMultiplication

This class complements FastDoubleMath with methods for converting FloatingPointLiteral productions to floats.

See JavaDoubleParser for a description of FloatingPointLiteral.

Field Summary

Modifier and TypeField and Description
private static final int
FLOAT_EXPONENT_BIAS

Bias used in the exponent of a float.

private static final int
private static final int
private static final int
private static final int
private static final float[]
FLOAT_POWER_OF_TEN

Precomputed powers of ten from 10^0 to 10^10.

private static final int
FLOAT_SIGNIFICAND_WIDTH

The number of bits in the significand, including the implicit bit.

Constructor Summary

AccessConstructor and Description
private
FastFloatMath()

Don't let anyone instantiate this class.

Method Summary

Modifier and TypeMethod and Description
pack-priv static float
decFloatLiteralToFloat(boolean isNegative, long significand, int exponent, boolean isSignificandTruncated, int exponentOfTruncatedSignificand)

pack-priv static float
hexFloatLiteralToFloat(boolean isNegative, long significand, int exponent, boolean isSignificandTruncated, int exponentOfTruncatedSignificand)

pack-priv static float

Returns:

the computed double on success, Double#NaN on failure
tryDecToFloatWithFastAlgorithm
(boolean
whether the number is negative
isNegative
,
long
uint64 the significand
significand
,
int
int32 the exponent of the number
power
)

Attempts to compute digits * 10^(power) exactly; and if "negative" is true, negate the result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FLOAT_EXPONENT_BIASback to summary
private static final int FLOAT_EXPONENT_BIAS

Bias used in the exponent of a float.

FLOAT_MAX_EXPONENT_POWER_OF_TENback to summary
private static final int FLOAT_MAX_EXPONENT_POWER_OF_TEN
FLOAT_MAX_EXPONENT_POWER_OF_TWOback to summary
private static final int FLOAT_MAX_EXPONENT_POWER_OF_TWO
FLOAT_MIN_EXPONENT_POWER_OF_TENback to summary
private static final int FLOAT_MIN_EXPONENT_POWER_OF_TEN
FLOAT_MIN_EXPONENT_POWER_OF_TWOback to summary
private static final int FLOAT_MIN_EXPONENT_POWER_OF_TWO
FLOAT_POWER_OF_TENback to summary
private static final float[] FLOAT_POWER_OF_TEN

Precomputed powers of ten from 10^0 to 10^10. These can be represented exactly using the float type.

FLOAT_SIGNIFICAND_WIDTHback to summary
private static final int FLOAT_SIGNIFICAND_WIDTH

The number of bits in the significand, including the implicit bit.

Constructor Detail

FastFloatMathback to summary
private FastFloatMath()

Don't let anyone instantiate this class.

Method Detail

decFloatLiteralToFloatback to summary
pack-priv static float decFloatLiteralToFloat(boolean isNegative, long significand, int exponent, boolean isSignificandTruncated, int exponentOfTruncatedSignificand)
hexFloatLiteralToFloatback to summary
pack-priv static float hexFloatLiteralToFloat(boolean isNegative, long significand, int exponent, boolean isSignificandTruncated, int exponentOfTruncatedSignificand)
tryDecToFloatWithFastAlgorithmback to summary
pack-priv static float tryDecToFloatWithFastAlgorithm(boolean isNegative, long significand, int power)

Attempts to compute digits * 10^(power) exactly; and if "negative" is true, negate the result.

This function will only work in some cases, when it does not work it returns null. This should work *most of the time* (like 99% of the time). We assume that power is in the [-325, 308] interval: the caller is responsible for this check.

Parameters
isNegative:boolean

whether the number is negative

significand:long

uint64 the significand

power:int

int32 the exponent of the number

Returns:float

the computed double on success, Double#NaN on failure