當前位置: 首頁>>代碼示例>>Java>>正文


Java BigDecimal.pow方法代碼示例

本文整理匯總了Java中java.math.BigDecimal.pow方法的典型用法代碼示例。如果您正苦於以下問題:Java BigDecimal.pow方法的具體用法?Java BigDecimal.pow怎麽用?Java BigDecimal.pow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.math.BigDecimal的用法示例。


在下文中一共展示了BigDecimal.pow方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sumCorrelationsOfBucket

import java.math.BigDecimal; //導入方法依賴的package包/類
static BigDecimal sumCorrelationsOfBucket(RiskClass riskClass, List<WeightedSensitivity> weightedSensitivities) {
  BigDecimal sum = BigDecimal.ZERO;

  for (WeightedSensitivity weightedSensitivityK : weightedSensitivities) {
    for (WeightedSensitivity weightedSensitivityI : weightedSensitivities) {
      if (weightedSensitivityI != weightedSensitivityK) {
        BigDecimal correlation = RiskCorrelation.getSensitivityCorrelation(riskClass, weightedSensitivityI.getSensitivity(), weightedSensitivityK.getSensitivity());
        BigDecimal squaredCorrelation = correlation.pow(2);
        BigDecimal value = squaredCorrelation.multiply(weightedSensitivityI.getWeightedValue()).multiply(weightedSensitivityK.getWeightedValue());
        sum = sum.add(value);
      }
    }
  }

  return sum;
}
 
開發者ID:AcadiaSoft,項目名稱:simm-lib,代碼行數:17,代碼來源:CurvatureMarginBucketUtils.java

示例2: calculate

import java.math.BigDecimal; //導入方法依賴的package包/類
private static BigDecimal calculate(String input) {

        int i = 1;
        while (i < input.length() && !order.containsKey(input.charAt(i)))
            i++;

        String var = input.substring(0, i);
        BigDecimal value = variables.getOrDefault(var, new BigDecimal(var));

        char ope = i < input.length() ? input.charAt(0) : 0;
        if (ope == 0) return value;

        int currOrder = order.getOrDefault(ope, -1);

        BigDecimal result = null;
        if (currOrder > 0)
            result = calculate(input.substring(i + 1));

        switch (currOrder) {
            case '+':
                return value.add(result);
            case '-':
                return value.subtract(result);
            case '*':
                return value.multiply(result);
            case '/':
                return value.divide(result, BigDecimal.ROUND_HALF_UP);
            case '^':
                // If pow of int BigDecimal can handle it
                if (result.precision() == 0) return value.pow(result.intValue());
                // Otherwise we gotta revert to power of doubles
                return BigDecimal.valueOf(Math.pow(value.doubleValue(), result.doubleValue()));
        }

        return null;
    }
 
開發者ID:Baizey,項目名稱:Helpers,代碼行數:37,代碼來源:Evaluator.java

示例3: sumCorrelationsAcrossBuckets

import java.math.BigDecimal; //導入方法依賴的package包/類
static BigDecimal sumCorrelationsAcrossBuckets(RiskClass riskClass, List<BucketWeightedAggregation> aggregateByBucket) {
  BigDecimal sum = ZERO;

  if (CollectionUtils.isNotEmpty(aggregateByBucket)) {
    for (BucketWeightedAggregation bucketAggregateB : aggregateByBucket) {
      for (BucketWeightedAggregation bucketAggregateC : aggregateByBucket) {
        if (!StringUtils.equals(bucketAggregateB.getBucket(), bucketAggregateC.getBucket())) {
          BigDecimal correlation = RiskCorrelation.getBucketCorrelation(riskClass, bucketAggregateB.getBucket(), bucketAggregateC.getBucket());
          BigDecimal squaredCorrelation = correlation.pow(2);

          BigDecimal bucketBSum = WeightedSensitivityUtils.sumWeightSensitivities(bucketAggregateB.getWeightedSensitivities());
          BigDecimal bucketBAggregate = bucketAggregateB.getAggregate();
          BigDecimal sb = bucketBSum.min(bucketBAggregate).max(bucketBAggregate.negate());

          BigDecimal bucketCSum = WeightedSensitivityUtils.sumWeightSensitivities(bucketAggregateC.getWeightedSensitivities());
          BigDecimal bucketCAggregate = bucketAggregateC.getAggregate();
          BigDecimal sc = bucketCSum.min(bucketCAggregate).max(bucketCAggregate.negate());

          BigDecimal product = squaredCorrelation.multiply(sb).multiply(sc);
          sum = sum.add(product);
        }
      }
    }
  }
  return sum;
}
 
