List of usage examples for java.math BigDecimal pow
public BigDecimal pow(int n)
(thisn)
, The power is computed exactly, to unlimited precision. From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("1.23"); // apply pow method on bg1 BigDecimal bg2 = bg1.pow(3); System.out.println(bg2);/* ww w. j a v a 2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { BigDecimal decimalA = new BigDecimal("123456789012345"); BigDecimal decimalB = new BigDecimal("10"); decimalA = decimalA.add(decimalB);/*from ww w.j a v a 2 s . c o m*/ System.out.println("decimalA = " + decimalA); decimalA = decimalA.multiply(decimalB); System.out.println("decimalA = " + decimalA); decimalA = decimalA.subtract(decimalB); System.out.println("decimalA = " + decimalA); decimalA = decimalA.divide(decimalB); System.out.println("decimalA = " + decimalA); decimalA = decimalA.pow(2); System.out.println("decimalA = " + decimalA); decimalA = decimalA.negate(); System.out.println("decimalA = " + decimalA); }
From source file:adalid.commons.util.ObjUtils.java
public static BigDecimal xRaisedToTheY(Object x, Object y) { BigDecimal bx = NumUtils.numberToBigDecimal(x); Integer iy = bx == null ? null : NumUtils.numberToInteger(y); return bx == null || iy == null ? null : bx.pow(iy); }
From source file:com.idylwood.utils.MathUtils.java
private final static double varianceSlow(final double[] data) { BigDecimal mean = new BigDecimal(0); for (double x : data) mean = mean.add(new BigDecimal(x), MathContext.UNLIMITED); mean = mean.divide(new BigDecimal(data.length), MathContext.UNLIMITED); //mean = new BigDecimal(mean(data)); BigDecimal ret = new BigDecimal(0); for (double x : data) { //BigDecimal summand = ret.add(new BigDecimal(x),MathContext.UNLIMITED); BigDecimal summand = new BigDecimal(x).subtract(mean, MathContext.UNLIMITED); ret = ret.add(summand.pow(2)); }// w ww . java2s .co m ret = ret.divide(new BigDecimal(data.length - 1), MathContext.DECIMAL128); return ret.doubleValue(); }
From source file:de.tbuchloh.kiskis.model.validation.WeakPasswordValidator.java
public BigDecimal getVariationCnt() { final BigDecimal two = new BigDecimal(2); return two.pow(_bitSize.intValue()); }
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);/*from ww w .j a v a 2 s . c o m*/ nSquare = nSquare.multiply(radians.pow(2)).setScale( ((mc == null ? MathContext.DECIMAL128 : mc).getPrecision() + 2), RoundingMode.HALF_UP); index++; } return cos.setScale((mc == null ? MathContext.DECIMAL128 : mc).getPrecision(), RoundingMode.HALF_UP); }
From source file:dom.rootlocus.utils.Utils.java
/** * get the module of a complex number/*from w w w . j a v a 2s . c o m*/ * * @param n:the number that we are interested in its module * @return the module * */ public double getModule(Complex n) { BigDecimal Re = new BigDecimal(n.getReal()); BigDecimal Img = new BigDecimal(n.getImaginary()); return Math.sqrt(Re.pow(2).add(Img.pow(2)).doubleValue()); }
From source file:org.cirdles.ambapo.LatLongToUTM.java
/** * eta refers to the east-west direction * // w ww.j a v a2 s .c om * @param changeInLongitudeRadians * @param tauPrime * @return BigDecimal eta prime * * */ private static BigDecimal calcEtaPrimeEast(BigDecimal changeInLongitudeRadians, BigDecimal tauPrime) { BigDecimal etaPrime; double sinOfLatRad = Math.sin(changeInLongitudeRadians.doubleValue()); double cosOfLatRad = Math.cos(changeInLongitudeRadians.doubleValue()); double cosOfLatRadSquared = Math.pow(cosOfLatRad, 2); BigDecimal tauPrimeSquared = tauPrime.pow(2); double sqrt = Math.sqrt(tauPrimeSquared.doubleValue() + cosOfLatRadSquared); double sinOverSqrt = sinOfLatRad / sqrt; Asinh asinhOfSin = new Asinh(); etaPrime = new BigDecimal(asinhOfSin.value(sinOverSqrt)); return etaPrime; }
From source file:org.cirdles.ambapo.UTMToLatLong.java
/** * /*from ww w . j a v a 2s. c o m*/ * @param xiPrime * @param etaPrime * @return tau prime */ private static BigDecimal calcTauPrime(BigDecimal xiPrime, BigDecimal etaPrime) { double xiPrimeDouble = xiPrime.doubleValue(); double etaPrimeDouble = etaPrime.doubleValue(); BigDecimal sinOfXiPrime = new BigDecimal(Math.sin(xiPrimeDouble)); BigDecimal cosOfXiPrime = new BigDecimal(Math.cos(xiPrimeDouble)); BigDecimal sinhOfEtaPrime = new BigDecimal(Math.sinh(etaPrimeDouble)); BigDecimal squareRoot = new BigDecimal( Math.sqrt(sinhOfEtaPrime.pow(2).add(cosOfXiPrime.pow(2)).doubleValue())); BigDecimal tauPrime = sinOfXiPrime.divide(squareRoot, PRECISION, RoundingMode.HALF_UP); return tauPrime; }
From source file:org.cirdles.ambapo.UTMToLatLong.java
/** * /* w ww. j av a 2 s . co m*/ * @param currentTau * @param currentSigma * @param originalTau * @return function of tau */ private static BigDecimal functionOfTau(BigDecimal currentTau, BigDecimal currentSigma, BigDecimal originalTau) { BigDecimal funcOfTau = originalTau .multiply(new BigDecimal(Math.sqrt(1 + currentSigma.pow(2).doubleValue()))) .subtract(currentSigma.multiply(new BigDecimal(Math.sqrt(1 + currentTau.pow(2).doubleValue())))) .subtract(originalTau); return funcOfTau; }