Package org.apache.commons.numbers.core
Class ExtendedPrecision
java.lang.Object
org.apache.commons.numbers.core.ExtendedPrecision
Computes extended precision floating-point operations.
Extended precision computation is delegated to the DD
class. The methods here
are extensions to prevent overflow or underflow in intermediate computations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
The scale to use when down-scaling during a split into a high part.private static final double
The downscale factor squared.private static final double
The lower limit for a productx * y
below which the round-off component may be sub-normal.private static final double
The upper limit above which a number may overflow during the split into a high part.private static final double
The scale to use when up-scaling during a split into a high part.private static final double
The upscale factor squared. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static double
productLow
(double x, double y, double xy) Compute the low part of the double length number(z,zz)
for the exact product ofx
andy
.
-
Field Details
-
SAFE_UPPER
private static final double SAFE_UPPERThe upper limit above which a number may overflow during the split into a high part. Assuming the multiplier is above 2^27 and the maximum exponent is 1023 then a safe limit is a value with an exponent of (1023 - 27) = 2^996. 996 is the value obtained fromMath.getExponent(Double.MAX_VALUE / MULTIPLIER)
.- See Also:
-
SAFE_LOWER
private static final double SAFE_LOWERThe lower limit for a productx * y
below which the round-off component may be sub-normal. This is set as 2^-1022 * 2^54.- See Also:
-
DOWN_SCALE
private static final double DOWN_SCALEThe scale to use when down-scaling during a split into a high part. This must be smaller than the inverse of the multiplier and a power of 2 for exact scaling.- See Also:
-
UP_SCALE
private static final double UP_SCALEThe scale to use when up-scaling during a split into a high part. This is the inverse ofDOWN_SCALE
.- See Also:
-
UP_SCALE2
private static final double UP_SCALE2The upscale factor squared.- See Also:
-
DOWN_SCALE2
private static final double DOWN_SCALE2The downscale factor squared.- See Also:
-
-
Constructor Details
-
ExtendedPrecision
private ExtendedPrecision()Private constructor.
-
-
Method Details
-
productLow
static double productLow(double x, double y, double xy) Compute the low part of the double length number(z,zz)
for the exact product ofx
andy
. This is equivalent to computing adouble
containing the magnitude of the rounding error when converting the exact 106-bit significand of the multiplication result to a 53-bit significand.The method is written to be functionally similar to using a fused multiply add (FMA) operation to compute the low part, for example JDK 9's Math.fma function (note the sign change in the input argument for the product):
double x = ...; double y = ...; double xy = x * y; double low1 = Math.fma(x, y, -xy); double low2 = productLow(x, y, xy);
Special cases:
- If
x * y
is sub-normal or zero then the result is 0.0. - If
x * y
is infinite or NaN then the result is NaN.
This method delegates to
DD.twoProductLow(double, double, double)
but uses scaling to avoid intermediate overflow.- Parameters:
x
- First factor.y
- Second factor.xy
- Product of the factors (x * y).- Returns:
- the low part of the product double length number
- See Also:
- If
-