開發者ID:AcadiaSoft,項目名稱:simm-lib,代碼行數:27,代碼來源:CurvatureMarginAcrossBucketUtils.java

示例4: eval

import java.math.BigDecimal; //導入方法依賴的package包/類
private BigDecimal eval(Interpreter interpreter, HashMap<String, BigDecimal> arguments, HashSet<String> reserved) throws SyntaxException, ArithmeticException, StackOverflowError {
    if (value == null) {
        BigDecimal l = left.eval(interpreter, arguments);
        BigDecimal r = right.eval(interpreter, arguments);
        switch (operator) {
            case '-': return l.subtract(r);
            case '+': return l.add(r);
            case '*': return l.multiply(r);
            case '%': return l.remainder(r);
            case '/': return l.divide(r, interpreter.getInternalRounding(), RoundingMode.HALF_UP);
            case '^': return l.pow(r.intValue());
        }
    }
    if (reserved.contains(value))
        throw new SyntaxException("Variable '" + value + "' is reserved");
    if(arguments.containsKey(value))
        return arguments.get(value);

    HashMap<String, BigDecimal> variables = interpreter.getVariables();
    if(variables.containsKey(value))
        return variables.get(value);
    if (value.contains("(")) {
        HashMap<String, Function> functions = interpreter.getFunctions();
        String name = value.split("\\(")[0];
        if(!functions.containsKey(name)) throw new SyntaxException("Function '" + name + "' not defined");
        String args = value.substring(name.length() + 1, value.length() - 1);
        return functions.get(name).eval(interpreter, arguments, args);
    }
    if(value.matches("[0-9]+(\\.[0-9]*)?"))
        return new BigDecimal(value);
    throw new SyntaxException("Variable '" + value + "' not defined");
}
 
開發者ID:Baizey,項目名稱:Helpers,代碼行數:33,代碼來源:ParserNode.java

示例5: sqrtNewtonRaphson

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Private utility method used to compute the square root of a BigDecimal.
 * See http://www.codeproject.com/Tips/257031/Implementing-SqrtRoot-in-BigDecimal
 * 
 * @author Luciano Culacciatti 
 */
private static BigDecimal sqrtNewtonRaphson(BigDecimal c, BigDecimal xn, BigDecimal precision){
    BigDecimal fx = xn.pow(2).add(c.negate());
    BigDecimal fpx = xn.multiply(new BigDecimal(2));
    BigDecimal xn1 = fx.divide(fpx, 2 * SQRT_DIG.intValue(), RoundingMode.HALF_DOWN);
    xn1 = xn.add(xn1.negate());
    BigDecimal currentSquare = xn1.pow(2);
    BigDecimal currentPrecision = currentSquare.subtract(c);
    currentPrecision = currentPrecision.abs();
    if(currentPrecision.compareTo(precision) <= -1){
        return xn1;
    }
    return sqrtNewtonRaphson(c, xn1, precision);
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:20,代碼來源:JBigNumber.java

示例6: localPow

import java.math.BigDecimal; //導入方法依賴的package包/類
public BigDecimal localPow(BigDecimal b, BigInteger pw, MathContext mc){
   
    BigInteger Threshold = new BigInteger("100000000");
    BigInteger Counter = Threshold;
    BigInteger Divider = BigInteger.ONE;
    if(pw.compareTo(Threshold)<=0)
         return b.pow(pw.intValueExact(), mc);
    
     
    while(Counter.compareTo(pw)<=0){
        Divider=Divider.add(BigInteger.ONE);
         Counter =Counter.add(Threshold);
    }
     Divider = Divider.subtract(BigInteger.ONE);
     Counter = Counter.subtract(Threshold);
     
     BigInteger Remainder = pw.subtract(Counter);
      
     return b.pow(Remainder.intValueExact(),jc.MC).multiply(localPow(b.pow(100000000,jc.MC),Divider,jc.MC),jc.MC);
     
     
}
 
開發者ID:mathhobbit,項目名稱:EditCalculateAndChart,代碼行數:23,代碼來源:CalCpowl.java

示例7: square

import java.math.BigDecimal; //導入方法依賴的package包/類
public static BigDecimal square(BigDecimal b1) {
  return b1.pow(2);
}
 
開發者ID:AcadiaSoft,項目名稱:simm-lib,代碼行數:4,代碼來源:BigDecimalUtils.java


注:本文中的java.math.BigDecimal.pow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。