Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:fsm.series.Series_CC.java

public strictfp double getF5Value(double y, int m, int n) {

    double um = getMu_m(m);
    double un = getMu_m(n);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double alphaN = (sin(un) - sinh(un)) / (cos(un) - cosh(un));

    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd1;//from   ww w . j  a va2s .  com
    BigDecimal Ynd1;

    BigDecimal cosh = new BigDecimal(-km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(alphaM * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(alphaM * km * sin(km * y));
    BigDecimal cos = new BigDecimal(km * cos(km * y));

    Ymd1 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-kn * cosh(kn * y));

    BigDecimal sinhN = new BigDecimal(alphaN * kn * sinh(kn * y));
    BigDecimal sinN = new BigDecimal(alphaN * kn * sin(kn * y));
    BigDecimal cosN = new BigDecimal(kn * cos(kn * y));

    Ynd1 = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd1.multiply(Ynd1);

    return ans.doubleValue();
}

From source file:fsm.series.Series_CC.java

@Override
public double getSecondDerivativeValue(double y, int m) {

    // d2Y =alphaM*(km^2*cos(km*y) + km^2*cosh(km*y)) - km^2*sin(km*y) - km^2*sinh(km*y)
    double um = getMu_m(m);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double km = um / a;

    BigDecimal d2Ym;/*  www  . jav a  2  s  . c om*/

    BigDecimal cosh = new BigDecimal(km * km * alphaM * cosh(km * y));
    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(km * km * alphaM * cos(km * y));

    d2Ym = (cos.add(sin).add(sinh).add(cosh));

    return d2Ym.doubleValue();

}

From source file:fsm.series.Series_CC.java

public strictfp double getF1Value(double y, int m, int n) {

    double um = getMu_m(m);
    double un = getMu_m(n);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double alphaN = (sin(un) - sinh(un)) / (cos(un) - cosh(un));

    double km = um / a;
    double kn = un / a;

    BigDecimal Ym;/*from   w w w  .j  a  v a 2s.com*/
    BigDecimal Yn;

    BigDecimal cosh = new BigDecimal(-alphaM * -cosh(km * y));
    BigDecimal sinh = new BigDecimal(-sinh(km * y));
    BigDecimal sin = new BigDecimal(sin(km * y));
    BigDecimal cos = new BigDecimal(-alphaM * cos(km * y));

    Ym = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y));
    BigDecimal sinhN = new BigDecimal(-sinh(kn * y));
    BigDecimal sinN = new BigDecimal(sin(kn * y));
    BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y));

    Yn = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ym.multiply(Yn);

    return ans.doubleValue();

}

From source file:fsm.series.Series_CC.java

public strictfp double getF4Value(double y, int m, int n) {

    double um = getMu_m(m);
    double un = getMu_m(n);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double alphaN = (sin(un) - sinh(un)) / (cos(un) - cosh(un));

    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd2;/*from w w  w  .j a  v  a 2 s .com*/
    BigDecimal Ynd2;

    BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y));

    Ymd2 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(alphaN * kn * kn * cosh(kn * y));

    BigDecimal sinhN = new BigDecimal(-kn * kn * sinh(kn * y));
    BigDecimal sinN = new BigDecimal(-kn * kn * sin(kn * y));
    BigDecimal cosN = new BigDecimal(alphaN * kn * kn * cos(kn * y));

    Ynd2 = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd2.multiply(Ynd2);

    return ans.doubleValue();
}

From source file:com.artivisi.biller.simulator.gateway.pln.PlnGateway.java

