Skip to content

Commit

Permalink
Add LongDecial.MIN_SCALE_BITS and LongDecimal.MAX_SCALE_BITS, re #4
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jun 10, 2020
1 parent 2d9a49b commit 675f1ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/main/java/org/libj/math/LongDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@
*/
public final class LongDecimal {
private static final Logger logger = LoggerFactory.getLogger(LongDecimal.class);
static final byte maxScaleBits = 17;
private static final long[] pow2 = new long[maxScaleBits];
static final byte[] minPrecision = new byte[maxScaleBits];
static final byte[] maxPrecision = new byte[maxScaleBits];
static final short[] minScale = new short[maxScaleBits];
static final short[] maxScale = new short[maxScaleBits];

/** The minimum allowed number of scale bits (inclusive). */
public static final byte MIN_SCALE_BITS = 0;
/** The maximum allowed number of scale bits (inclusive). */
public static final byte MAX_SCALE_BITS = 16;

private static final byte noScaleBits = MAX_SCALE_BITS + 1;
private static final long[] pow2 = new long[noScaleBits];
static final byte[] minPrecision = new byte[noScaleBits];
static final byte[] maxPrecision = new byte[noScaleBits];
static final short[] minScale = new short[noScaleBits];
static final short[] maxScale = new short[noScaleBits];

static {
for (byte b = 0; b < maxScaleBits; ++b) {
for (byte b = 0; b < noScaleBits; ++b) {
minPrecision[b] = Numbers.precision(minValue(b));
maxPrecision[b] = Numbers.precision(maxValue(b));
pow2[b] = (long)Math.pow(2, b);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/libj/math/LongDecimalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public abstract class LongDecimalTest {
static final NumberFormat expectedFormatter = new DecimalFormat("0E0");
static final NumberFormat epsilonFormatter = new DecimalFormat("0E0");
static final long[] pow2 = new long[64];
static final BigInteger[] minValue = new BigInteger[maxScaleBits];
static final BigInteger[] maxValue = new BigInteger[maxScaleBits];
static final BigInteger[] minValue = new BigInteger[MAX_SCALE_BITS + 1];
static final BigInteger[] maxValue = new BigInteger[MAX_SCALE_BITS + 1];

static {
for (byte i = 0; i < minValue.length; ++i) {
Expand Down

0 comments on commit 675f1ba

Please sign in to comment.