- // >>> FIXME: these need to take a scale value and perform a range check. we also need truncating counterparts
- public static Decimal64 valueOf(final byte byteVal) {
- return byteVal < 0 ? new Decimal64(1, -byteVal, 0, true) : new Decimal64(1, byteVal, 0, false);
+ /**
+ * Return the minimum value supported in specified scale.
+ *
+ * @param scale scale to use
+ * @return Minimum value in that scale
+ * @throws IllegalArgumentException if {@code scale} is not in range {@code [1..18]}
+ */
+ public static Decimal64 minValueIn(final int scale) {
+ return MIN_VALUE[offsetOf(scale)];
+ }
+
+ /**
+ * Return the maximum value supported in specified scale.
+ *
+ * @param scale scale to use
+ * @return Maximum value in that scale
+ * @throws IllegalArgumentException if {@code scale} is not in range {@code [1..18]}
+ */
+ public static Decimal64 maxValueIn(final int scale) {
+ return MAX_VALUE[offsetOf(scale)];
+ }
+
+ // >>> FIXME: these need truncating counterparts
+ public static Decimal64 valueOf(final int scale, final byte byteVal) {
+ final byte offset = offsetOf(scale);
+ final var conv = CONVERSION[offset];
+ if (byteVal < conv.minByte || byteVal > conv.maxByte) {
+ throw new IllegalArgumentException("Value " + byteVal + " is not in range ["
+ + conv.minByte + ".." + conv.maxByte + "] to fit scale " + scale);
+ }
+ return byteVal < 0 ? new Decimal64(offset, -byteVal, true) : new Decimal64(offset, byteVal, false);
+ }
+
+ public static Decimal64 valueOf(final int scale, final short shortVal) {
+ final byte offset = offsetOf(scale);
+ final var conv = CONVERSION[offset];
+ if (shortVal < conv.minShort || shortVal > conv.maxShort) {
+ throw new IllegalArgumentException("Value " + shortVal + " is not in range ["
+ + conv.minShort + ".." + conv.maxShort + "] to fit scale " + scale);
+ }
+ return shortVal < 0 ? new Decimal64(offset, -shortVal, true) : new Decimal64(offset, shortVal, false);