private boolean handleInquiryPostpaid(ISOSource src, ISOMsg msg, ISOMsg response)
        throws ISOException, IOException, VetoException {
    String bit48Request = msg.getString(48);
    if (bit48Request.length() != 19) {
        logger.error("[POSTPAID] - [INQ-REQ] - Invalid bit 48 [{}]", bit48Request);
        response.set(39, ResponseCode.ERROR_INVALID_MESSAGE);
        src.send(response);//  w ww. ja  v  a  2 s .  c  om
        return true;
    }

    String mitra = bit48Request.substring(0, 7);
    if (billerSimulatorService.findMitraByKode(mitra.trim()) == null) {
        logger.debug("[POSTPAID] - [INQ-REQ] - Mitra [{}]", mitra);
        logger.error("[POSTPAID] - [INQ-REQ] - Kode mitra tidak ditemukan [{}]", mitra);
        response.set(39, ResponseCode.ERROR_UNREGISTERED_SWITCHING);
        src.send(response);
        return true;
    }

    String idpel = bit48Request.substring(7);
    Pelanggan p = plnSimulatorService.findPelangganByIdpel(idpel);
    if (p == null) {
        logger.error("[POSTPAID] - [INQ-REQ] - IDPEL tidak ditemukan [{}]", idpel);
        response.set(39, ResponseCode.ERROR_UNKNOWN_SUBSCRIBER);
        src.send(response);
        return true;
    }

    if (!ResponseCode.SUCCESSFUL.equals(p.getResponseCode())) {
        logger.error("[POSTPAID] - [INQ-REQ] - Pelanggan diset untuk RC [{}]", p.getResponseCode());
        response.set(39, p.getResponseCode());
        src.send(response);
        return true;
    }

    List<TagihanPascabayar> daftarTagihan = plnSimulatorService.findTagihan(p);
    if (daftarTagihan.size() < 1) {
        logger.error("[POSTPAID] - [INQ-REQ] - Tagihan untuk idpel [{}] tidak ada", idpel);
        response.set(39, ResponseCode.ERROR_CURRENT_BILL_IS_NOT_AVAILABLE);
        src.send(response);
        return true;
    }

    List<TagihanPascabayar> tagihanDikirim;
    if (daftarTagihan.size() > 4) {
        tagihanDikirim = daftarTagihan.subList(0, 4);
    } else {
        tagihanDikirim = daftarTagihan;
    }

    BigDecimal amount = BigDecimal.ZERO;
    for (TagihanPascabayar tagihanPascabayar : tagihanDikirim) {
        amount = amount.add(tagihanPascabayar.getBill());
        amount = amount.add(tagihanPascabayar.getDenda());
    }

    response.set(4,
            "360" + "0" + StringUtils.leftPad(amount.setScale(0, RoundingMode.HALF_EVEN).toString(), 12, "0"));

    InquiryPostpaidResponse ipr = new InquiryPostpaidResponse();
    ipr.setBank(msg.getString(32));
    ipr.setSwitcher(mitra);
    ipr.setStan(msg.getString(11));

    for (TagihanPascabayar tagihanPascabayar : tagihanDikirim) {
        InquiryPostpaidResponseDetail detail = new InquiryPostpaidResponseDetail();
        detail.setTagihanPascabayar(tagihanPascabayar);
        detail.setInquiryPostpaidResponse(ipr);
        ipr.getDetails().add(detail);
    }

    plnService.save(ipr);

    StringBuffer bit48Response = createBit48InquiryPostpaidResponse(bit48Request, p, daftarTagihan,
            tagihanDikirim, ipr);

    response.set(39, ResponseCode.SUCCESSFUL);
    response.set(48, bit48Response.toString());

    try {
        logger.info("[POSTPAID] - [INQ-REQ] - Pelanggan diset untuk hold [{}]", p.getHoldResponse());
        Thread.sleep(p.getHoldResponse());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    src.send(response);
    return true;
}

From source file:fsm.series.Series_CC.java

public strictfp double getF2Value(double y, int m, int n) {

    double Pi = Math.PI;

    double um = getMu_m(m);
    double un = getMu_m(n);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double alphaN = (sin(un) - sinh(un)) / (cos(un) - cosh(un));

    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd2;/*w w  w  . j a  va2 s .  c o  m*/
    BigDecimal Yn;

    BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y));

    Ymd2 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y));
    BigDecimal sinhN = new BigDecimal(-sinh(kn * y));
    BigDecimal sinN = new BigDecimal(sin(kn * y));
    BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y));

    Yn = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd2.multiply(Yn);

    return ans.doubleValue();
}

From source file:jp.furplag.util.commons.NumberUtils.java

public static BigDecimal cos(final BigDecimal angle, MathContext mc, boolean isRadians) {
    if (angle == null)
        return null;
    BigDecimal cos = BigDecimal.ONE;
    BigDecimal radians = isRadians ? angle : valueOf(toRadians(angle), BigDecimal.class);
    BigDecimal nSquare = radians.pow(2);
    int index = 0;
    for (BigDecimal factor : COSINE_FACTOR_DECIMAL128) {
        BigDecimal temporary = factor.multiply(nSquare);
        if (index % 2 == 0)
            temporary = temporary.negate();
        cos = cos.add(temporary);
        nSquare = nSquare.multiply(radians.pow(2)).setScale(
                ((mc == null ? MathContext.DECIMAL128 : mc).getPrecision() + 2), RoundingMode.HALF_UP);
        index++;/*from   w w  w .j av a  2s .c  o m*/
    }

    return cos.setScale((mc == null ? MathContext.DECIMAL128 : mc).getPrecision(), RoundingMode.HALF_UP);
}

From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java

private BigDecimal calculateTotal(final LocalDate d, final Account account, final CurrencyNode baseCurrency) {
    // get the amount for the account               
    BigDecimal total = AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(),
            account.getBalance(d, baseCurrency));

    // add the amount of every child account
    for (int y = 0; y < account.getChildCount(); y++) {
        total = total.add(
                calculateTotal(d, account.getChildren(Comparators.getAccountByCode()).get(y), baseCurrency));
    }/* w w w  .j av a 2 s  .c o  m*/
    return total;
}

From source file:io.silverware.microservices.monitoring.MetricsManager.java

/**
 * Method responsible for adding new time to values collection and also updating min, max, avg and count metrics.
 *
 * @param elapsedTime/*  w  w  w .ja va2  s . co  m*/
 *       runtime of microservice method.
 */
public void addTime(BigDecimal elapsedTime) {

    if (elapsedTime.compareTo(BigDecimal.ZERO) <= 0) {
        throw new IllegalArgumentException("Elapsed time is negative or zero");
    }

    mapValues.put(longAdder.longValue(), elapsedTime);

    longAdder.increment();

    final BigDecimal count = new BigDecimal(metrics.getCount());
    final BigDecimal averageTime = metrics.getAverageTime();
    final BigDecimal minTime = metrics.getMinTime();
    final BigDecimal maxTime = metrics.getMaxTime();

    metrics.incrementCount();

    metrics.setAverageTime((averageTime.multiply(count).add(elapsedTime)).divide(count.add(BigDecimal.ONE),
            BigDecimal.ROUND_HALF_UP));

    if (elapsedTime.compareTo(maxTime) >= 1) {
        metrics.setMaxTime(elapsedTime);
    } else {
        metrics.setMinTime(elapsedTime);
    }
}

From source file:net.groupbuy.plugin.PaymentPlugin.java

/**
 * ?/* w  ww .  j  a  v a  2s.  co m*/
 * 
 * @param amount
 *            ?
 * @return ?
 */
public BigDecimal calculateAmount(BigDecimal amount) {
    return amount.add(calculateFee(amount)).setScale(2, RoundingMode.UP);
}