/** * Get the sign of the underlying decimal. * @return 0 if the decimal is equal to 0, -1 if less than zero, and 1 if greater than 0 */ @HiveDecimalVersionV1 public int signum() { return bd.signum(); }
/** Note - this method will corrupt the value if it doesn't fit. */ @HiveDecimalVersionV1 public long longValue() { return bd.longValue(); }
@HiveDecimalVersionV1 public int scale() { return bd.scale(); }
@HiveDecimalVersionV1 @Override public int hashCode() { return bd.hashCode(); }
@HiveDecimalVersionV1 @Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != getClass()) { return false; } return bd.equals(((HiveDecimalV1) obj).bd); }
/** * A short variation of longValue(). * <p> * This method will return a corrupted value unless isShort() is true. */ @HiveDecimalVersionV1 public short shortValue() { return fastShortValueClip(); }
/** * Return a BigDecimal representing the decimal. The BigDecimal class is able to accurately * represent the decimal. * * NOTE: We are not representing our decimal as BigDecimal now as OldHiveDecimal did, so this * is now slower. * */ @HiveDecimalVersionV1 public BigDecimal bigDecimalValue() { return fastBigDecimalValue(); }
@HiveDecimalVersionV1 public long longValueExact() { return bd.longValueExact(); } }
/** * Returns the scale of the decimal. Range 0 .. MAX_SCALE. * */ @HiveDecimalVersionV1 public int scale() { return fastScale(); }
/** * Return a float representing the decimal. Due the limitations of float, some values will not * be accurate. * */ @HiveDecimalVersionV1 public float floatValue() { return fastFloatValue(); }
/** * Return the long value of a decimal. * <p> * This method will return a corrupted value unless isLong() is true. */ @HiveDecimalVersionV1 public long longValue() { return fastLongValueClip(); }
/** * Return a double representing the decimal. Due the limitations of double, some values will not * be accurate. * */ @HiveDecimalVersionV1 public double doubleValue() { return fastDoubleValue(); }
@HiveDecimalVersionV1 public HiveDecimalV1 abs() { return create(bd.abs()); }
@HiveDecimalVersionV1 public HiveDecimalV1 add(HiveDecimalV1 dec) { return create(bd.add(dec.bd)); }
/** * An int variation of longValue(). * <p> * This method will return a corrupted value unless isInt() is true. */ @HiveDecimalVersionV1 public int intValue() { return fastIntValueClip(); }
/** * Get a BigInteger representing the decimal's digits without a dot. * <p> * @return Returns a signed BigInteger. */ @HiveDecimalVersionV1 public BigInteger unscaledValue() { return fastBigIntegerValue(); }
@HiveDecimalVersionV1 public static HiveDecimalV1 create(BigInteger unscaled, int scale) { BigDecimal bd = normalize(new BigDecimal(unscaled, scale), true); return bd == null ? null : new HiveDecimalV1(bd); }
@HiveDecimalVersionV1 public static HiveDecimalV1 create(BigInteger bi) { BigDecimal bd = normalize(new BigDecimal(bi), true); return bd == null ? null : new HiveDecimalV1(bd); }
@HiveDecimalVersionV1 public long longValueExact() { if (!isLong()) { throw new ArithmeticException(); } return fastLongValueClip(); }
/** * Create a HiveDecimal object from an int. * */ @HiveDecimalVersionV1 public static HiveDecimal create(int intValue) { HiveDecimal result = new HiveDecimal(); result.fastSetFromInt(intValue); return result; }