Package java.math

Examples of java.math.BigDecimal.precision()


     */
    private static int roundAway0(BigDecimal b1, BigDecimal b2) {
        int failures = 0;
        BigDecimal exactSum = b1.add(b2);

        for(int precision = 1 ; precision < exactSum.precision()+2; precision++) {
            for(RoundingMode rm : nonExactRoundingModes) {
                MathContext mc = new MathContext(precision, rm);
                BigDecimal roundedExactSum = exactSum.round(mc);

                try {
View Full Code Here


        }
        return Boolean.parseBoolean( pigObj.toString() );
      case DECIMAL:
        BigDecimal bd = (BigDecimal)pigObj;
        DecimalTypeInfo dti = (DecimalTypeInfo)hcatFS.getTypeInfo();
        if(bd.precision() > dti.precision() || bd.scale() > dti.scale()) {
          handleOutOfRangeValue(pigObj, hcatFS);
          return null;
        }
        return HiveDecimal.create(bd);
      case CHAR:
View Full Code Here

  }

  public static String getBaseDecimal(ExpandedDouble hd) {
    int gg = 64 - hd.getBinaryExponent() - 1;
    BigDecimal bd = new BigDecimal(hd.getSignificand()).divide(new BigDecimal(BigInteger.ONE.shiftLeft(gg)));
    int excessPrecision = bd.precision() - 23;
    if (excessPrecision > 0) {
      bd = bd.setScale(bd.scale() - excessPrecision, BigDecimal.ROUND_HALF_UP);
    }
    return bd.unscaledValue().toString();
  }
View Full Code Here

      }
      int binaryExp = binExp - newFrac.bitLength() + frac.bitLength();

      bd = new BigDecimal( frac.shiftRight(frac.bitLength()-binaryExp-1));
    }
    int excessPrecision = bd.precision() - nDec;
    if (excessPrecision > 0) {
      bd = bd.setScale(bd.scale() - excessPrecision, BigDecimal.ROUND_HALF_UP);
    }
    return bd.unscaledValue();
  }
View Full Code Here

    }
    else {
      bigNum = new BigDecimal( num.toString() ).stripTrailingZeros();
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
View Full Code Here

    BigDecimal bigNum = getBigDecimalValue( str );
    if ( bigNum == null ) {
      return false;
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
View Full Code Here

            return newInfinity(context.runtime, sign1 * sign2);
        }

        BigDecimal res = value.multiply(val.value);
        // FIXME: rounding mode should not be hard-coded. See #mode.
        if (res.precision() > digits) res = res.round(new MathContext(digits,  RoundingMode.HALF_UP));

        return new RubyBigDecimal(context.runtime, res).setResult();
    }
   
    // Calculate appropriate zero or infinity depending on exponent...
View Full Code Here

    private int getExponent() {
        if (isZero() || isNaN() || isInfinity()) return 0;

        BigDecimal val = value.abs().stripTrailingZeros();
        return val.precision() - val.scale();
    }

    @JRubyMethod
    public IRubyObject sqrt(IRubyObject arg) {
        Ruby runtime = getRuntime();
View Full Code Here

        BigDecimal b1_negate = b1.negate();
        BigDecimal b2_negate = b2.negate();

        b1_negate.precision();
        b2_negate.precision();

        failures += roundAway1(b1,        b2);
        failures += roundAway1(b1,        b2_negate);
        failures += roundAway1(b1_negate, b2);
        failures += roundAway1(b1_negate, b2_negate);
View Full Code Here

     */
    private static int roundAway0(BigDecimal b1, BigDecimal b2) {
        int failures = 0;
        BigDecimal exactSum = b1.add(b2);

        for(int precision = 1 ; precision < exactSum.precision()+2; precision++) {
            for(RoundingMode rm : nonExactRoundingModes) {
                MathContext mc = new MathContext(precision, rm);
                BigDecimal roundedExactSum = exactSum.round(mc);

                try {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.