/** * Create a HiveDecimal from a FastHiveDecimal object. Used by HiveDecimalWritable. * @param fastDec the value to set * @return new hive decimal */ @HiveDecimalVersionV2 public static HiveDecimal createFromFast(FastHiveDecimal fastDec) { return new HiveDecimal(fastDec); }
@HiveDecimalVersionV2 public static HiveDecimal create( boolean isNegative, byte[] bytes, int offset, int length, int scale) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromDigitsOnlyBytesAndScale( isNegative, bytes, offset, length, scale)) { return null; } return result; }
/** * Return a decimal with only the integer digits. * <p> * Any fractional digits are removed. E.g. 2.083 scale 3 returns as 2 scale 0. * */ @HiveDecimalVersionV2 public HiveDecimal integerPortion() { HiveDecimal result = new HiveDecimal(); result.fastIntegerPortion(); return result; }
/** * Create a HiveDecimal object from an int. * */ @HiveDecimalVersionV1 public static HiveDecimal create(int intValue) { HiveDecimal result = new HiveDecimal(); result.fastSetFromInt(intValue); return result; }
@HiveDecimalVersionV2 public static HiveDecimal createFromBigIntegerBytesAndScale( byte[] bytes, int offset, int length, int scale) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBigIntegerBytesAndScale( bytes, offset, length, scale)) { return null; } return result; }
/** * Create a HiveDecimal object from a float. * <p> * This method is equivalent to HiveDecimal.create(Float.toString(floatValue)) */ @HiveDecimalVersionV2 public static HiveDecimal create(float floatValue) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromFloat(floatValue)) { return null; } return result; }
/** * Create a HiveDecimal object from a double. * <p> * This method is equivalent to HiveDecimal.create(Double.toString(doubleValue)) */ @HiveDecimalVersionV2 public static HiveDecimal create(double doubleValue) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromDouble(doubleValue)) { return null; } return result; }
/** * Create a HiveDecimal object from a long. * */ @HiveDecimalVersionV1 public static HiveDecimal create(long longValue) { HiveDecimal result = new HiveDecimal(); result.fastSetFromLong(longValue); return result; }
/** * Return a decimal with only the fractional digits. * <p> * Zero is returned when there are no fractional digits (i.e. scale is 0). * */ @HiveDecimalVersionV2 public HiveDecimal fractionPortion() { HiveDecimal result = new HiveDecimal(); result.fastFractionPortion(); return result; }
/** * Same as the method above, except blanks before and after are tolerated. * */ @HiveDecimalVersionV2 public static HiveDecimal create(byte[] bytes, boolean trimBlanks) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBytes( bytes, 0, bytes.length, trimBlanks)) { return null; } return result; }
/** * Create a HiveDecimal object from a long with a specified scale. * */ @HiveDecimalVersionV2 public static HiveDecimal create(long longValue, int scale) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromLongAndScale( longValue, scale)) { return null; } return result; }
/** * Same as the method above, except blanks before and after are tolerated. * @param string the string to parse * @param trimBlanks True specifies leading and trailing blanks are to be ignored. * @return a new hive decimal */ @HiveDecimalVersionV2 public static HiveDecimal create(String string, boolean trimBlanks) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromString( string, trimBlanks)) { return null; } return result; }
/** * Same as the method above, except blanks before and after are tolerated. * */ @HiveDecimalVersionV2 public static HiveDecimal create( byte[] bytes, int offset, int length, boolean trimBlanks) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBytes( bytes, offset, length, trimBlanks)) { return null; } return result; }
/** * Add the current decimal and another decimal and return the result. * */ @HiveDecimalVersionV1 public HiveDecimal add(HiveDecimal dec) { HiveDecimal result = new HiveDecimal(); if (!fastAdd( dec, result)) { return null; } return result; }
/** * Subtract from the current decimal another decimal and return the result. * */ @HiveDecimalVersionV1 public HiveDecimal subtract(HiveDecimal dec) { HiveDecimal result = new HiveDecimal(); if (!fastSubtract( dec, result)) { return null; } return result; }
/** * Divides this decimal by another decimal and returns a new decimal with the result. * */ @HiveDecimalVersionV1 public HiveDecimal divide(HiveDecimal divisor) { HiveDecimal result = new HiveDecimal(); if (!fastDivide( divisor, result)) { return null; } return result; }
/** * Return the result of decimal^exponent * <p> * CONSIDER: Currently, negative exponent is not supported. * CONSIDER: Does anybody use this method? * */ @HiveDecimalVersionV1 public HiveDecimal pow(int exponent) { HiveDecimal result = new HiveDecimal(this); if (!fastPow( exponent, result)) { return null; } return result; }
/** * Create a HiveDecimal by parsing the characters in a whole byte array. * * Same rules as create(String string) above. * */ @HiveDecimalVersionV2 public static HiveDecimal create(byte[] bytes) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBytes( bytes, 0, bytes.length, false)) { return null; } return result; }
/** * Create a HiveDecimal by parsing the characters in a slice of a byte array. * * Same rules as create(String string) above. * */ @HiveDecimalVersionV2 public static HiveDecimal create(byte[] bytes, int offset, int length) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBytes( bytes, offset, length, false)) { return null; } return result; }
/** * Take the absolute value of a decimal. * <p> * @return When the decimal is negative, returns a new HiveDecimal with the positive value. * Otherwise, returns the current 0 or positive value object; */ @HiveDecimalVersionV1 public HiveDecimal abs() { if (fastSignum() != -1) { return this; } HiveDecimal result = new HiveDecimal(this); result.fastAbs(); return result; }