本文整理了Java中java.math.BigDecimal.negate()
方法的一些代码示例,展示了BigDecimal.negate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.negate()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:negate
[英]Returns a new BigDecimal whose value is the -this. The scale of the result is the same as the scale of this.
[中]返回一个新的BigDecimal,其值为-this。结果的比例与此的比例相同。
代码示例来源:origin: robovm/robovm
/**
* Returns a {@code BigDecimal} whose value is the absolute value of
* {@code this}. The result is rounded according to the passed context
* {@code mc}.
*/
public BigDecimal abs(MathContext mc) {
BigDecimal result = (signum() < 0) ? negate() : new BigDecimal(getUnscaledValue(), scale);
result.inplaceRound(mc);
return result;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Returns the unit amount (e.g. .01 for US)
* @param currency
* @return
*/
public Money getUnitAmount(Money difference) {
Currency currency = difference.getCurrency();
BigDecimal divisor = new BigDecimal(Math.pow(10, currency.getDefaultFractionDigits()));
BigDecimal unitAmount = new BigDecimal("1").divide(divisor);
if (difference.lessThan(BigDecimal.ZERO)) {
unitAmount = unitAmount.negate();
}
return new Money(unitAmount, currency);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
*
* @param difference
* @return
*/
public static Money getUnitAmount(Money difference) {
Currency currency = BroadleafCurrencyUtils.getCurrency(difference);
BigDecimal divisor = new BigDecimal(Math.pow(10, currency.getDefaultFractionDigits()));
BigDecimal unitAmount = new BigDecimal("1").divide(divisor);
if (difference.lessThan(BigDecimal.ZERO)) {
unitAmount = unitAmount.negate();
}
return new Money(unitAmount, currency);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* The hyperbolic tangent.
*
* @param x The argument.
* @return The tanh(x) = sinh(x)/cosh(x).
*/
static public BigDecimal tanh(final BigDecimal x) {
if (x.compareTo(BigDecimal.ZERO) < 0) {
return tanh(x.negate()).negate();
} else if (x.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO;
} else {
BigDecimal xhighpr = scalePrec(x, 2);
/* tanh(x) = (1-e^(-2x))/(1+e^(-2x)) .
*/
BigDecimal exp2x = exp(xhighpr.multiply(new BigDecimal(-2)));
/* The error in tanh x is err(x)/cosh^2(x).
*/
double eps = 0.5 * x.ulp().doubleValue() / Math.pow(Math.cosh(x.doubleValue()), 2.0);
MathContext mc = new MathContext(err2prec(Math.tanh(x.doubleValue()), eps));
return BigDecimal.ONE.subtract(exp2x).divide(BigDecimal.ONE.add(exp2x), mc);
}
} /* BigDecimalMath.tanh */
代码示例来源:origin: stackoverflow.com
private static final BigDecimal SQRT_DIG = new BigDecimal(150);
private static final BigDecimal SQRT_PRE = new BigDecimal(10).pow(SQRT_DIG.intValue());
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);
代码示例来源:origin: deeplearning4j/nd4j
BigDecimal pihalf = onepi.divide(new BigDecimal(2));
} else if (res.compareTo(pihalf.negate()) < 0) {
res = res.add(onepi);
代码示例来源:origin: deeplearning4j/nd4j
return cos(x.negate());
} else if (x.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ONE;
ifac = ifac.multiply(BigInteger.valueOf(2 * i));
xpowi = xpowi.multiply(xhighpr).multiply(xhighpr);
BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
resul = resul.add(corr);
代码示例来源:origin: deeplearning4j/nd4j
return sinh(x.negate()).negate();
} else if (x.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO;
BigDecimal two = new BigDecimal(2);
BigDecimal xhalf = x.divide(two);
ifac = ifac.multiply(BigInteger.valueOf(2 * i + 1));
xpowi = xpowi.multiply(xhighpr).multiply(xhighpr);
BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
resul = resul.add(corr);
代码示例来源:origin: deeplearning4j/nd4j
return sin(x.negate()).negate();
} else if (x.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO;
return sin(subtractRound(res, p)).negate();
} else if (res.multiply(new BigDecimal(2)).compareTo(p) > 0) {
if (res.multiply(new BigDecimal(4)).compareTo(p) > 0) {
return cos(subtractRound(p.divide(new BigDecimal(2)), res));
} else {
xpowi = xpowi.multiply(res).multiply(res).negate();
BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
resul = resul.add(corr);
代码示例来源:origin: deeplearning4j/nd4j
return cos(x.negate());
} else if (x.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ONE;
return cos(subtractRound(res, p)).negate();
} else if (res.multiply(new BigDecimal(2)).compareTo(p) > 0) {
return cos(subtractRound(p, res)).negate();
} else {
if (res.multiply(new BigDecimal(4)).compareTo(p) > 0) {
return sin(subtractRound(p.divide(new BigDecimal(2)), res));
} else {
xpowi = xpowi.multiply(res).multiply(res).negate();
BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
resul = resul.add(corr);
代码示例来源:origin: org.apache.commons/commons-math3
final BigDecimal b_two_j_p_1 = new BigDecimal(2 * j + 1, mContext);
final BigDecimal b_j = new BigDecimal(j, mContext);
final BigDecimal b_j_p_1 = new BigDecimal(j + 1, mContext);
points[idx] = c.negate(mContext);
weights[idx] = tmp2;
pmc = pmc.negate(mContext);
代码示例来源:origin: deeplearning4j/nd4j
if (x.compareTo(BigDecimal.ONE) > 0 || x.compareTo(BigDecimal.ONE.negate()) < 0) {
throw new ArithmeticException("Out of range argument " + x.toString() + " of asin");
return pi(mc).divide(new BigDecimal(2));
return asin(x.negate()).negate();
xpowi = sqrt(xhighpr.multiply(new BigDecimal(2)));
resul = multiplyRound(xpowi, resul);
MathContext mc = new MathContext(resul.precision());
BigDecimal pihalf = pi(mc).divide(new BigDecimal(2));
mc = new MathContext(err2prec(resul.doubleValue(), eps));
代码示例来源:origin: deeplearning4j/nd4j
final BigDecimal invx = exp(x.negate());
ifac = ifac.multiply(BigInteger.valueOf(i));
xpowi = xpowi.multiply(x);
final BigDecimal c = xpowi.divide(new BigDecimal(ifac), mcTay);
resul = resul.add(c);
if (Math.abs(xpowi.doubleValue()) < i && Math.abs(c.doubleValue()) < 0.5 * xUlpDbl) {
代码示例来源:origin: robovm/robovm
return subtrahend.negate();
return valueOf(this.smallValue - subtrahend.smallValue,this.scale);
return new BigDecimal(this.getUnscaledValue().subtract(subtrahend.getUnscaledValue()), this.scale);
} else if (diffScale > 0) {
return valueOf(this.smallValue-subtrahend.smallValue*MathUtils.LONG_POWERS_OF_TEN[diffScale],this.scale);
return new BigDecimal(this.getUnscaledValue().subtract(
Multiplication.multiplyByTenPow(subtrahend.getUnscaledValue(),diffScale)), this.scale);
} else {// case s2 > s1 : [ u1 * 10 ^ (s2 - s1) - u2 , s2 ]
return valueOf(this.smallValue*MathUtils.LONG_POWERS_OF_TEN[diffScale]-subtrahend.smallValue,subtrahend.scale);
return new BigDecimal(Multiplication.multiplyByTenPow(this.getUnscaledValue(),diffScale)
.subtract(subtrahend.getUnscaledValue()), subtrahend.scale);
代码示例来源:origin: deeplearning4j/nd4j
return atan(x.negate()).negate();
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr).negate();
BigDecimal resul = xhighpr.plus();
BigDecimal resul = onepi.divide(new BigDecimal(2));
final BigDecimal xhighpr = divideRound(-1, scalePrec(x, 2));
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr).negate();
代码示例来源:origin: deeplearning4j/nd4j
BigDecimal xmin1 = x.subtract(new BigDecimal(n));
BigDecimal resul = log(scalePrec(x, 2)).negate();
代码示例来源:origin: konsoletyper/teavm
BigDecimal result = new BigDecimal(mantissa, -exponent);
if (multiplier != 1) {
result = result.divide(BigDecimal.valueOf(multiplier));
result = result.negate();
代码示例来源:origin: apache/hbase
BigDecimal longMax = BigDecimal.valueOf(Long.MAX_VALUE);
double negInf = Double.NEGATIVE_INFINITY;
BigDecimal negLarge = longMax.multiply(longMax).negate();
BigDecimal negMed = new BigDecimal("-10.0");
BigDecimal negSmall = new BigDecimal("-0.0010");
long zero = 0l;
BigDecimal posSmall = negSmall.negate();
BigDecimal posMed = negMed.negate();
BigDecimal posLarge = negLarge.negate();
double posInf = Double.POSITIVE_INFINITY;
double nan = Double.NaN;
代码示例来源:origin: apache/ignite
BigDecimal valArr[] = new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN, new BigDecimal("-100.5"),
BigDecimal.valueOf(Long.MAX_VALUE, 0), BigDecimal.valueOf(Long.MIN_VALUE, 0),
BigDecimal.valueOf(Long.MAX_VALUE, 8), BigDecimal.valueOf(Long.MIN_VALUE, 8)};
obj2.valArr = new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN.negate()};
obj2.rawVal = BigDecimal.TEN;
obj2.rawValArr = new BigDecimal[] {BigDecimal.ZERO, BigDecimal.ONE};
代码示例来源:origin: pholser/junit-quickcheck
@Override public BigDecimal generate(SourceOfRandomness random, GenerationStatus status) {
BigDecimal minToUse = min;
BigDecimal maxToUse = max;
int power = status.size() + 1;
if (minToUse == null && maxToUse == null) {
maxToUse = TEN.pow(power);
minToUse = maxToUse.negate();
}
if (minToUse == null)
minToUse = maxToUse.subtract(TEN.pow(power));
else if (maxToUse == null)
maxToUse = minToUse.add(TEN.pow(power));
int scale = decideScale();
BigDecimal minShifted = minToUse.movePointRight(scale);
BigDecimal maxShifted = maxToUse.movePointRight(scale);
BigInteger range = maxShifted.toBigInteger().subtract(minShifted.toBigInteger());
BigInteger generated;
do {
generated = random.nextBigInteger(range.bitLength());
} while (generated.compareTo(range) >= 0);
return minShifted.add(new BigDecimal(generated)).movePointLeft(scale);
}
内容来源于网络,如有侵权,请联系作者删除!