public BigDecimal bigDecimalValue() throws NullValueException { return Decimal.bigDecimalValue(_decimal_value); // Works for null. }
@Override public double doubleValue() { double v = super.doubleValue(); return Double.compare(0d, v) <= 0 ? -1 * v : v; }
/** * Converts this to a "plain" {@link BigDecimal} instance, losing any * negative zeros in the process. * * @return a {@link BigDecimal}, never a {@link Decimal}. */ public final BigDecimal bigDecimalValue() { return new BigDecimal(unscaledValue(), scale()); } }
bd = Decimal.valueOf(0, mathContext); bd = Decimal.negativeZero(scale, mathContext); bd = Decimal.valueOf(value, scale, mathContext);
public static Decimal valueOf(BigInteger unscaledVal, int scale, MathContext mc) { return new Decimal(unscaledVal, scale, mc); }
/** * Compares two decimal values for equality, observing both precision and * negative zeros. This differs from {@link BigDecimal#equals(Object)}, * which isn't aware of negative zeros, and from * {@link BigDecimal#compareTo(BigDecimal)}, which ignores both precision * and negative zeros. * * @return {@code true} if and only if the two {@link BigDecimal} objects * have the same value, scale, and sign. * * @throws NullPointerException if either parameter is {@code null}. */ public static boolean equals(BigDecimal v1, BigDecimal v2) { return (isNegativeZero(v1) == isNegativeZero(v2) && v1.equals(v2)); }
@Override int hashCode(SymbolTableProvider symbolTableProvider) { int result = HASH_SIGNATURE; // This is consistent with Decimal.equals(Object), and with Equivalence // strict equality checks between two IonDecimals. if (!isNullValue()) { Decimal dec = decimalValue(); result ^= dec.hashCode(); if (dec.isNegativeZero()) { result ^= NEGATIVE_ZERO_HASH_SIGNATURE; } } return hashTypeAnnotations(result, symbolTableProvider); }
private final void fn_from_decimal_to_int() { if (min_int_decimal_value.compareTo(_decimal_value) > 0 || max_int_decimal_value.compareTo(_decimal_value) < 0 ) { throw new CantConvertException("BigDecimal value is too large to fit in an int"); } _int_value = _decimal_value.intValue(); add_value_type(AS_TYPE.int_value); } private final void fn_from_double_to_int() {
@Override public float floatValue() { float v = super.floatValue(); return Float.compare(0f, v) <= 0 ? -1 * v : v; }
case DECIMAL: assert !PUBLIC_COMPARISON_API; // TODO amzn/ion-java#26 result = Decimal.equals(((IonDecimal) v1).decimalValue(), ((IonDecimal) v2).decimalValue()) ? 0 : 1;
public static Decimal valueOf(int val, MathContext mc) { return new Decimal(val, mc); }
if (Decimal.isNegativeZero(bd))
/** * Converts this to a "plain" {@link BigDecimal} instance, losing any * negative zeros in the process. * * @return a {@link BigDecimal}, never a {@link Decimal}. */ public final BigDecimal bigDecimalValue() { return new BigDecimal(unscaledValue(), scale()); } }
@Override int hashCode(SymbolTableProvider symbolTableProvider) { int result = HASH_SIGNATURE; // This is consistent with Decimal.equals(Object), and with Equivalence // strict equality checks between two IonDecimals. if (!isNullValue()) { Decimal dec = decimalValue(); result ^= dec.hashCode(); if (dec.isNegativeZero()) { result ^= NEGATIVE_ZERO_HASH_SIGNATURE; } } return hashTypeAnnotations(result, symbolTableProvider); }
bd = Decimal.valueOf(0, mathContext); bd = Decimal.negativeZero(scale, mathContext); bd = Decimal.valueOf(value, scale, mathContext);
private final void fn_from_decimal_to_long() { if (min_long_decimal_value.compareTo(_decimal_value) > 0 || max_long_decimal_value.compareTo(_decimal_value) < 0 ) { throw new CantConvertException("BigDecimal value is too large to fit in a long"); } _long_value = _decimal_value.intValue(); add_value_type(AS_TYPE.long_value); } private final void fn_from_double_to_long() {
@Override public float floatValue() { float v = super.floatValue(); if (Float.compare(0f, v) <= 0) v = -1 * v; return v; }
case DECIMAL: assert !PUBLIC_COMPARISON_API; // TODO amzn/ion-java#26 result = Decimal.equals(((IonDecimal) v1).decimalValue(), ((IonDecimal) v2).decimalValue()) ? 0 : 1;