Skip to content

Commit db6320d

Browse files
Johannes Grahamrgiulietti
authored andcommitted
8368968: FloatingDecimal: Clean up unused code
Reviewed-by: rgiulietti
1 parent ef724f4 commit db6320d

File tree

1 file changed

+2
-160
lines changed

1 file changed

+2
-160
lines changed

src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java

Lines changed: 2 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import jdk.internal.vm.annotation.Stable;
2929

30-
import java.util.Arrays;
31-
3230
/**
3331
* A class for converting between ASCII and decimal representations of a single
3432
* or double precision floating point number. Most conversions are provided via
@@ -102,7 +100,6 @@ public static double parseDoubleSignlessDigits(int decExp, byte[] digits, int le
102100
* values into an ASCII <code>String</code> representation.
103101
*/
104102
public interface BinaryToASCIIConverter {
105-
int getChars(byte[] result);
106103

107104
/**
108105
* Retrieves the decimal exponent most closely corresponding to this value.
@@ -117,20 +114,6 @@ public interface BinaryToASCIIConverter {
117114
*/
118115
int getDigits(byte[] digits);
119116

120-
/**
121-
* Indicates the sign of the value.
122-
* @return {@code value < 0.0}.
123-
*/
124-
boolean isNegative();
125-
126-
/**
127-
* Indicates whether the value is either infinite or not a number.
128-
*
129-
* @return <code>true</code> if and only if the value is <code>NaN</code>
130-
* or infinite.
131-
*/
132-
boolean isExceptional();
133-
134117
/**
135118
* Indicates whether the value was rounded up during the binary to ASCII
136119
* conversion.
@@ -147,63 +130,9 @@ public interface BinaryToASCIIConverter {
147130
boolean decimalDigitsExact();
148131
}
149132

150-
/**
151-
* A <code>BinaryToASCIIConverter</code> which represents <code>NaN</code>
152-
* and infinite values.
153-
*/
154-
private static class ExceptionalBinaryToASCIIBuffer implements BinaryToASCIIConverter {
155-
private final String image;
156-
private final boolean isNegative;
157-
158-
public ExceptionalBinaryToASCIIBuffer(String image, boolean isNegative) {
159-
this.image = image;
160-
this.isNegative = isNegative;
161-
}
162-
163-
@Override
164-
@SuppressWarnings("deprecation")
165-
public int getChars(byte[] chars) {
166-
image.getBytes(0, image.length(), chars, 0);
167-
return image.length();
168-
}
169-
170-
@Override
171-
public int getDecimalExponent() {
172-
throw new IllegalArgumentException("Exceptional value does not have an exponent");
173-
}
174-
175-
@Override
176-
public int getDigits(byte[] digits) {
177-
throw new IllegalArgumentException("Exceptional value does not have digits");
178-
}
179-
180-
@Override
181-
public boolean isNegative() {
182-
return isNegative;
183-
}
184-
185-
@Override
186-
public boolean isExceptional() {
187-
return true;
188-
}
189-
190-
@Override
191-
public boolean digitsRoundedUp() {
192-
throw new IllegalArgumentException("Exceptional value is not rounded");
193-
}
194-
195-
@Override
196-
public boolean decimalDigitsExact() {
197-
throw new IllegalArgumentException("Exceptional value is not exact");
198-
}
199-
}
200-
201133
private static final String INFINITY_REP = "Infinity";
202134
private static final String NAN_REP = "NaN";
203135

204-
private static final BinaryToASCIIConverter B2AC_POSITIVE_INFINITY = new ExceptionalBinaryToASCIIBuffer(INFINITY_REP, false);
205-
private static final BinaryToASCIIConverter B2AC_NEGATIVE_INFINITY = new ExceptionalBinaryToASCIIBuffer("-" + INFINITY_REP, true);
206-
private static final BinaryToASCIIConverter B2AC_NOT_A_NUMBER = new ExceptionalBinaryToASCIIBuffer(NAN_REP, false);
207136
private static final BinaryToASCIIConverter B2AC_POSITIVE_ZERO = new BinaryToASCIIBuffer(false, new byte[]{'0'});
208137
private static final BinaryToASCIIConverter B2AC_NEGATIVE_ZERO = new BinaryToASCIIBuffer(true, new byte[]{'0'});
209138

@@ -260,16 +189,6 @@ public int getDigits(byte[] digits) {
260189
return this.nDigits;
261190
}
262191

263-
@Override
264-
public boolean isNegative() {
265-
return isNegative;
266-
}
267-
268-
@Override
269-
public boolean isExceptional() {
270-
return false;
271-
}
272-
273192
@Override
274193
public boolean digitsRoundedUp() {
275194
return decimalDigitsRoundedUp;
@@ -826,83 +745,6 @@ private static int insignificantDigitsForPow2(int p2) {
826745
61,
827746
};
828747

829-
/**
830-
* Converts the decimal representation of a floating-point number into its
831-
* ASCII character representation and stores it in the provided byte array.
832-
*
833-
* @param result the byte array to store the ASCII representation, must have length at least 26
834-
* @return the number of characters written to the result array
835-
*/
836-
public int getChars(byte[] result) {
837-
assert nDigits <= 19 : nDigits; // generous bound on size of nDigits
838-
int i = 0;
839-
if (isNegative) {
840-
result[0] = '-';
841-
i = 1;
842-
}
843-
if (decExponent > 0 && decExponent < 8) {
844-
// print digits.digits.
845-
int charLength = Math.min(nDigits, decExponent);
846-
System.arraycopy(digits, firstDigitIndex, result, i, charLength);
847-
i += charLength;
848-
if (charLength < decExponent) {
849-
charLength = decExponent - charLength;
850-
Arrays.fill(result, i, i + charLength, (byte) '0');
851-
i += charLength;
852-
result[i++] = '.';
853-
result[i++] = '0';
854-
} else {
855-
result[i++] = '.';
856-
if (charLength < nDigits) {
857-
int t = nDigits - charLength;
858-
System.arraycopy(digits, firstDigitIndex + charLength, result, i, t);
859-
i += t;
860-
} else {
861-
result[i++] = '0';
862-
}
863-
}
864-
} else if (decExponent <= 0 && decExponent > -3) {
865-
result[i++] = '0';
866-
result[i++] = '.';
867-
if (decExponent != 0) {
868-
Arrays.fill(result, i, i-decExponent, (byte) '0');
869-
i -= decExponent;
870-
}
871-
System.arraycopy(digits, firstDigitIndex, result, i, nDigits);
872-
i += nDigits;
873-
} else {
874-
result[i++] = digits[firstDigitIndex];
875-
result[i++] = '.';
876-
if (nDigits > 1) {
877-
System.arraycopy(digits, firstDigitIndex+1, result, i, nDigits - 1);
878-
i += nDigits - 1;
879-
} else {
880-
result[i++] = '0';
881-
}
882-
result[i++] = 'E';
883-
int e;
884-
if (decExponent <= 0) {
885-
result[i++] = '-';
886-
e = -decExponent + 1;
887-
} else {
888-
e = decExponent - 1;
889-
}
890-
// decExponent has 1, 2, or 3, digits
891-
if (e <= 9) {
892-
result[i++] = (byte) (e + '0');
893-
} else if (e <= 99) {
894-
result[i++] = (byte) (e / 10 + '0');
895-
result[i++] = (byte) (e % 10 + '0');
896-
} else {
897-
result[i++] = (byte) (e / 100 + '0');
898-
e %= 100;
899-
result[i++] = (byte) (e / 10 + '0');
900-
result[i++] = (byte) (e % 10 + '0');
901-
}
902-
}
903-
return i;
904-
}
905-
906748
}
907749

908750
private static final ThreadLocal<BinaryToASCIIBuffer> threadLocalBinaryToASCIIBuffer =
@@ -1707,9 +1549,9 @@ private static BinaryToASCIIConverter getCompatBinaryToASCIIConverter(double d,
17071549
// Discover obvious special cases of NaN and Infinity.
17081550
if ( binExp == (int)(DoubleConsts.EXP_BIT_MASK>>EXP_SHIFT) ) {
17091551
if ( fractBits == 0L ){
1710-
return isNegative ? B2AC_NEGATIVE_INFINITY : B2AC_POSITIVE_INFINITY;
1552+
throw new IllegalArgumentException((isNegative ? "-" : "") + INFINITY_REP);
17111553
} else {
1712-
return B2AC_NOT_A_NUMBER;
1554+
throw new IllegalArgumentException(NAN_REP);
17131555
}
17141556
}
17151557
// Finish unpacking

0 commit comments

Comments
 (0)