Remove unused doubleToLongDecimal method
@@ -1741,84 +1741,4 @@ public final class UnscaledDecimal128Arithmetic
}
private UnscaledDecimal128Arithmetic() {}
-
- public static Slice doubleToLongDecimal(double value, long precision, int scale)
- {
- if (Double.isInfinite(value) || Double.isNaN(value)) {
- throwOverflowException();
- }
-
- // Translate the double into sign, exponent and significand, according
- // to the formulae in JLS, Section 20.10.22.
- long valBits = Double.doubleToLongBits(value);
- int sign = ((valBits >> 63) == 0 ? 1 : -1);
- int exponent = (int) ((valBits >> 52) & 0x7ffL);
- long significand = (exponent == 0
- ? (valBits & ((1L << 52) - 1)) << 1
- : (valBits & ((1L << 52) - 1)) | (1L << 52));
- exponent -= 1075;
- // At this point, value == sign * significand * 2**exponent.
-
- // zero check
- if (significand == 0) {
- return unscaledDecimal();
- }
-
- // Normalize
- while ((significand & 1) == 0) { // i.e., significand is even
- significand >>= 1;
- exponent++;
- }
-
- // so far same as java.math.BigDecimal, but the scaling below is
- // specific to ANSI SQL Numeric.
-
- // first, underflow is NOT an error in ANSI SQL Numeric.
- // CAST(0.000000000....0001 AS DECIMAL(38,1)) is "0.0" without an error.
-
- // second, overflow IS an error in ANSI SQL Numeric.
- // CAST(10000 AS DECIMAL(38,38)) throws overflow error.
-
- // value == sign * significand * 2**exponent.
- // decimal == sign * unscaledValue / 10**scale.
- // so, to make value == decimal, we need to scale it up/down such that:
- // unscaledValue = significand * 2**exponent * 10**scale
- // Notice that we must do the scaling carefully to check overflow and
- // preserve precision.
-
- Slice unscaledValue = UnscaledDecimal128Arithmetic.unscaledDecimal(significand);
-
- if (exponent >= 0) {
- // both parts are scaling up. easy. Just check overflow.
- shiftLeftDestructive(unscaledValue, exponent);
- rescale(unscaledValue, scale, unscaledValue);
- }
- else {
- // 2**exponent part is scaling down while 10**scale is scaling up.
- // Now it's tricky.
- // unscaledValue = significand * 10**scale / 2**twoScaleDown
- short twoScaleDown = (short) -exponent;
-
- if (scale >= twoScaleDown) {
- // make both scaling up as follows
- // unscaledValue = significand * 5**(scale) *
- // 2**(scale-twoScaleDown)
- shiftLeftDestructive(unscaledValue, scale - twoScaleDown);
- scaleUpFiveDestructive(unscaledValue, scale);
- }
- else {
- // Gosh, really both scaling up and down.
- // unscaledValue = significand * 5**(scale) /
- // 2**(twoScaleDown-scale)
- // To check overflow while preserving precision, we need to do a
- // real multiplication
-
- multiplyShiftDestructive(unscaledValue, POWERS_OF_FIVE[scale], (twoScaleDown - scale));
- }
- }
-
- setNegative(unscaledValue, sign < 0);
-
- return unscaledValue;
- }
}
